在 .NET core 2.0 中引用 .NET framework 4 dll [英] referencing .NET framework 4 dll in .NET core 2.0

查看:126
本文介绍了在 .NET core 2.0 中引用 .NET framework 4 dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些用 .Net 框架 4.0 编写的 dll,当我将它引用到我的项目时,我无法运行我的程序.NET core 2.0.

I have some dll that is written in .Net framework 4.0 and I can't run my program when I'm referencing it to my project which is written in .NET core 2.0.

尽管我的 IDE(与 2017 相比)可以在运行时正确识别从该 dll 导入的对象,但我有以下异常:

Although my IDE (vs 2017) can recognize the objects imported from that dll correctly in run time Im having the following exception:

System.BadImageFormatException: 'Could not load file or assembly 'A_dotnet_4.0_A, Version=10.0.0.0, Culture=neutral, PublicKeyToken=0ad20d08c672086a'. An attempt was made to load a program with an incorrect format.'

我试图:

  1. 如我在此处的帖子中看到的那样,将我的设置更改为任何 CPU
  2. 尝试清理重建我的项目.

有可能吗?如果是这样,我该怎么做.在下面的 link 中似乎是可能的 - 我就是不明白怎么做.

Is it even possible? and if it does, how should I do so. In the following link is seem like it is possible - I just can't understand how.

推荐答案

总结:

它不起作用,因为该 DLL 的 .NET Framework 版本太低..NET Core 2.0 及更高版本支持引用其他 .NET Standard dll(因此 .NET Core 或 .NET Framework,或未来可能实现 .NET Standard 的任何其他库).

It doesn't work because the .NET Framework version of that DLL is too low. .NET Core 2.0 and up support referencing other .NET Standard dlls (so either .NET Core or .NET Framework, or whichever other future library might implement .NET Standard).

.NET Framework 4.0 未实现 .NET Standard,因此它不会生成与 .NET Standard 兼容的 dll:.NET Framework 仅从 4.5 及更高版本开始实现 .NET Standard.因此,如果您能找到为 .NET Framework 4.5 编译的该 DLL 的版本,那么理论上它应该可以工作,除非出现一些边缘情况.

.NET Framework 4.0 does not implement .NET Standard, so it does not produce .NET Standard compatible dlls: .NET Framework only started implementing .NET Standard from version 4.5 and up. So if you can find a version of that DLL compiled for .NET Framework 4.5, it should theoretically work, barring some edge cases.

这篇关于在 .NET core 2.0 中引用 .NET framework 4 dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