RuntimeInformation and OSPlatform class does not exist after Upgrading to .NET5.0
See original GitHub issueI do not know if this is a good place for this issue or not, but after updating the Microsoft.Extensions.DependencyInjection.Abstractions
to version 5.0.0 it does not recognize the RuntimeInformation
and OSPlatform
classes.
This repo can reproduce this problem.
The strange thing is that these classes are available in versions 4.5 and 4.7, but not in 4.6!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Determine Operating System in .NET Core
Method. System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(). Possible Argument. OSPlatform.Windows OSPlatform.OSX OSPlatform.
Read more >CA1416: Validate platform compatibility (code analysis)
A violation only occurs if the project does not target the supported platform ( net5.0-differentPlatform ). This also applies to multi-targeted ...
Read more >Platform compatibility analyzer
A Roslyn analyzer that can help detect platform compatibility issues in cross-platform apps and libraries.
Read more >System.Runtime.InteropServices.RuntimeInformation 4.3.0
Provides APIs to query about runtime and OS information. Commonly Used Types: System.Runtime.InteropServices.RuntimeInformation System.
Read more >Migrating from .NET Framework to .NET Core: Tips and Tricks
NET Core console app. The results were the same when running the console app on Windows and Mac. Thus, when a library does...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the investigation, @joperezr. I’m going to close this issue as “by design” since there isn’t a change needed in our NuGet packages.
@mjebrahimi - like @joperezr mentions above, you can resolve this by adding a PackageReference to https://www.nuget.org/packages/System.Runtime.InteropServices.RuntimeInformation. Thanks for reporting the issue. This information can unblock someone else if they run into the same problem.
Actually just looked at it again and what was happening here before (and the reason why it worked) is that when folks used this package in net461 it was causing the netstandard facades to be includded in your project, which in this particular case was helping resolve these two types. That is why @eerhardt you don’t see a dependency explicitly on the RuntimeInformation package but it was still getting pulled in. Now this package doesn’t require the netstandard facades any longer (also resulting in your bin output folder for net461 to be much cleaner 😄) but that is also meaning in this particular case that these two types are not resolving. As explained above, a simple package Reference to the RuntimeInformation package should resolve this.