C# 无法加载由 {myassembly} 导入的过程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1945589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:07:00  来源:igfitidea点击:

A procedure imported by {myassembly} could not be loaded

c#debuggingassemblies

提问by BlueTrin

when running a prorgam, it seems that I am missing a library, when I launch the output of my project I get an exception at startup.

在运行程序时,我似乎缺少一个库,当我启动项目的输出时,我在启动时遇到异常。

A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
An unhandled exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll

Additional information: A procedure imported by 'my assembly, Version=xx.1.1.0, Culture=neutral, PublicKeyToken=7292581204d9e04a' could not be loaded.

'ScriptX.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', No symbols loaded.

My question is: how can I determine which library is missing because, at this point, I cannot see the values passed to:

我的问题是:如何确定缺少哪个库,因为此时我看不到传递给的值:

mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x3a bytes    

采纳答案by Ofek Shilon

There is in fact a built in mechanism for just these diagnostics.

事实上,这些诊断有一个内置的机制。

(1) In your project properties/Debug, make sure 'Enable native code debugging' is checked:

(1) 在您的项目属性/调试中,确保选中“启用本机代码调试”:

enter image description here

在此处输入图片说明

(2) Raise the show-loader-snapsflag - it is a registry key in the IFEO, and is accessible via the 'GlobalFlags' GUI:

(2) 提高show-loader-snaps标志 - 它是 IFEO 中的注册表项,可通过“GlobalFlags”GUI 访问:

enter image description here

在此处输入图片说明

(3) Run the app and inspect the (very) verbose output pane. You can mostly skip to the end or look for 'ERROR'.

(3) 运行应用程序并检查(非常)详细的输出窗格。您通常可以跳到最后或查找“错误”。

More details here.

更多细节在这里

回答by Richard

Are you doing any dllimport? - this looks like an issue with an unmanaged dll not being found?

你在做任何dllimport吗?- 这看起来像是未找到非托管 dll 的问题?

First thing is to ensure that any unmanaged dll's or exe's that you are calling into (via dllimport) are deployed into the same folder as the .Net exe that you are building

第一件事是确保您调用(通过 dllimport)的任何非托管 dll 或 exe 部署到与您正在构建的 .Net exe 相同的文件夹中

If the source of the calling assembly is not available you could try using reflectoron that assembly to search for dllimport statements

如果调用程序集的源不可用,您可以尝试在该程序集上使用反射器来搜索 dllimport 语句

Other than that you might want to enable the fustion log viewer to trace assembly load issues - see this blog postand msdn pagefor more details

除此之外,您可能希望启用融合日志查看器来跟踪程序集加载问题 -有关更多详细信息,请参阅此博客文章msdn 页面

回答by Hans Passant

Implement a handler for the AppDomain.AssemblyResolve event. It tells you which assembly it is looking for with ResolveEventArgs.Name. If this is just an effort to troubleshoot this particular assembly then use Fuslogvw.exe. If the hangup is an unmanaged assembly then DependencyWalker's Profile option can show you what LoadLibrary() call is failing. SysInternals' ProcMon will work too but is a lot noisier.

为 AppDomain.AssemblyResolve 事件实现一个处理程序。它通过 ResolveEventArgs.Name 告诉您它正在寻找哪个程序集。如果这只是为了解决此特定程序集的故障,请使用 Fuslogvw.exe。如果挂断是非托管程序集,则 DependencyWalker 的 Profile 选项可以显示 LoadLibrary() 调用失败的内容。SysInternals 的 ProcMon 也可以工作,但噪音更大。

回答by hellyale

In some cases when using COM, you might just need to unregister and reregister the dll with RegAsm.exe. That is what fixed this issue for me last week, things had gotten out of sync.

在某些情况下,使用 COM 时,您可能只需要使用 RegAsm.exe 取消注册并重新注册 dll。这就是上周为我解决这个问题的原因,事情已经不同步了。