Use WinRT API in netstandard2.0 library referenced by .NET 5.0 with IsOSPlatform check

0

We are in the process of updating our netcoreapp3.1 libraries and programs to net5.0. These libraries are referencing one netstandard2.0 library which uses WinRT if supported via a NuGet reference to Microsoft.Windows.SDK.Contracts.
This is checked via RuntimeInformation.IsOSPlatform(OSPlatform.Windows). If I now use this library from net5.0 and execute the part using WinRT I get the following exception (executed on Win 10 20H2 with .NET 5.0.2):

System.PlatformNotSupportedException: Operation is not supported on this platform. (0x80131539)

If I read up on the breaking changes for net5.0 I get that this package is no longer needed/supported and to use WinRT you should target e.g. net5.0-windows10.0.17763.0. But I would like to keep the library platform-agnostic as netstandard2.0 and keep using the IsOSPlatform-switch, as other parts of the library are also used on Linux or using net471.

How can I make this work with net5.0 as we did with netcoreapp3.1?

c#
.net
windows-runtime
interop
.net-5
asked on Stack Overflow Feb 10, 2021 by Christoph Fink • edited Feb 10, 2021 by Christoph Fink

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0