Error when .NET461 full framework references .NETStandard nuget packages

After updating MongoDb driver in a C# big project I start having a problem in a Web Project where we have this error after a deploy in test server (but we have no error in local machine of developers)

An assembly with the same identity ‘System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ has already been imported. Try removing one of the duplicate references.

This happens because MongoDB driver > 2.8 reference in the chain System.Buffer 4.4.0. If you take an empty .NET Full Framework 4.6.1 and references MongoDb 2.8.x driver you can verify that you have

image

Figure 1: System.Buffers reference for the project

This seems an innocuous reference, but if you look closely to what is inside System.Buffer you can verify that there is no package for full framework. Just check in the packages directory to verify that there is no .NET full framework package.

image

Figure 2: There is no full framework package inside System.Buffers

This imply that, when you build the project, in the bin directory you will find all the dll of netstandard project, because actually you are referencing netstandard 2.0 dll.

image

Figure 3: All netstandard dlls included in the bin directory of the project.

Now you have a problem, because you have netstandard runtime included in your project, most of the time it is safe, but there are situation where this can generate errors.

You can find the issue in GitHub #39362, that in turn is a duplicate of #39362 (my original issue).

Actually, if you want to avoid problems, you should be 100% sure not to reference any netstandard dll in a .NET 4.6.1 full framework project, or you should use full framework 4.7.2 or greater.

Gian Maria.

Error with dotnet restore, corrupted header

I’m trying to compile with dotnetcore 2.0 a project on Linux, but I got this strange error when I run the dotnet restore command.

image

Figure 1: Error restoring packages

The exact error comes from NuGet.targets and tells me: a local file header is corrupt and points to my solution file. Clearly this project builds just fine on another computer.

Since I’m experiencing intermittent connection, I suspect that nuget cache can be somewhat corrupted, so I run this command to clear all caches.

dotnet nuget locals --clear all

This clear all the caches. After this command run, I simply re-run again the dotnet restore command and this time everything went well.

Gian Maria.

.NET core 2.0, errors installing on linux

.NET Core 2.0 is finally out, and I immediately try to install it on every machine and especially in my linux test machines. In one of my Ubuntu machine I got an installation problem, a generic error of apt-get and I was a little bit puzzled on why the installation fail.

Since in windows the most common cause of .NET Core installation error is the presence of an old package (especially the preview version), I decide to uninstall all previous installation of .NET core on that machine. Luckly enough, doing this on linux is really simple, first of all I list all installed packages that have dotnet in the name

sudo apt list --installed | grep dotnet

This is what I got after a clean installation of .NET core 2.0

image

Figure 1: List of packages that contains dotnet in the name

But in that specific virtual machine I got several versions and a preview of 2.0, so I decided to uninstall every pacakge using the command sudo apt-get purge packagename, finally, after all packages were uninstalled I issued a sudo apt-get clean and finally I tried to install again .NET core 2.0 and everything went good.

If you have any installation problem of .net core under linux, just uninstall everything related with dotnet core with apt-get purge and this should fix your problems.

Gian Maria.