Could not load file or assembly 'Microsoft.Extensions.Options, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 - asp.net-core

After adding some nuget packages, my asp.net core app has stopped working and started to generate this error once deployed to Amazon windows server [Works OK on my dev machine (as always :-)].
Visual Studio: 2019
Target Framework: netcoreapp3.1
Installed: dotnet-hosting-5.0.7 + dotnet-sdk-5.0.401
in my deps.json file, the Microsoft.Extensions.Options always appear in the right version (3.1.10) and never in 5.0.0 version.
Any ideas where the problem might come from?

I had similar issue. The error is:
FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Options, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified
The fix: upgrade Microsoft.Extensions.Options in Nuget from version 2.x.x to latest version (version 5.0.0) and delete all obj and bin folders and rebuild.
My projects are on .NET Framework 4.7.2. When Microsoft.Extensions.Options get updated, several other Nuget packages that were also on version 2.x.x also got updated.

After uninstalling most of the Nuget packages and reinstalling them with the right version, the problem was resolved.

Related

[Azure Function]Could not load file or assembly 'System.Configuration.ConfigurationManager'

.Net Core 3.1. I used System.Runtime.Caching library, it depends on System.Configuration.ConfigurationManager.
But there is a amazing thing happened, I test it in MS unit test project[.NET Core 3.1], it runs well, then in Azure Function project[.NET Core 3.1], it will throw 'Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.' error, and in project .deps.json, also have dependency configurations
Below is Stack Trace:
System.Configuration.ConfigurationManager 6.0 won't support .net SDK 3.1, so update the "System.Configuration.ConfigurationManager" version to 4.7.0 and any other lower version. and try it.
According to your description, it seems it missed the nugetpackage System.Configuration.ConfigurationManager inside your application.
I suggest you could install the package System.Configuration.ConfigurationManager inside the local and re-publish again.
Install-Package System.Configuration.ConfigurationManager

.NET Core 2 project - TypeLoadException

I have a .NET core 2 project cloned on my newly bought Laptop (running on Win10). I have installed VS Community 2017 along with .Net core 2 framework. When I load the solution, I have working on my old PC, I got dependency errors marked with a yellow triangle in the solution explorer. These are two types:
Microsoft.Extensions.Primitives 2.0.0-preview1-final depends on System.Runtime.CompilerServices.Unsafe (>= 4.4.0-preview1-25219-04) but System.Runtime.CompilerServices.Unsafe 4.4.0-preview1-25219-04 was not found. An approximate best match of System.Runtime.CompilerServices.Unsafe 4.4.0-preview1-25305-02 was resolved.
Package 'librdkafka.redist 0.11.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
Apart from these warnings, I have a runtime exception saying:
System.TypeLoadException: 'Could not load type 'Microsoft.AspNetCore.Builder.AuthenticationOptions' from assembly 'Microsoft.AspNetCore.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.'
I have the AspNet.Security.OAuth.Validation NuGet package referenced with version 1.0.0, which does not look 100% right to me, but it has been working
well so far.
This is the exactly same project as the one working on my old PC, nothing changed.
warnings in solution explorer
Any ideas?
find
PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final"
and remove . then build it.

Can't get NLog 2.0.1 version from NUGet

In Visual Studio 2010, in Package Manager Console I type:
Install-Package NLog -Version 2.0.1
And I'm getting 2.0.0 (on disk). On Codeplex there's no 2.0.1 version. Version 2.0.1 is required for ServiceStack.Logging.NLog because of error:
Can't load file 'NLog, Version=2.0.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' or one of it dependencies. (Exception HRESULT: 0x80131040)
Version 2.0.1 is also listed on NuGet available packages.
I have replaced NLog.dll and ServiceStack.Logging.NLog.dll with files from latest ServiceStack v3 snapshot and my program runs fine (ASP .Net4 Web Application) but this is not solution for long time. In ServiceStack snapshot NLog.dll is 2.0.0 and ServiceStack.Logging.NLog.dll is 1.0.8.
Try NLog version 2.0.1.1 or 2.0.1.2 from NuGet.
The NLog assembly in those packages has a version of 2.0.1.0

Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35'

