简体   繁体   English

在 .NET 4.5 可执行文件中运行 .NET 2.0 目标 DLL

[英]Run .NET 2.0 targeted DLL in a .NET 4.5 Executable

I have very simple C# library (we'll call it myApi.dll) targeted for .NET 2.0 that executes a simple database insertion.我有一个非常简单的 C# 库(我们称之为 myApi.dll),它针对 .NET 2.0 执行简单的数据库插入。 I underlying requirements must keep it at .NET 2.0.我的基础要求必须保持在 .NET 2.0。 When I reference myApi.dll in a new a new VS2013 app, also targeting .NET 2.0, it works exactly as programmed.当我在一个新的 VS2013 应用程序中引用 myApi.dll 时,也针对 .NET 2.0,它完全按照编程的方式工作。

The problem is when I take myApi.dll over to another project targeted for .NET 4.5, developed in VS2019, it crashes.问题是当我将 myApi.dll 带到另一个针对 .NET 4.5 的项目(在 VS2019 中开发)时,它崩溃了。 It's crashing with an error message that says.它崩溃并显示一条错误消息。

"Could not load file or assembly 'Microsoft.Vsa, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."

Both executing programs are on the same machine.两个执行程序都在同一台机器上。 The app targeting .NET 2.0 runs myApi.dll fine but the app targeting .NET 4.5 doesn't.针对 .NET 2.0 的应用程序运行 myApi.dll 很好,但针对 .NET 4.5 的应用程序没有。

I've reviewed helpful hints like我已经查看了有用的提示,例如

I thought setting my 4.5 applications App.confg file to mirror this would help but it didn't.我认为将我的 4.5 应用程序 App.confg 文件设置为镜像这会有所帮助,但它没有。

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
    <supportedRuntime version="v2.0"/>
  </startup>
</configuration>

Any thoughts as to why the .NET 2.0 can call myApi.dll just fine and the .NET 4.5 app crashes?关于为什么 .NET 2.0 可以调用 myApi.dll 并且 .NET 4.5 应用程序崩溃的任何想法?

VS 2019 does not support obsoleted API of .NET 2.0 to 3.5, because it doesn't support .NET Framework before 4.0. VS 2019 不支持 .NET 2.0 到 3.5 的过时的 API,因为它不支持 4.0 之前的 .NET Framework。 Use older version of Visual Studio, such as VS 2015 (with Update 3) for this obsoleted Vsa API usage.对于这个过时的 Vsa API 用法,请使用旧版本的 Visual Studio,例如 VS 2015(带有更新 3)。

See also this VS 2019 documentation: https://docs.microsoft.com/en-us/visualstudio/releases/2019/compatibility#-visual-studio-2019-support-for-net-development另请参阅此 VS 2019 文档: https://docs.microsoft.com/en-us/visualstudio/releases/2019/compatibility#-visual-studio-2019-support-for-net-development

Visual Studio 2019 支持 .NET 开发

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM