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.
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.
That's it for this lesson, onwards to lesson 3 :)
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:Sigh; another report of problems with System.Numerics.Vectors in a .net standard 2.0 lib running on net461 causing binding problems. Yay?— Marc Gravell (@marcgravell) August 21, 2018
Sorry but we messed up. We tried to make .NET Framework 4.6.1 retroactively implement .NET Standard 2.0. This was a mistake as we don't have a time machine and there is a tail of bugs.— Immo Landwerth (@terrajobst) August 21, 2018
If you want to consume .NET Standard 1.5+ from .NET Framework, I recommend to be on 4.7.2. https://t.co/E7H2Ps9cLk
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.Note that that this has nothing to do with missing APIs (although .NET Framework 4.6.1 misses about 100 APIs). It's all about binding policy, assembly identities, and treatment of framework assemblies in tooling (MSBuild, ClickOnce, test runners etc).— Immo Landwerth (@terrajobst) August 21, 2018
That's it for this lesson, onwards to lesson 3 :)
I learnt exactly the same lesson!
ReplyDeleteGoing 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!).
ReplyDeleteNext, 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.