NUnit tests fail because of DLL loading issue within F# library - f#

I've ran into this issue before when using NUnit with F#:
Could not load file or assembly 'nunit.framework, Version=2.6.3.13283
I have downgraded my version of FSharp.Core to a lower version number.
I'm not sure what I need to do to get my tests to run without any exceptions.
Code
module Foo
open NUnit.Framework
open FsUnit
[<Test>]
let ``some test``() =
1 |> should equal 1
Packages.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FSharp.Core" version="4.0.0.1" targetFramework="net46" />
<package id="FsUnit" version="1.4.1.0" targetFramework="net46" />
<package id="NUnit" version="2.6.4" targetFramework="net46" />
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net46" />
<package id="xunit" version="2.1.0" targetFramework="net46" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net46" />
<package id="xunit.assert" version="2.1.0" targetFramework="net46" />
<package id="xunit.core" version="2.1.0" targetFramework="net46" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net46" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net46" />
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net46" />
</packages>

This is most likely because FsUnit references an older version of nunit.framework (2.6.3), but your applcation is compiled against a newer version of NUnit (2.6.4).
The way to solve this is to add app.config to your test project, which will map all versions of NUnit to the one that you are referencing in your project. Something like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="nunit.framework"
publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9999.9999.9999.9999"
newVersion="2.6.4.14350" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I was solving the exact same problem in one project recently, so the above might just work for you - but if no, check what is your version of nunit.framework.dll using a tool like ILSpy. I have 2.6.4.14350, but you might have a different one.

Related

Serilog not logging anymore after upgrading to 2.*

We have a large application (about 40 projects) that uses .NET Framework 4.8 and C# in VS 2019. It includes a couple of WCF services and a bunch of Web Apps using different "old" technologies (WebForms, ASP.NET MVC).
We are trying to upgrade Serilog from 1.5.14 to 2.11.0.
The upgrade went fine following the upgrade guide (see Upgrade Guide here), and the project compiles and runs fine.
The problem is that it doesn't log anything anymore: each separate service and web app has its own Serilog configuration (using XML AppSettings), but no log file is created and of course no logging is done, and the configuration hasn't been changed. No exception or anything like that is thrown either.
The problem might be that the configuration is not read for some reason, or there is something to add missing from the upgrade guide. The original code that initializes the logger looks like this:
Log.Logger = new LoggerConfiguration()
.Enrich.WithExceptionDetails()
.ReadFrom.AppSettings()
.CreateLogger();
Log.Information("Service Starting");
If I change the code to be like this:
var l = new LoggerConfiguration().ReadFrom.AppSettings().Enrich.WithExceptionDetails().WriteTo.File("c:\\logs\\log.txt");
Log.Logger = l.CreateLogger();
Log.Information("Service Starting");
Then magically the "log.txt" file is created and everything is logged into it, but using "Debug" settings, so again it looks like the config is not read.
This is my typical Serilog configuration:
<appSettings>
<!--Serilog-->
<add key="serilog:minimum-level" value="Debug" />
<!--trace logging-->
<add key="serilog:write-to:Trace" value="Serilog.Trace" />
<add key="serilog:write-to:Trace.restrictedToMinimumLevel" value="Debug" />
<!--rolling file logging-->
<add key="serilog:write-to:RollingFile" value="Serilog.RollingFileSink" />
<add key="serilog:write-to:RollingFile.restrictedToMinimumLevel" value="Information" />
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\Service-{Date}.log" />
<add key="serilog:write-to:RollingFile.retainedFileCountLimit" value="10" />
</appSettings>
And below is the list of packages installed on the project configured as above:
<package id="Serilog" version="2.11.0" targetFramework="net48" />
<package id="Serilog.Enrichers.Environment" version="2.2.0" targetFramework="net48" />
<package id="Serilog.Enrichers.Process" version="2.0.2" targetFramework="net48" />
<package id="Serilog.Enrichers.Thread" version="3.1.0" targetFramework="net48" />
<package id="Serilog.Exceptions" version="8.4.0" targetFramework="net48" />
<package id="Serilog.Formatting.Compact" version="1.1.0" targetFramework="net48" />
<package id="Serilog.Settings.AppSettings" version="2.2.2" targetFramework="net48" />
<package id="Serilog.Sinks.Console" version="4.0.1" targetFramework="net48" />
<package id="Serilog.Sinks.EventLog" version="3.1.0" targetFramework="net48" />
<package id="Serilog.Sinks.File" version="5.0.0" targetFramework="net48" />
<package id="Serilog.Sinks.Observable" version="2.0.2" targetFramework="net48" />
<package id="Serilog.Sinks.PeriodicBatching" version="2.3.1" targetFramework="net48" />
<package id="Serilog.Sinks.Seq" version="5.1.1" targetFramework="net48" />
<package id="Serilog.Sinks.TextWriter" version="2.1.0" targetFramework="net48" />
<package id="Serilog.Sinks.Trace" version="3.0.0" targetFramework="net48" />
<package id="SerilogMetrics" version="2.1.0" targetFramework="net48" />
Anybody who can help please?
Thanks
In the end after looking at some different pieces of docs I've found what the missing bits were.
The updated configuration above needs to look like this:
<add key="serilog:using:File" value="Serilog.Sinks.File" />
<add key="serilog:write-to:File" value="Serilog.FileSink" />
<add key="serilog:write-to:File.restrictedToMinimumLevel" value="Information" />
<add key="serilog:write-to:File.path" value="C:\Logs\Service-.log" />
<add key="serilog:write-to:File.rollingInterval" value="Day" />
<add key="serilog:write-to:File.retainedFileCountLimit" value="10" />
The config above works the same as the previous configuration and without the need to use the deprecated RollingFile sink.
The key thing here is the "using" line: without that nothing gets logged and no exception is thrown.
The second thing is the additional "rollingInterval" line that appends the date to the provided file name (note the "pathFormat" changed into just "path" there).
Hope it can be useful for somebody else.

