gpt4 book ai didi

c# - .NET 程序集未从用户控件中找到错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:56:34 25 4
gpt4 key购买 nike

我遇到了一个问题,我的用户控件在运行时找不到特定的引用程序集。

我在运行时从嵌入式资源中提取引用的程序集,但这是用户控件在提取之前以某种方式寻找的唯一程序集,因此找不到它。

为什么应用程序不等待创建程序集的实例来寻找它?

我正在努力理解。为什么这个程序集属于“预绑定(bind)”类别?

下方融合日志

*** Assembly Binder Log Entry  (8/15/2012 @ 8:55:28 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Temp\gn\WPFDemo\bin\Debug\WPFDemo.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = xxxx
LOG: DisplayName = AVX.NET, Version=1.2.0.1551, Culture=neutral, PublicKeyToken=4300bc540bfb680e
(Fully-specified)
LOG: Appbase = file:///C:/Temp/gn/WPFDemo/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = WPFDemo.exe
Calling assembly : Test, Version=1.0.6.39680, Culture=neutral, PublicKeyToken=4300bc540bfb680e.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Temp\gn\WPFDemo\bin\Debug\WPFDemo.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: AVX.NET, Version=1.2.0.1551, Culture=neutral, PublicKeyToken=4300bc540bfb680e
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Temp/gn/WPFDemo/bin/Debug/AVX.NET.DLL.
LOG: Attempting download of new URL file:///C:/Temp/gn/WPFDemo/bin/Debug/AVX.NET/AVX.NET.DLL.
LOG: Attempting download of new URL file:///C:/Temp/gn/WPFDemo/bin/Debug/AVX.NET.EXE.
LOG: Attempting download of new URL file:///C:/Temp/gn/WPFDemo/bin/Debug/AVX.NET/AVX.NET.EXE.
LOG: All probing URLs attempted and failed.

*** Assembly Binder Log Entry (8/15/2012 @ 8:55:28 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Temp\gn\WPFDemo\bin\Debug\WPFDemo.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = xxxx
LOG: DisplayName = AVX.NET, Version=1.2.0.1551, Culture=neutral, PublicKeyToken=4300bc540bfb680e
(Fully-specified)
LOG: Appbase = file:///C:/Temp/gn/WPFDemo/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = WPFDemo.exe
Calling assembly : Test, Version=1.0.6.39680, Culture=neutral, PublicKeyToken=4300bc540bfb680e.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Temp\gn\WPFDemo\bin\Debug\WPFDemo.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: AVX.NET, Version=1.2.0.1551, Culture=neutral, PublicKeyToken=4300bc540bfb680e
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Temp/gn/WPFDemo/bin/Debug/AVX.NET.DLL.
LOG: Attempting download of new URL file:///C:/Temp/gn/WPFDemo/bin/Debug/AVX.NET/AVX.NET.DLL.
LOG: Attempting download of new URL file:///C:/Temp/gn/WPFDemo/bin/Debug/AVX.NET.EXE.
LOG: Attempting download of new URL file:///C:/Temp/gn/WPFDemo/bin/Debug/AVX.NET/AVX.NET.EXE.
LOG: All probing URLs attempted and failed.

最佳答案

CLR 加载程序集有几个触发器。除了显式的 Assembly.LoadXxx() 调用之外,最常见的调用是即时编译器。这需要程序集在该方法执行之前为该方法正确生成代码。

因此,如果您有任何代码使用此类程序集中的类型,并且该代码“接近”您拥有的用于提取 DLL 的代码,那么您很可能会得到这样的结果。在您的提取代码可以运行之前,抖动很可能需要程序集。

您必须特别注意由抖动优化器执行的内联优化,在没有附加调试器的情况下在发布版本中启用。现在“关闭”延伸到方法体之外。为防止这种情况发生,从执行 DLL 提取代码的方法调用的任何方法都必须用 [MethodImpl(MethodImplOptions.Noinlining)] 修饰。

使用这种方法您可能会遇到另一个问题。看起来您没有编写自定义 AppDomain.AssemblyResolve 事件处理程序。或者它可能还没有注册。在最新版本的 Windows 上,您无法将 DLL 解压缩到与 EXE 相同的目录,UAC 会阻止此操作。需要提取到可写目录。说 TEMP 目录。然后需要自定义程序集解析处理程序。当可执行文件不知从何而来时,病毒扫描程序会感到紧张,这是另一种高度随机且完全无法诊断的可能故障模式。

请使用部署单个可执行文件的最常见方式避免此类问题。一个名为 setup.exe,由安装项目创建。在 VS 中很容易做到。

关于c# - .NET 程序集未从用户控件中找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11969971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com