[Azure Function]Could not load file or assembly 'System.Configuration.ConfigurationManager' - asp.net-core

.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

Related

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

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.

System.Web.ApplicationServices in .NET Core 2

I'm building a Web API in .NET Core 2. I'm using some custom nuget packages to leverage their built in functionality. These custom packages were built against an older .NET version (4.6.1). The problem is some of these packages have references to the old System.Web dll. I'm getting this warning on some of the custom packages in the solution
package was restored using '.net framework version=v4.6.1 instead of using the proj target framework.
The app is also throwing this exception below when I call code in one of the custom packages
System.IO.FileNotFoundException: Could not load file or assembly System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral,The system cannot find the file specified
Is there any way around this other than re-writing the code in my web Api?
No. System.Web is completely incompatible with Core. While Microsoft opened up NuGet packages that target .NET Framework to be utilized in with .NET Core, it did so based only on .NET Standard 2.0 compatibility, and makes no assurances that the packages will function in part or whole. You'll actually get a warning during compile telling you as much. Also, while you can actually have something like an ASP.NET Core app actually target .NET Framework, again, compatibility of third-party components is not guaranteed, simply because they target the same framework.
Long and short, if there's any dependency on System.Web at all, you can't use it.

Self-contained Asp.net core (1.0.1) app cannot find RestSharp dll

I have an ASP.Net Core (1.0.1) web app. One of the packages it consumes itself consumes RestSharp. When built, the RestSharp dll is indeed in the app root. But when I deploy and browse to the app, I get the following error:
Application startup exception: System.IO.FileLoadException: Could not load file or assembly 'RestSharp, Version=105.2.3.0, Culture=neutral, PublicKeyToken=8d483824b1b4e30c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'RestSharp, Version=105.2.3.0, Culture=neutral, PublicKeyToken=8d483824b1b4e30c'.
Let me be clear, here... the dll is the correct version: 105.2.3.0.
Now, if I register RestSharp to the GAC, all is well and the website works. But this is a .Net Core self-contained app and it shouldn't be looking in the GAC at all (should it??).
I'm really lost and confused. I honestly don't know what's going on, so I really could do with some help.
App folder after publishing:
MyApp/
MyApp.exe
....
....
etc.
RestSharp.dll (v105.2.3.0)
web.config
appsettings.json
UPDATE:
Sorry, I should have also mentioned that I'm targetting net46.
As mason rightly pointed out: You said "This is a .NET Core self contained app". But that's not true if you're targeting .NET Framework 4.6.

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

How do I stop Ninject for WebApi failing on "var kernel = new StandardKernel();"

I just installed Ninject.MVC5 into my solution (I have an MVC project and a WebApi project in there and I wanted Ninject for both).
Then I installed WebApiContrib.IoC.Ninject to build on the previous install so that I could use Ninject in the WebApi package.
Then I updated the packages (because NuGet showed updates to install - even though I had updated the packages directly prior to installing Ninject).
I tried running my WebApi project but it failed on var kernel = new StandardKernel(); in NinjectWebCommon.CreateKernel() with this error:
An exception of type 'System.IO.FileNotFoundException' occurred in Ninject.dll but was not handled in user code
Additional information: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Having read several answers on here and contemplated certain relatively complex solutions I tried one more thing which I will share in the Answer in case it helps anyone else...
I removed WebApiContrib.IoC.Ninject from the WebApi project (via NuGet: Manage and then untick to remove) and then added it back.
Project runs and behaves as expected, and no updates are required after adding WebApiContrib.IoC.Ninject back in to WebApi project.
The update that NuGet identified as required overwrote/broke something that was fixed by this answer.
Add the package Microsoft.Aspnet.Mvc from Nuget.
Solved for me.
In my case, MVC4 for Framework 4.0 and Visual Studio 2017