warning MSB3258 on mscorlib for shared reference - c#

So I am currently working on a .NET Framework project that is referencing a DLL made by another dev I am working with that I will call "random.dll". My project is targeting .NET 3.5. I have no compiler errors in my project but when I attempt to build while referencing this DLL I receive a warning during the build saying the reference could not be resolved:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3258: The primary reference "random.dll" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework.
This build warning causes my build to fail when attempting to reference classes in that reference.
I then zipped up my project and sent it to the dev who was able to build it themselves with no changes to the project. I am trying to figure out what could possibly be different on only my machine that would cause this issue.

Change your .net framework to 4.0.0

Related

.NET Framework: How to update System.Runtime?

I have a DLL compiled from a project of type "Class Library" which has a target framework of netcoreapp3.1 (EDIT: now netstandard2.0).
I then reference this DLL in another project, a Windows Forms application, which targets .NET Framework 4.7.2 (EDIT: now 4.8).
When trying to compile the Windows Forms application, I get the following error:
Error CS1705: Assembly 'BC' with identity 'BC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
I would like to update System.Runtime on the WinForms project to use version 4.2.2.0 (which is apparently required by my DLL), however, I found no way to do so - there are no NuGet packages installed and the references section in Visual Studio doesn't seem to include System.Runtime directly:
How do I update System.Runtime and resolve the error?
Try any of the following:
Upgrade your WinForms project to .NET 4.8, because there have been a lot of compatibility fixes in that release. .NET 4.8 still has issues when interfacing with .NET Core libs, but many problems will just be gone.
Or try changing your library to .netstandard2.0. Then it should always be compatbile to Net Framework.
For best compatiblity, try doing both: Setting the library to .netstandard2.0 and change the WinForms app to .NET 4.8.

What causes error MC1000: Unknown build error, 'Could not find assembly 'System.Runtime.InteropServices.PInvoke...'

The full error information is
Code: MC1000
Description: Unknown build error, 'Could not find assembly 'System.Runtime.InteropServices.PInvoke, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.'
File: C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets 243
I'll provide a little context in case it's helpful. This is in a .NET Core 3.0 WPF project, that references a .NET Core 3.0 Console App, that references a .NET Standard 2.0 Class Library. All levels except the top level WPF project also reference a slew of Nuget packages, most of which are probably targeting .NET Standard 1.3 or 2.0. They are all targeting a compatible .NET Standard, I don't have any that are throwing the NU1701 warning.
So the question: what is causing this error?

C# - Xamarin.Froms.Build.Task.GetTaskAbi - error

I have been getting the below error everytime I try to build a Xamarin Forms App.
Does anyone have a solution to this error.
I have uninstalled and reinstalled VS2017 two times.
I have deleted all the folder to do a clean install.
Severity Code Description Project File Line Suppression State
Error The "Xamarin.Forms.Build.Tasks.GetTasksAbi" task could not be loaded from the assembly C:\Users\Regardt.nuget\packages\xamarin.forms\3.0.0.446417\build\netstandard2.0\Xamarin.Forms.Build.Tasks.dll. Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. App2.Android
Download and install .NET Framework 4.7.1 or 4.7.2 then seemed to resolve the issue.
Microsoft .NET Framework 4.7.1 (Offline Installer):
https://www.microsoft.com/en-us/download/details.aspx?id=56116
Microsoft .NET Framework 4.7.2 offline installer for Windows:
https://support.microsoft.com/en-us/help/4054530/microsoft-net-framework-4-7-2-offline-installer-for-windows

System.Data.Linq in netstandard20

I have a netstandard20 project that references a .Net 4.6 Project, all compiles and runs except where I call any functionality in the .Net 4.6 project, I get the following error.
FileNotFoundException: Could not load file or assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
In VS 2017, in the project explorer under Dependancies / SDK / Microsoft.NETCore.App I can see System.Data.dll and System.Data.Common.dll but no reference to System.Data.Linq.dll, I am assuming this is my problem and it has not been pulled in.
How do I get my project to include System.Data.Linq.dll?
If I include C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Data.Linq.dll I get the following error
BadImageFormatException: Could not load file or assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
I was able to solve my need to use System.Data.Linq in a .NET Standard 2.0 library by using the Mindbox.Data.Linq NuGet package.
After installing it you should be able to use the System.Data.Linq namespace just like you could when writing for .NET Framework!
System.Data.Linq is not part of .NET Standard 2.0 and .NET Core 2.0 and therefore cannot be used on that platform.
Even tough you have been able add a reference to a .NET 4.6 project via the compatibility shims, it fails at runtime because of a feature that is not available on the target runtime

Portable Class Library - you must add a reference to assembly 'System.Net, Version=2.0.5.0

We have a Portable Class Library targeting 4.0. A WPF application references this which is a standard .NET 4.0 app.
The PCL references the System.Net.NetworkCredential class.
When we build the .NET 4.0 app we get an error:
The type 'System.Net.NetworkCredential' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.
Several posts say to install KB2468871. That doesn't apply/change things.
If we add an assembly reference to "System.Net 4.0.0.0" in the app then the error changes:
Reference to type 'System.Net.NetworkCredential' claims it is defined in 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Net.dll', but it could not be found...
Of course NetworkCredential is not in System.Net, it is in the System assembly.
If I retarget to 4.5 everything works, but we need to use 4.0.
Any ideas? Thanks.
KB2468871 enables portable libraries to run on 4.0, it does not enable them to build in Visual Studio.
The first error should go away if you add a reference to System.Net, 4.0.0.0. If it does not, then you're machine is missing a required patch.
If are using:
Visual Studio 2010
You need to install Portable Library Tools: http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/. This will install a patch that will make this work.
Visual Studio 2012 or Visual Studio 2013
This should work out of the box, if not, then you install is likely in an incomplete state. Try repairing your installation.

Categories