Compatibility of .NET Standard 2.0 library that uses StoreAPI and WPF .NET 8.0?

Richard Freytag 1 Reputation point
2024-05-08T17:36:27.52+00:00

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?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,481 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,691 questions
Microsoft Partner Center API
Microsoft Partner Center API
Microsoft Partner Center: A Microsoft website for partners that provides access to product support, a partner community, and other partner services.API: A software intermediary that allows two applications to interact with each other.
318 questions
{count} votes