从用户控件中找不到.NET程序集错误

时间:2012-08-15 13:15:53

标签: c# .net assemblies

我遇到的问题是我的用户控件在运行时没有找到特定的引用程序集。

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

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

我想了解。 为什么这个程序集属于“预绑定”类别?

下面的Fusion日志

*** 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.

1 个答案:

答案 0 :(得分:1)

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

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

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

你可能正在寻找这种方法的另一个问题。它看起来并不像您编写了自定义的AppDomain.AssemblyResolve事件处理程序。或者它可能还没有注册。您无法在最新版本的Windows上将DLL提取到与EXE相同的目录,UAC会停止此操作。需要提取到可写目录。说出TEMP目录。然后需要自定义程序集解析处理程序。当可执行文件无处出现时,病毒扫描程序会感到紧张,另一种高度随机且完全不可识别的可能故障模式。

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