Compatibility of .NET Standard 2.0 library that uses StoreAPI and WPF .NET 8.0?
I am working with a .NET Standard 2.0 Library that we wrote and use both in a WPF + .NET Framework 4.8 windows application and in a UWP windows application. This .NET Standard 2.0 library has references to Microsoft.Windows.SDK.Contracts version 10.0.22621.2428 nuget package. Our apps use this library to call to Store API's and Windows.ApplicationModel.Package.Current; to programmatically return the app's package name and version.
Now I want to publish a new WPF .NET Core 8.0 application in Store. When our library (mentioned above) is added as reference it throws error from the library "System.PlatformNotSupportedException" at line Windows.ApplicationModel.Package.Current;
I changed WPF settings to
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<SupportedOSPlatformVersion>10.0.22621.0</SupportedOSPlatformVersion>
I wrote code in WPF App to read package name and version by calling "Windows.ApplicationModel.Package.Current" in a button click event and it did worked.
private void btnWinRTTest_Click(object sender, RoutedEventArgs e)
{
Windows.ApplicationModel.Package package = Windows.ApplicationModel.Package.Current;
var Packageversion = new Version(package.Id.Version.Major, package.Id.Version.Minor, package.Id.Version.Build);
var PackageDisplayName = package.DisplayName;
var PackageUniqueName = package.Id.Name;
this.Title = string.Format("{0} - {1}",PackageDisplayName, Packageversion.ToString());
}
But the same existing code in the library function, throws "System.PlatformNotSupportedException" at line Windows.ApplicationModel.Package.Current;
Whats the trouble? Any clues / suggestion?