在UWP应用的完全信任Win32组件中使用.NET标准库时抛出的FileNotFoundException(无法加载文件或程序集)

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

我在.NET标准库中拥有域逻辑。我正在尝试在UWP应用程序中定义的完全信任获胜表格托盘组件中使用它。在UWP项目和Win Forms项目中都引用了我的域逻辑库。现在,如果我将Win Forms应用程序启动为系统任务栏中的完全信任过程,并调用域逻辑,它将引发FileNotFoundException,说它找不到在我的“域逻辑”库中添加的nuget程序包。但是,如果我单独启动表单应用程序,它将得到正确执行。按照答案,我在构建后事件中添加了复制任务,并且复制的dll也包含在项目中。

这里是sample repo,用于重现上述问题。自述文件包含简要说明以重现该问题。如何修复被抛出的FileNotFound?

这里是异常跟踪。

System.TypeInitializationException: The type initializer for 'DIServiceProviderSingleton' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at DomainLogic.DIServiceProvider..ctor()
   at DomainLogic.DIServiceProvider.DIServiceProviderSingleton..cctor()
   --- End of inner exception stack trace ---
   at DomainLogic.DIServiceProvider.get_Instance()
   at SystrayComponent.SystrayApplicationContext.PerformDomainLogic(Object sender, EventArgs e)

最初,nuget包dll没有复制到SystrayComponent的bin文件夹中。我按照发布在here上的解决方法进行了修复。

c# winforms uwp .net-standard-2.0
1个回答
1
投票

除了包含exe文件,还需要包含DomainLogic.dll文件。

请在DomainLogic.dll中找到UWP-Systray-master\SystrayComponent\bin\Debug文件并将其添加到Win32文件夹中。

添加后,在Visual Studio中“包含在项目中”。

谢谢

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