How to get rid of Nuget package's Entity Framework error

I have an ASP.NET MVC 5 project. It works fine, but every time I add a view (which successfully gets created) and then when I build solution I get error
This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is packages\EntityFramework.6.4.4\build\EntityFramework.props.
I have to update (goes back to 6.1.3 version every time) Entity Framework which annoys me a lot. is there anything I can do to to solve this permanently?
Edit: here are all packages that uses targetframework=net472
<package id="Antlr" version="3.5.0.2" targetFramework="net472" />
<package id="bootstrap" version="3.3.4" targetFramework="net472" />
<package id="EntityFramework" version="6.4.4" targetFramework="net472" />
<package id="FontAwesome" version="4.7.0" targetFramework="net472" />
<package id="jQuery" version="3.6.0" targetFramework="net472" />
<package id="jquery.datatables" version="1.10.15" targetFramework="net472" />
<package id="jQuery.UI.Combined" version="1.13.1" targetFramework="net472" />
<package id="jQuery.Validation" version="1.19.4" targetFramework="net472" />
<package id="Microsoft.AspNet.Mvc" version="5.2.9" targetFramework="net472" />
<package id="Microsoft.AspNet.Razor" version="3.2.9" targetFramework="net472" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net472" />
<package id="Microsoft.AspNet.WebPages" version="3.2.9" targetFramework="net472" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="3.6.0" targetFramework="net472" />
<package id="Microsoft.jQuery.Unobtrusive.Ajax" version="3.1.2" targetFramework="net472" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.12" targetFramework="net472" />
<package id="Microsoft.Owin" version="4.2.2" targetFramework="net472" />
<package id="Microsoft.Web.Infrastructure" version="2.0.0" targetFramework="net472" />
<package id="Modernizr" version="2.8.3" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
<package id="Owin" version="1.0" targetFramework="net472" />
<package id="PasswordHashTool" version="1.0.0" targetFramework="net472" />
<package id="popper.js" version="1.16.1" targetFramework="net472" />
<package id="WebGrease" version="1.6.0" targetFramework="net472" />
Try to make the following steps:
Exit from the Visual Studio.
Remove the EntityFramework... folder from the packages
Remove <package id="EntityFramework" version="6.4.4" targetFramework="net472" /> line from the packages.config file using a text editor.
Open the solution and add the required package EntityFramework.6.4.4 again using the NuGet Package Manager.
NOTE: Watch closely to the installation log. Probably you will see
error related to the version conflict.

