Lessons Learnt: Migrating From Net Framework to Net Core - Net Standard Libraries and Net Framework 4.6.1

My second lesson that I wanted to share is related to .Net Standard 2.0 libraries and .Net Framework 4.6.1. You might remember from last time that ".Net Standard 2.0 requires .Net 4.6.1 as a minimum", I've added emphesis to the as a minimum. In the beginning we were using most of our .Net Standard libraries without a problem in 4.6.1 but a couple of times we started hitting random errors that I couldn't pinpoint.

One example I had was using our .Net Standard 2.0 library which uses the System.IO.Ports NuGet package. On Windows everything appeared fine however when we used this with Mono we kept having "Unable to find port" exceptions. We knew this worked fine when we targetted .Net 4.5 however since switching to Net Standard and then the System.IO.Ports Nuget we were hitting this issue. At one point we even considered if this was a real deal breaker and did we have to revert the changes but I remembered the 4.6.1 being a minimum and the little note next to it.

That little 2 is key, when you continue down the documents page the additional information is the answer.
There are several issues with consuming .NET Standard libraries that were built for those versions from .NET Framework 4.6.1 projects. For .NET Framework projects that need to use such libraries, we recommend that you upgrade the project to target .NET Framework 4.7.2 or higher.
We then bumped up the project that we are using Mono with to .Net 4.7.2 and everything went back to normal.

This got me thinking further, should we ever use .Net Standard libraries with our .Net Framework 4.6.1 projects, my initial thoughts were no, it's just not worth the risk and I was sure I remembered a few people on Twitter discussing this.

And then Immo Landwerth chimed in with a few comments:

So this confirmed my thoughts, using .Net 4.6.1 with .Net Standard just isn't ideal. This isn't a massive issue for us as where possible we can always upgrade to 4.7.2 or still Multi Target for our more legacy projects.

That's it for this lesson, onwards to lesson 3 :)


  1. I learnt exactly the same lesson!

  2. Going through similar pains here as we try to move most libraries to .NET Standard 2. We're not going down the multi-targeting route - we first upgraded to net 472 (after learning the 461 issues the hard way as well!).

    Next, we only create new libraries/code in .NET Standard 2, and will gradually go back through existing ones to port over to netstandard2.0.

    Once all that is done we have to upgrade our web project to .NET Core and razor pages - although we might go direct to Blazor.


Post a Comment

Popular posts from this blog

WebUSB - An unexpected update...

Can you use BuildRoot with Windows Subsystem for Linux......

DotNet CLI , private NuGet feeds and Linux...