在 .NET Core 3.0 中加载 exe 时出现错误的 IL 格式 [英] Bad IL Format when loading exe in .NET Core 3.0

查看:34
本文介绍了在 .NET Core 3.0 中加载 exe 时出现错误的 IL 格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 .NET Core 3.0 WPF 项目.其中之一,我发布到一个名为DefaultPlugin.exe"的可执行文件中.

I have two .NET Core 3.0 WPF projects. One of them, I published into an executable called "DefaultPlugin.exe".

在我的第二个 WPF 项目中,我尝试使用 Assembly.Load 加载第一个项目并读取类型.但是,当我这样做时,我会收到来自 System.Private.CoreLib 的异常错误的 IL 格式".当我从 bin 文件夹加载 DefaultPlugin.dll 时它会起作用,我还检查了我的 CPU 配置以确保它们匹配.

In my second WPF project, I'm trying to load the first project using Assembly.Load and read the types. However, when I do so, I get an exception, "Bad IL Format" from System.Private.CoreLib. It works when I load the DefaultPlugin.dll from the bin folder I also checked my CPU configuration to make sure they match.

///Works:
string path = @"C:UsersS-D81source
eposDefaultPluginDefaultPlugininDebug
etcoreapp3.0win-x64DefaultPlugin.dll";
///Does not work:
//string path = @"C:UsersS-D81source
eposDefaultPluginDefaultPlugininDebug
etcoreapp3.0win-x64DefaultPlugin.exe";
//string path = @"C:UsersS-D81source
eposDefaultPluginDefaultPlugininRelease
etcoreapp3.0win-x64publishDefaultPlugin.exe";

Assembly assembly = Assembly.LoadFrom(path);

有没有办法在已发布的 .NET Core 3.0 程序集上使用 Assembly.Load 或者这只是新框架的限制?

Is there a way to use Assembly.Load on a published .NET Core 3.0 assembly or is this just a limitation of the new framework?

推荐答案

在 .NET Core 3.0 应用程序中生成的 .exe 文件不是一个 IL 程序集,而是一个本地主机可执行文件,它在加载实际的 IL 应用程序之前查找并启动运行时具有 .dll 扩展名的程序集.

The generated .exe file in .NET Core 3.0 applications is not an IL assembly but a native host executable that finds and boots the runtime before loading the actual IL application assembly which has a .dll extension.

您应该能够通过加载具有相同项目名称的 .exe 文件旁边的 .dll 文件来加载您的插件.

You should be able to load your plugin by loading the .dll file next to the .exe file with the same project name.

这篇关于在 .NET Core 3.0 中加载 exe 时出现错误的 IL 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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