Why am I not able to use the latest version of NUnit and FsCheck with F#?

I would like to use the latest versions of NUnit, FsCheck, and F#.
However, when I point to the latest versions of my packages, my unit tests do not get discovered.
However, my property-based tests are discovered (i.e. FsCheck).
My packages are the following:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FsCheck" version="2.4.0" targetFramework="net461" />
<package id="FsCheck.Xunit" version="2.4.0" targetFramework="net461" />
<package id="FSharp.Core" version="4.0.0.1" targetFramework="net461" />
<package id="FsUnit" version="2.2.0" targetFramework="net461" />
<package id="NUnit" version="3.2.1" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net461" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net461" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net461" />
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net461" />
</packages>
My app.config is the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9999.9999.9999.9999" newVersion="3.2.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Have you tried installing the NUnit3 test adapter so that Visual Studio knows about NUnit?
https://www.nuget.org/packages/NUnit3TestAdapter
It could be that your FsCheck tests are found because Visual Studio already knows about XUnit.

MvvmCross SQLite.Net-PCL plugin missing assembly

So i've added the "MvvmCross.HotTuna.Plugin.SQLitePCL" version "4.0.0-beta6" to my solution (My core, my android and my iphone projects).
I can now use SQLite.Net, and i can build for android and iPhoneSimulator. However, as soon as I switch to "iPhone" as my target, I get the following error:
Failed to resolve assembly: 'SQLite.Net.Platform.XamarinIOS, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null' SimplyRemember.Touch
It makes sense that it cannot find this assembly, as it is indeed not listed under "References" - Only the "SQLite.Net.Platform.XamarinIOS.Unified" is. Notice the ".Unified".
I have tried cleaning my solution. I have tried wiping my "/Library/Caches/Xamarin/mtbs" folder. I have tried wiping my "packages" folder in my solution, and restoring all packages. Same result every time.
As a sidenote, this was also the case when i used SQLitePCL version "4.0.0-beta5" in which i had added its dependencies to SQLite.Net-PCL 3.0.5 and SQLite.Net.Async-PCL 3.0.5 manually
Full packages.config for my Touch project:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Acr.Support" version="1.0.2" targetFramework="xamarinios1" />
<package id="Acr.UserDialogs" version="4.1.8" targetFramework="xamarinios1" />
<package id="MvvmCross.HotTuna.Binding" version="4.0.0-beta5" targetFramework="xamarinios1" />
<package id="MvvmCross.HotTuna.CrossCore" version="4.0.0-beta5" targetFramework="xamarinios1" />
<package id="MvvmCross.HotTuna.MvvmCrossLibraries" version="4.0.0-beta5" targetFramework="xamarinios1" />
<package id="MvvmCross.HotTuna.Plugin.SQLitePCL" version="4.0.0-beta6" targetFramework="xamarinios1" />
<package id="MvvmCross.HotTuna.StarterPack" version="4.0.0-beta5" targetFramework="xamarinios1" />
<package id="Splat" version="1.6.2" targetFramework="xamarinios1" />
<package id="SQLite.Net.Async-PCL" version="3.1.1" targetFramework="xamarinios1" />
<package id="SQLite.Net-PCL" version="3.1.1" targetFramework="xamarinios1" />
<package id="StyleCop.Analyzers" version="1.0.0-beta014" targetFramework="xamarinios1" developmentDependency="true" />
</packages>

Why does Azure CloudConfigurationManager.GetSetting return null

