I just changed the .csproj from <TargetFramework>netcoreapp3.1</TargetFramework> to <TargetFramework>netstandard2.0</TargetFramework> and when debugging, I receive the following:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly '..., Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies.
The system cannot find the file specified. at CDMToJSON.Program.Main(String[] args)
I tried adding all missing .dll's in the folder (Sources\CDMToJSON\bin\Debug\netstandard2.0), but for one with the Newtonsoft.Json the error kept persisting, which made me think that there would be a better way to add these NuGets and dependencies.
Therefore, how can I add all these .dll's properly after changing the Targeting Framework?
netstandard TFMs are only for libraries. They cannot be used for projects which are directly executable, such as desktop apps, console apps, or unit test projects.
You need to pick a concrete runtime that your program will target, such as netcoreapp3.1 or net5.0, and then target it.
Related
I'm converting a .NET Framework library to .NET Standard 2.0, because I need to use it from both an old .NET Framework project and a modern .NET 5 project
In the original library, I use the ProtectedData class, which is part of the .NET Framework (from the System.Security.Cryptography assembly).
This is not part of the base .NET Standard library, so to make it work I've added the appropriate NugetPackage, System.Security.Cryptography.ProtectedData.
With this, the project compiles correctly, however when I try to run it I get the following error:
System.IO.FileNotFoundException: 'Could not load file or assembly
'System.Security.Cryptography.ProtectedData, Version=6.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The system cannot find the file specified.'
So I looked in the compilation output directory, and I see that there is no trace of a System.Security.Cryptography.ProtectedData.DLL file, its like the compilation system is not copying the dependency to the output directory. How can I fix this?
Found this answer on another forum, and it seems to work.
I added:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
to the .csproj file and now dependencies are being copied correctly.
Still would like an explanation as to WHY this is needed, since I never had to do this before for other projects...
If you are forced to use packages.config, the accepted answer won't work.
You can turn on Detailed build output to see where the compiler fails to copy the dll from the packages folder to the output folder.
To fix this, you need to add a Reference with a HintPath to the .csproj file in order for the build to resolve the reference from the packages folder.
Include should be set to the path the compiler is complaining about.
HintPath should be set to the correct path found by browsing the packages folder:
<Reference Include="'System.Security.Cryptography.ProtectedData, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'">
<HintPath>..\packages\PathToDll</HintPath>
</Reference>
I'm copying my program to a Virtual Machine to see what software I need and which settings I need to have enabled (or disabled). My program is running fine on my work laptop and on my own laptop (older version), but on the VM the program throws an error during run time.
My program is made out of one executable and many DLLs, both the Executable and the DLLs are able to start just fine including using the dependency system.drawing.common. But one of the classes in one of the DLLs gives an error that the dependency system.drawing.common could not be loaded. Rebuilding the DLL in question doesn't give a warning that something is wrong. See image below for the error I see.
[ERROR][12/18/2019 11:04:02 AM][Thread 0006]>
[akka://ModulairVisionFramework/user/AcquireImageActor] Could not load file ?
or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, >PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Cause: System.IO.FileNotFoundException: Could not load file or assembly >'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, >PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, >PublicKeyToken=cc7b13ffcd2ddd51'
at CameraSystem.Actors.AcquireImageActor.<.ctor>b__2_0(AcquireImage resp)
at lambda_method(Closure , Object , Action1 )
at Akka.Tools.MatchHandler.PartialHandlerArgumentsCapture2.Handle(T >value)
at Akka.Actor.ReceiveActor.ExecutePartialMessageHandler(Object message, >PartialAction`1 partialAction)
at Akka.Actor.ReceiveActor.OnReceive(Object message)
at Akka.Actor.UntypedActor.Receive(Object message)
at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)
at Akka.Actor.ActorCell.ReceiveMessage(Object message)
at Akka.Actor.ActorCell.Invoke(Envelope envelope)
What can the cause be that the main executable and the interface of the DLL are both using system.drawing.common fine, but a class in the DLL in question cannot use the dependency? And how can this issue be resolved? I have not faced this issue on my work laptop so far or on another computer (older version of my application but still uses system.drawing.common).
EDIT
In both the executable project as in the DLL in question I'm using the NuGet package manager for system.drawing.common. How the package is included:
<PackageReference Include="system.drawing.common" Version="4.6.0" />
I hit this same problem a week or so ago. If this is a .NET core assembly, the way you reference it makes a big difference. Instead of referencing the .NET lib directly (right click -> add reference), use a package reference in the project file:
<PackageReference Include="System.Drawing.Common" Version="4.6.0" />
I have a .NET Core project with many libraries as dependencies.
I wanted to change code in one of the library (a dll dependency) and wanted to run the project using the said new dll.
I changed the file version of the dll in the deps.json file but when i run the project using dotnet project.dll I see this exception thrown:
Application startup exception: System.IO.FileNotFoundException: Could not load file or assembly 'CuPletEngine, Version=16.0.229.1809, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
I made the change to deps.json file in order to force the application to to look for a different dll version.
Why would it still look for older version?
Please help.
I need to create ASP.NET CORE 2.1 web API from one class that is in Class library project(Targets 4.7.2).
I have added references to Microsoft.AspNetCore and Microsoft.AspNetCore.Mvc.Core.
Following call throws exception:
CreateWebHostBuilder().Build().Run();
Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Output window:
Exception thrown: 'System.IO.FileNotFoundException' in Microsoft.Extensions.DependencyInjection.dll
An exception of type 'System.IO.FileNotFoundException' occurred in Microsoft.Extensions.DependencyInjection.dll but was not handled in user code
Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I have tried adding System.Runtime.InteropServices.RuntimeInformation reference manualy with no success.
Am I missing something here?
If you have added the reference as nuget pakage you can try to add this property group in the csproj:
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> </PropertyGroup>
This property will copy the nuget dll in the output directory instead of use the dll in the nuget memory cache.
This can help you if in your solution you have many projects that refers different version of the same package (related dependencies too).
If you have added the reference as a simple "reference" to a known dll, you should verify the dll is in the output directory. Verify the version of that dll too. If it's different and the dll reference refers a strict version could be a problem.
I recently added the package LinqToExcel to my .net 4 WPF project and now when entering the designer I am presented with the following error:
System.IO.FileNotFoundException
Could not load file or assembly 'Castle.DynamicProxy2, Version=2.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The system cannot find the file specified.
LinqToExcel only has one dependency - log4net, which it installed as part of the NuGet process. Both are referenced and set to Copy Local. I'm not sure where the reference to Castle is coming from or how to go about fixing it.
Does anyone have any suggestions?