C#依赖注入和dll加载异常

时间:2019-05-15 04:50:38

标签: c# dll dependency-injection

我正在创建一个项目,该项目应在Windows和Linux计算机上使用。该解决方案包含3个项目:Win-Windows本机功能实现,Lin-Linux本机功能实现和Core-项目,其中包含所有依赖项并根据运行时信息解析它们。 Win项目有一个目标框架:.Net框架4.6.2,Linux项目:-.Net标准2.0和Core项目是多目标的:

<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>

这里的问题是Win项目中的某些类使用UIAutomationClientUIAutomationTypes Windows特定的DLL。在VS中运行项目时,如果应用程序调用该类,则会收到以下异常:

Could not load file or assembly 'UIAutomationClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

在Win项目中。

我试图更改Core.csproj文件并添加以下行:

<ItemGroup Condition="'$(TargetFramework)'=='net462'">
  <Reference Include="UIAutomationClient"/>
  <Reference Include="UIAutomationTypes"/>
</ItemGroup>

但是它添加了引用,但是异常仍然存在。 请帮助我找出如何解决此问题。 如果需要,我将提供更多代码。

谢谢

0 个答案:

没有答案
相关问题