NetStandard / Net Framework reference hell - c#

I have a NetStandard 1.6 library that references an external library (System.Runtime.Loader, fetched from NuGet). If I reference my NetStandard library from a Net Framework 4.7 Windows-application I get a System.IO.FileNotFoundException when running the Net Framework application.
Full exception:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Now, I know full what the exception message means but I haven't got the foggiest on how to solve it in this situation.
Ideas?

I advise you to right click on the visual studio solution, go to manage nuget packages for the solution and check the versions of the various libraries you have. Any conflicts between the libraries will be present in the 'consolidate' tab. Alternatively, try removing the library reference from the project's reference folder and adding it back.

Related

How to fix source-code generator with .NET 6?

I ported my .NET 5.0 application to .NET 6.0 and now I found that the source-code generator fails. It shows the following error:
Generator 'PermissionGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Adding <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> to the property-group of the generator's project-file didn't really help. It does add System.Collection.Immutable.dll to the output folder (6.0.21.52210), but I still get the same error.
My generator is a .NET Standard 2.0 project, which might not be necessary anymore with .NET 6. So I also tried setting the runtime for the generator to .NET 6. This failed with another error:
An instance of analyzer ... cannot be created from ... Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
It seems that this is an issue with Paket v6 that seems to have a problem when used in conjunction with source-generators. I now use the traditional approach (including the analyzers directly in the project-file) and it now works again. I filed an issue with Paket (link).
I fixed this issue in my project by downgrading Microsoft.CodeAnalysis.CSharp to version 4.0.1. I guess newer versions have an issue finding System.Collections.Immutable.
This is with my source generator on netStandard2.0 and the project the source was being generated for on net6.0.

.NET Core 3.1 and Could not load file or assembly System.Data.Entity

The similar problem is written here, but not totally same.
I have a new Core 3.1 web project and old .netFramework 4.0 project working with EntityFramework (like BLL).
I'm trying to create an instance of the class from that BLL and getting an error "System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. No such file"
I've installed NuGet packages EntityFramework and EntityFrameworkCore, but it didn't help. In references of the Core 3.1 project I can't find any Entity library. How can I fix it?
Also I tried to add reference to a file System.Data.Entity.dll, but having another error then - "Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)"

xamarin intent extension with netstandard cause MT2001 error

I'm trying to add siri intent to my application.
I've created intent extensions project, than created ios library project (kit project as in a documentation) which has reference to .netstandard project with shared logic (core).
The core project use MvvmCross and when i'm trying to build main application it cause to:
error MT2001: Could not link assemblies. Reason: Error while
processing references of 'Diabetto.iOS.Intents, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null'
With more detailed logs i've known a reason of this error:
Error while processing references of 'Diabetto.iOS.Intents' --->
Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly:
'MvvmCross, Version=6.4.1.0, Culture=neutral, PublicKeyToken=null'
---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'MvvmCross, Version=6.4.1.0, Culture=neutral,
PublicKeyToken=null'
I've tried to add nuget reference to iOS class library, to iOS intent library (unsuccessful, got error
Failed to add reference. The package 'MvvmCross' tried to add a
framework reference to 'System.Drawing.Common.dll' which was not found
in the GAC
VS 2019 16.3.5, iOS project 13.1
To be clear, my project structure
and link to project
Solved this problem.
Explicit add nuget reference to System.Drawing.Common and MvvmCross.
Problem was in System.Drawing.Common, VS is trying to use GAC version. With nuget reference it use .net standard version.

System.IO.FileNotFoundException Error while refrencing a .net standard library inside a .net framework project

I'm getting System.IO.FileNotFoundException error while trying to add a .net standard library into .net framework project's references.
I have created a .net standard project which contains some other .net standard nuggets in its references, and it's output is a dll which I have inserted it as a reference in a .net framework library (actually it is a unit test project for it). But as I told before it always show me this error:
Message: Test method xDetector.Test.IntegreatedTest.TestMethod threw
exception: System.IO.FileNotFoundException: Could not load file or
assembly 'xFramework.NetCore.xDetector, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file specified.
I have try several ways like editing cproj file and adding other changing visual studio version (which currently is 2019) but no success.
Where the problem may come from?

Add Reporting.WinForms Reference to VS2015

I'm looking at adding the reference;
Microsoft.Reporting.WinForms
to my VisualStudio (2015) project but when I go to Add the Reference in the Solution Explorer I couldn't find it.
Eventually I added it through NuGet but now I am getting the error message;
Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
which leads me to believe I just haven't added the package properly. I've installed Microsoft SQL Server Data Tools through program features but still no luck.
What am I missing?
You can try by executing this into Package Manager Console
Install-Package Microsoft.Reporting.WinForms.v11

Categories