Getting a FileNotFoundException for a reference to a .NET Framework 4.6.2 library out of a .NET Framework 4.6.2 library that was loaded by a .NET 5 project.
Tried all known solutions:
FileNotFoundException (DLL not found)
How to enable assembly bind failure logging (Fusion) in .NET
https://web.archive.org/web/20131212004447/http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx
FileNotFoundException when loading dll
Interestingly, the Fusion Log does not list any access attempt to the problematic dll file.
Compiled the project via Rebuild, nothing helped.
After having created a completely new library and placed only the isolated method there that needs to be accessed and the error reoccurred also, it was clear, that this isn't a setup problem.
Solved this problem with the Clean Solution command!
This command is available:
in the context menu of the solution entry in the Solution Explorer
in the Build menu of visual studio
Related
I am creating an API-Addin for a Program that uses .NET Framework 4.7.2 and I cannot change that. I am adding the ComponentOne (.NET 4.5.2) DLLs in Visual Studio. When the Addin in the external program tries to load the dll, there is an error that the DLL cannot be found. I am pretty sure this problem is caused by the different .NET Framework versions. Is there any workaround which could help when loading DLLs with lower .NET versions?
I managed to find a solution where I manually load the DLL before it is referenced. I used the Assembly.LoadFrom(assemblyPath) function.
https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.loadfrom?view=net-6.0
I am currently working with 2 C# projects inside one VS 2017 solution. One project contains all the business logic and the other simply the UI. The UI, of course, references the Core project.
The Core solution uses RestSharp package on it's code, so I installed it using NuGet. When I run the solution and I reach the part of the code where RestSharp is used, the following exception is thrown: "System.IO.FileNotFoundException: Could not load file or assembly 'RestSharp'".
The problem gets solved if I also install 'RestSharp' package inside the UI project. But, I am trying to avoid that as the UI does not need to use that package.
Is there a way to avoid that? Regards
Check if Copy Local is set to true for the RestSharp reference. When it is set the RestSharp dll will be copied along with the Core dll.
I've ran into a weird problem.
I basically have my own web-stack for .NET-core which I've built into a few .dlls, and I want to reference these from another ASP CORE-solution.
VS seems to find the assemblies, where I can navigate types etc.
I can also build the project without any issues, but when IIS then runs the server I get an internal server error stating:
FileNotFoundException: Could not load file or assembly 'myDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
The referenced DLLs are in the debug-folder, and the really weird thing is that if I create a new ASP Core project in the same solution as the web-stack, I can reference and use it without any problems.
Why is this happening only when running on a project outside the web-stack's solution, and what can I do to make it runnable everywhere?
The .NET Core Tooling in VS 2017 (< 15.3 preview) / .NET CLI < 2.0 doesn't fully support referencing assemblies on disk. You need to package the library up as a NuGet package or use a project reference ("same solution"). The technical reason is that all the required assemblies and versions are resolved during compilation and written to the .deps.json file. When loading arbitrary assemblies, this might fail because either the assembly or its dependencies cannot be found (or a conflict with each other).
for load the external dll in core project, needed to:
vs 2017 with version 15.3 or upper.
Microsoft.Extensions.DependencyModel NuGet package installed in your project.
Maybe Relevant information: I have a web application I built with .net 4.5. I wanted to deploy to Azure's Web Sites but it only supports .net 4.0 so I downgraded the project to .net 4.0.
It still works when run locally.
When I publish to Azure, i get this error:
Could not load file or assembly 'System.Net.Http' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I have tried removing the Web API with nuget and readding it, as another question on SO suggested but I still have the same problem.
I have tried close/open VS, and clean/build.
I solved a similar problem (System.Web.Http and System.Net.Http.Formatting) error by removing the reference to problem reference (which was pointed to my .Net installation folder) and replacing it with the reference file in my packages folder that was installed by the Microsoft.AspNet.WebApi NuGet package.
I had the same problem. However, updating assembly versions, copy local, and specific version settings alone did not solve my problem. In my application configuration I deploy a web and a worker role to a cloud service. After creating the service, on the configure tab I set the Operating System to Windows Server 2012 R2 to get the support for .Net Framework 4.5.1. But the error still occured.
Upon further research, I found that the *.cscfg file for my cloud service overrode the portal setting with an obscure osFamily setting of "3". When I started my project it was on MVC3 and did not yet have WebAPI and framework 4.5.1. osFamily 3 was the latest at the time.
In my latest deployment I had upgraded my site to 4.5.1 framework and MVC5. I verified it worked locally on my development machine. But it didn't work after deployment with the error referencing System.Net.Http.Formatting version 4.0.0.0 not being found. I later saw the deployment log that showed the source error
"The feature named NetFx451 that is required by the uploaded package is not available in the OS * chosen for the deployment."
Here is the blog article that led me to the solution to change the osFamily setting to 4. Then my site worked after a fresh deployment.
http://tech.trailmax.info/2014/02/azure-deployment-the-feature-named-netfx451-that-is-required-by-the-uploaded-package-is-not-available-in-the-os-chosen-for-the-deployment/
System.NET.HTTP.dll only depends on System.dll, System.Core.dll and mscorlib.dll.
Make sure you have this DLL (System.NET.HTTP.dll) in your deployment package (you can do RDP connect and check deployment folder). Play with "Copy to Local" property of reference, or include this dll in your project on root level and set type "content" in properties.
Also System.Net.Http.dll is also supported for .NET 2.0 as i see - that might cause an issue. So additionally to above try to set property of reference "Specific version" = true
Azure Now supports .Net 4.5 on the configuration tab you can select .Net framework version V3.5 or V4.5 I have several MVC Web Apps with Numerous supporting DLLs all all compiled in V4.5. What Azure does not support is V 4.5.1 (from the VS 2013 RC release).
I had the same issue with an asp.net application with some Web Jobs which deployed to the same Azure App Service. It was solved by referencing the same System.Net.Http (nuget package) from all projects.
If all of the options you did didn't work, please try restarting (close / open as "admin") your visual studio, then clean / rebuild. This has fixed my problem.
Though this is only for my local machine, haven't tried yet with other environments like in azure or in any server.
I had the same experience with missing System.Net.Http issue.
I've got a Solution with lots of projects and all but one of them is behaving. The one that is not working is a ConsoleApplication, and it relies on C# Class Library project. I've added a reference to the library project, and add the namespace (which I've checked is correct), but everywhere I reference the classes in my library, I get:
The type or namespace 'MyClass' could not be found (are you missing a using directive or an assembly reference?).
The library project is building successfully (I can see the DLLs appear in the bin folder) and I've tried a project reference, and also a reference to the DLL itself. Neither works.
Also, all projects are set to build with a platform target of 'Any CPU'.
I've tried pretty much every suggestion I've come across on forums with no success. Can anyone shed some light on what's going wrong?
Thanks
This solved the problem:
The console application had a Target framework of .NET Framework 4 Client Profile, whereas the library just had .NET Framework 4. I set the console app to .NET Framework 4 and it all builds perfectly.
My bet is on a framework mismatch between your library and you app...
Check if your library is not building with a superior version than you app, or if your app is building with a Client profile flavor
It is probably that one of your DLLs references some part of the .net framework that is not referenced in your console application. For example if one of your class library projects has asp.net server controls in and references System.Web, but your console application does not reference System.Web it will not build and you will get that error. But it is not obvious because the DLLs referenced are stored in the GAC so they would never appear in your bin folder.
I had to simply restart visual studio for reference to work but make sure you have reference added in .csproj file.
If you still experience the issue, make sure the class you're referencing is public and that Asp.net core Framework version match.
Sounds weird,
Have you tried to remove the reference of the project and add it again? Check if your console app has got all the right references.
You could also inspect the .csproj file and see if everything is correct in there.
Just Check that you "Class Library" project has classes in it or if it is a data access layer project which include only a .edmx Model check the Model designer is found and it generates fine.
Good Luck
I worked with syncing the framework, but still, it was giving issue.
So I tried another way.
Right-click on the dependency, and select Add project reference. I added the required project then the error was gone.