.Net Core deps file modification not reflected - c#

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.

Related

.NET Standard: dependency not copied to output directory

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>

Could not load file or assembly ... after changing the TargetingFramework

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.

Error System.IO.FileLoadException: 'Could not load file or assembly 'log4net, Version=2.0.8.0 in .NET Core

I am doing migration my old .NET 4.5.2 console application to .NET Core, all the code is getting compile successfully but while executing console application I am getting following error
System.IO.FileLoadException: 'Could not load file or assembly 'log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'.
The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
In my console application there are few third party dlls along with our internal dlls are referenced which are build on .NET 4.5.2 framework.
Even problem is that before enter my project debug mode, this error has been thrown out due to this I am unable to debug code to find that which assembly is causing this issue.
Do I need to migrate my all internal dlls as well as third party dlls into .NET core which are referenced into my console application?
I know there are many question has been asked for this problem, but these questions are related to .NET framework 4.5.* but I didn't get any solution for migration existing .NET 4.5.2 to .NET Core
Finally I got an issue. The problem was that log4net.dll was not getting copied from this location (i.e. C:\Users\User.nuget\packages\log4net\2.0.8\lib\netstandard1.3) to bin/debug folder. I have manually copied this file and it started working.
Now I need to see why this file was not getting copied.

CryptoObfuscator error obfuscating UWP assembly

When trying to obfuscate a UWP (WinRT) AnyCPU assembly using CryptoObfuscator, the following error messages are observed:
1.) When merging in LogicNP.CryptoLicensing.WinRT.dll (a WinRT assembly) into a UWP DLL:
Error occurred while obfuscation: - .Net framework version type of the licensing assembly (Silverlight) does not match the version type of the obfuscating assembly (Normal).
2.) When merging of the licensing assembly is ignored:
Error occurred while obfuscation: System.IO.FileNotFoundException - System.IO.FileNotFoundException: could not result: System.Runtime, Version=4.0.20.0, Culture=neutral... Specify the path where this assembly resides using 'Search Directories'
Has anyone successfully used CryptoObfuscator (which is advertised as working on any .NET assembly) successfully?
There are in fact two issues to take into account when using CryptObfuscator in this scenario:
To obfuscate for other .NET versions, the following must be added to each relevant csproj in addition to setting the target framework to :
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
This resolves most can not find file issues when obfuscating.
For System.Runtime, you will need to download and open the NuGet package of System.Runtime. In the lib folder you will find some nice hacks that depend on the CLR in use and glue the rest of your .NET assemblies together with the CLR, such as using forwarded types for .NET 4.7. But in the ref folder such as for netstandard1.5 you will find a System.Runtime.dll. Copy that one manually to the output folder or a location where CryptoObfuscator will search.
You can also put it in another folder, and specify in CryptoObfuscator a search directory using Project Properties or in XML:
<SearchDirectories>
<SearchDirectory Path="PATH" />
</SearchDirectories>
Try Download from nuget "Microsoft.NETCore.UniversalWindowsPlatform" and copy "System.Runtime.dll" downloaded from nuget to CryptoObfuscator folder.

Missing Dependency: Castle.DynamicProxy2 after install LINQtoExecl from NuGet

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?

Categories

Resources