.NET7 或 8 - WPF - 访问 Windows.Storage 抛出 System.TypeInitializationException

问题描述 投票:0回答:1

我们如何使用为商店打包的 .NET7 或 8 以及 WPF Core 访问 Windows.Storage?

举个例子,我们曾经这样做过:

Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Information()
            .WriteTo.File(Path.Combine(ApplicationData.Current.LocalFolder.Path, "app.log")
            .CreateLogger();

但是,ApplicationData.Current.LocalFolder.Path 现在抛出:

System.TypeInitializationException: 
'The type initializer for 'WinRT.ActivationFactory`1' threw an exception.'

Inner Exception:
COMException: ClassFactory cannot supply requested class

仅供参考:

<PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFramework>net7.0-windows10.0.22621.0</TargetFramework>
  <Nullable>enable</Nullable>
  <ImplicitUsings>enable</ImplicitUsings>
  <UseWPF>true</UseWPF>
</PropertyGroup>

它曾经在 Windows 10 下工作,似乎找不到任何有关该主题的文档,有人知道吗?

c# .net wpf storage
1个回答
0
投票

摆弄后对我有用的解决方案是安装包 Microsoft.Windows.Compatibility 以及 SDK.Buildtools。

© www.soinside.com 2019 - 2024. All rights reserved.