In Visual Studio 2012 I created an ASP.NET MVC 4 project where the target framework is the .NET Framework 4.5. When I deployed my project to a web server it gave the following error:
Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file
specified.
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where
it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or
assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
The system cannot find the file specified.
Source Error:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237
I had the same issue today during deployment. I was able to fix it by marking the assembly to be copied to the deployment file.
In order to do this, in my Visual Studio project, select the System.Web.Http.Webhost assembly in your references and alter the 'Copy Local' property to True. I had to repeat this for a few other assemblies that were missing.
Thanks to this website for the tips - http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx/
Check the bin folder of your deployed project. It should contain System.Web.Http.WebHost.dll.
If this dll is in this folder, check it version. If it isn't 4.0.0.0, then you should deploy version 4.0.0.0 or change your web config to use other version (not really good idea because of dependencies)
Try to reinstall Microsoft.AspNet.WebApi package. Open Package Manager Console and type:
Update-Package Microsoft.AspNet.WebApi -reinstall
Be careful, this command will remove all dependencies and you will have to install them manually.
I had this error with an old project that I was going back to do a bit of work on. It turns out the project wasn't actually using WebApi so I uninstalled Microsoft.AspNet.WebApi using NuGet. That solved the problem for me.
If I'd actually have needed WebApi I'm sure installing it again would have fixed the error too.
I ran into this today after setting up a new Team City Build Agent. The new agent didn't have MVC 4 installed, perhaps part of the problem. Fortunately, I found this article which lead me to the solution. In Team City, I just updated the Build Step for the Nuget Restore so that it doesn't use the local cache.
This works because the cache may have been established by build runners with different (MVC) frameworks installed already.
I know this is answered but I thought I'd add something.
Every time I set "copy local" to true on a file causing the error I'd publish it and just get another one. So I just selected all of the files under references and set them all to true. This fixed the issue for me.
Important: This error message can be caused because you are deploying a 4.5 project to a server that doesn't have 4.0 installed. Make sure you have the .NET Framework version installed in IIS for the project you need. Some of these DLLs by default won't copy up, because it uses the core project DLL normally. Check to make sure your production server has the .NET version you're going with. I experienced this myself with a 4.5 project on a 4.0 server.
Ensure ASP.NET MVC 4 is installed on your server. Check it in the following location -
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4

ServiceStack Redis Client Expecting Older version of ServiceStack.Common

I just NuGetted ServiceStack.Redis 3.1.3 but as its dependencies it also gets ServiceStack.Common and ServiceStack.Text 3.1.6
Now when I build the application everything is OK.
But, when I run the application some of the Redis Client methods execute properly but some of them e.g. (RedisClient.GetAllKeys) gives throws the exception
Could not load file or assembly 'ServiceStack.Common, Version=1.0.4336.27526, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Then i removed all the dll's and nuget packgage config, and explicitly did a NuGet ServiceStack.Common -Version 3.1.3 and got it. But then when i tried to NuGet ServiceStack.Redis -Version 3.1.3 it automatically removed the 3.1.3 version of Common and downloaded the 3.1.6 version !!!
Arrrghhh, I hate over intelligent installers.
How do I fix this ?
Does the publisher of ServiceStack even know about this issue ??
Ok ! Found the Issue.
I was trying to use ServiceStack from a console application and it was configured to build in "ClientProfile" mode.
ServiceStack internally references System.Web which wasn't being accessible at runtime.
I switched the Application to Build using the full framework mode and everything works ok now.
Thanks anyways mythz !
Nope, ServiceStack was not aware of this issue. Though we'd like to know what's causing it.
I've tried a fresh install of ServiceStack.Redis and it works as expected.
To remove your dlls you need to go into NuGet package manager and finding the installed ServiceStack.Redis Package and clicking un-install. This should ensure the next install of the Project downloads it from the NuGet website and doesn't re-use your dirty dll cache.
Failing that ensure you have the latest version of NuGet and that your old NuGet caches are cleared. i.e. find and delete the NuGet /packages folder.