I have a cloud service web role project that runs locally in the emulator, but does not run when deployed. The error given is as follows:
[ArgumentNullException: Value cannot be null.
Parameter name: connectionString]
Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(String connectionString) in e:\projects\azure-sdk-for-net\microsoft-azure-api\Services\Storage\Lib\Common\CloudStorageAccount.cs:344
Candor.WindowsAzure.Storage.Table.CloudTableProxy`1.GetTable() in c:\Users\micha_000\Documents\GitHub\candor-common\Candor.WindowsAzure\Storage\Table\CloudTableProxy.cs:66
Candor.WindowsAzure.Storage.Table.CloudTableProxy`1.Get(String partitionKey, String rowKey) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor.WindowsAzure\Storage\Table\CloudTableProxy.cs:117
Candor.WindowsAzure.Logging.Common.Table.CloudTableLogger.get_Configuration() +218
Candor.WindowsAzure.Logging.Common.Table.CloudTableLogger.get_IsInfoEnabled() +9
Common.Logging.Factory.AbstractLogger.Info(Object message) in c:\_oss\common-logging\src\Common.Logging.Core\Logging\Factory\AbstractLogger.cs:503
Candor.Configuration.Provider.ProviderCollection`1.SetActiveProvider(T provider) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor\Configuration\Provider\ProviderCollection.cs:169
Candor.Configuration.Provider.ProviderResolver`1.AppendActive(T provider) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor\Configuration\Provider\ProviderResolver.cs:77
SHM.PublicMvcWeb.App_Start.ProviderBootstrapper.InitProviders() in c:\Users\micha_000\Documents\Git-Repos\shm-main\SHM.PublicMvcWeb\App_Start\ProviderBootstrapper.cs:23
SHM.PublicMvcWeb.App_Start.ProviderBootstrapper.PostStartup() in c:\Users\micha_000\Documents\Git-Repos\shm-main\SHM.PublicMvcWeb\App_Start\ProviderBootstrapper.cs:18
You can see the code for the relevant lines shown in the stack trace on github.
https://github.com/michael-lang/candor-common/
The lines leading to the error in CloudTableProxy are:
if (String.IsNullOrWhiteSpace(_connectionName))
throw new InvalidOperationException("The Cloud ConnectionName has not been configured.");
if (_account == null)
_account = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(_connectionName));
Since it does not throw the custom error "The cloud connectionName has not been configured.", that tells me that _connectionName passed into CloudConfigurationManager.GetSetting is not null. So CloudConfigurationManager is the call returning null for the supplied name. Given that this name does return a value when running locally, I am not sure why it isn't found when deployed to my cloud web role. If the connection name was entered as a typo, then it wouldn't work locally either. To be sure, here is my common logging configuration naming the connection to be used:
<common>
<logging>
<factoryAdapter type="Candor.WindowsAzure.Logging.Common.Table.CloudTableLoggerFactoryAdapter, Candor.WindowsAzure.Logging.Common">
<arg key="connectionName" value="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />
</factoryAdapter>
</logging>
</common>
I also have an entirely different solution with a cloud service web role using the same Candor.Common components, so I don't believe they are the problem.
I am using the same laptop to develop both solutions, and so both are using the Azure 2.2 Tools version. Inspecting the properties of the Cloud Service project in each solution verifies this.
I inspected every component and NuGet package reference to be sure there are no version mismatches through the solution. The same components are set to copy-local=true between the working solution and this non-working solution. They also have the same binding redirects. Although this was my biggest issue, now resolved, before running into this connection issue.
The non-working service deployment configuration:
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="SHM.AzureService.PublicMvcWeb" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2013-10.2.2">
<Role name="SHM.PublicMvcWeb">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" />
<Setting name="DefaultTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" />
<Setting name="UserTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" />
<Setting name="UserSaltTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" />
<Setting name="UserAuditTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
I also recently tried putting these same connection names in the web application's appsettings. This was in response to a comment 3 years ago that their code was executing before RoleEnvironment.OnStart. But this attempt still results in the same error.
Here is what the attempt looked like:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/>
<add key="DefaultTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/>
<add key="UserTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/>
<add key="UserSaltTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/>
<add key="UserAuditTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/>
</appSettings>
This code in error does run on start of the application using WebActivator 2.0.6, wheras my working solution uses WebActivator 2.0.4. But the release notes of WebActivator only shows compilation change from Debug to "Retail" and a license change between the two versions, and those changes were a year ago.
In case timing was the issue, I also tried adding a Thread.Sleep(1000) just before the call in error, and it didn't work either, so I am going to remove it.
using System.Threading;
using Candor.Configuration.Provider;
using Candor.Security;
using Candor.Security.Cryptography;
using Candor.Security.Web;
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(StopHarassingMe.PublicMvcWeb.App_Start.ProviderBootstrapper), "PreStartup")]
[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(StopHarassingMe.PublicMvcWeb.App_Start.ProviderBootstrapper), "PostStartup")]
namespace SHM.PublicMvcWeb.App_Start
{
public class ProviderBootstrapper
{
public static void PreStartup()
{
}
public static void PostStartup()
{
Thread.Sleep(1000); //let RoleEnvironment finish startup first or connectionstrings are not available.
InitProviders();
}
private static void InitProviders()
{
ProviderResolver<HashProvider>.Configure()
.AppendActive(new SHA2HashProvider("sha2") { IsObsolete = false, SaltModifier = "" });
}
}
}
This is the first provider configured in both the working and non-working solutions.
Here is a list of the packages used by the web application in error:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.5.0.2" targetFramework="net45" />
<package id="Candor.Core" version="1.4.1.0" targetFramework="net45" />
<package id="Candor.jQuery.AutoAsync" version="4.0.0.50129" targetFramework="net45" />
<package id="Candor.Security" version="2.4.0.0" targetFramework="net451" />
<package id="Candor.Security.AzureStorageProvider" version="2.3.2.0" targetFramework="net451" />
<package id="Candor.Web.Mvc" version="1.0.3.0" targetFramework="net451" />
<package id="Candor.Web.Mvc.ErrorHandler" version="1.0.0.0" targetFramework="net45" />
<package id="Candor.Web.Mvc.Security" version="2.1.0.0" targetFramework="net45" />
<package id="Candor.WindowsAzure" version="1.3.0.0" targetFramework="net451" />
<package id="Candor.WindowsAzure.Logging.Common" version="1.1.1.0" targetFramework="net451" />
<package id="Common.Logging" version="2.2.0" targetFramework="net45" />
<package id="Common.Logging.Core" version="2.2.0" targetFramework="net45" />
<package id="form2js" version="1.0.0.30224" targetFramework="net45" />
<package id="jQuery" version="2.1.4" targetFramework="net451" />
<package id="jQuery.UI.Combined" version="1.8.20.1" targetFramework="net45" />
<package id="jQuery.Validation" version="1.13.1" targetFramework="net45" />
<package id="MarkdownSharp" version="1.13.0.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net451" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net45" />
<package id="Modernizr" version="2.8.3" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="Respond" version="1.4.2" targetFramework="net45" />
<package id="RestSharp" version="105.0.1" targetFramework="net451" />
<package id="System.Spatial" version="5.6.0" targetFramework="net451" />
<package id="T4MVC" version="3.7.4" targetFramework="net45" />
<package id="T4MVCExtensions" version="3.7.4" targetFramework="net45" />
<package id="Twilio" version="4.0.3" targetFramework="net451" />
<package id="Twilio.Mvc" version="3.1.15" targetFramework="net451" />
<package id="Twilio.TwiML" version="3.3.6" targetFramework="net451" />
<package id="WebActivatorEx" version="2.0.6" targetFramework="net451" />
<package id="WebGrease" version="1.6.0" targetFramework="net45" />
<package id="WindowsAzure.Storage" version="2.1.0.3" targetFramework="net45" />
</packages>
There are a couple package differences between my working and non-working solution, but I didn't think these were applicable to the error. I went from MVC 5.0 to 5.2.3, upgraded javascript related packages, and Candor.WindowsAzure from 1.2.10 to 1.3. That may seem relevant, but the only code change was to replace the implementation of a batch update method.
WORKING SOLUTION PROJECT PACKAGES:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.5.0.2" targetFramework="net45" />
<package id="Candor.Core" version="1.4.1.0" targetFramework="net451" />
<package id="Candor.jQuery.AutoAsync" version="3.5.0.40210" targetFramework="net451" />
<package id="Candor.Security" version="2.4.0.0" targetFramework="net451" />
<package id="Candor.Security.AzureStorageProvider" version="2.3.2.0" targetFramework="net451" />
<package id="Candor.Web.Mvc" version="1.0.3.0" targetFramework="net451" />
<package id="Candor.Web.Mvc.ErrorHandler" version="1.0.0.0" targetFramework="net45" />
<package id="Candor.Web.Mvc.Security" version="2.1.0.0" targetFramework="net45" />
<package id="Candor.WindowsAzure" version="1.2.10.0" targetFramework="net451" />
<package id="Candor.WindowsAzure.Logging.Common" version="1.1.1.0" targetFramework="net451" />
<package id="Common.Logging" version="2.2.0" targetFramework="net451" />
<package id="Common.Logging.Core" version="2.2.0" targetFramework="net451" />
<package id="form2js" version="1.0.0.30224" targetFramework="net45" />
<package id="jQuery" version="2.0.3" targetFramework="net45" />
<package id="jQuery.UI.Combined" version="1.10.3" targetFramework="net45" />
<package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
<package id="MarkdownSharp" version="1.13.0.0" targetFramework="net451" />
<package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.2" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.HelpPage" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.OData" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages.Data" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages.WebData" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net45" />
<package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net45" />
<package id="Microsoft.jQuery.Unobtrusive.Ajax" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net45" />
<package id="Modernizr" version="2.7.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net45" />
<package id="SlidesJS" version="3.0.4" targetFramework="net451" />
<package id="System.Spatial" version="5.6.0" targetFramework="net45" />
<package id="T4MVC" version="3.7.4" targetFramework="net45" />
<package id="T4MVCExtensions" version="3.7.4" targetFramework="net45" />
<package id="WebActivatorEx" version="2.0.4" targetFramework="net45" />
<package id="WebGrease" version="1.6.0" targetFramework="net451" />
<package id="WindowsAzure.Storage" version="2.1.0.3" targetFramework="net45" />
</packages>
I tried to deploy as a website just to see what the difference would be. The table connection strings were in appSettings from the earlier attempts to get past the timing issue, so it made sense to try the websites deployment option (not a cloud web role).
The error from this attempt was
[FileNotFoundException: Could not load file or assembly 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
[FileNotFoundException: Could not load file or assembly 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
Candor.WindowsAzure.Logging.Common.Table.CloudTableLogger.WriteInternal(LogLevel level, Object message, Exception exception) +0
Common.Logging.Factory.AbstractLogger.Info(Object message) in c:\_oss\common-logging\src\Common.Logging.Core\Logging\Factory\AbstractLogger.cs:504
Candor.Configuration.Provider.ProviderCollection`1.SetActiveProvider(T provider) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor\Configuration\Provider\ProviderCollection.cs:166
Candor.Configuration.Provider.ProviderResolver`1.AppendActive(T provider) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor\Configuration\Provider\ProviderResolver.cs:75
This was odd, since the other working solution web role deployed to the cloud now, has that reference set as CopyLocal=false. But when I set it to true in this non-working solution, it started to work in the website deployment.
Next I redeployed the cloud web role with this component set as CopyLocal=True and it now works. I don't know why this is required in one project deployment and not the other, While both projects required the other azure components to be CopyLocal=true.
There is still one lingering problem with startup speed, but I'll leave that for another question, if I don't figure it out. For some reason this smaller project goes in a busy/recycle loop after it starts, but the page loads now and then. It is quite odd since it has fewer dependencies initialized on startup, that is providers instantiated that write a single log entry each.
Straight point to the question is - CloudConfigurationManager.GetSetting will read the given config key from Cloud Project settings if defined or else will fall back to actual project App Or Web config. So if you make sure that it exists at one of the places, it should work fine. As you confirmed that it is working locally, it should work exactly the same way even after deployment.
Other case that can happen is when you are having multiple config files for local and cloud deployment environments and that config could be missing from your cloud configuration file that you used to deploy into cloud.
In my case, I used SlowCheetah (NuGet package) to transform App.config files. In Debug it did not use the Transformation. Using the Debug settings in the "root"-config file solved my problem.

Resources