简体   繁体   English

SQL Server 自定义 CLR 失败并显示错误“无法加载文件或程序集或其依赖项之一。系统找不到指定的文件。”

[英]SQL Server custom CLR fails with error "Could not load file or assembly or one of its dependencies. The system cannot find the file specified."

I have created a SQL CLR that references the Windows DLL, WindowsBase.我创建了一个引用 Windows DLL WindowsBase 的 SQL CLR。 For the most part my CLR works just fine but if WindowsBase gets updated in the GAC then I get the error " Assembly in host store has a different signature than assembly in GAC. ".在大多数情况下,我的 CLR 工作得很好,但是如果 WindowsBase 在 GAC 中得到更新,那么我会收到错误消息“ Assembly in host store has a different signature than assembly in GAC. ”。

To address this I built my CLR to reference a version of WindowsBase that is not in the GAC.为了解决这个问题,我构建了我的 CLR 以引用不在 GAC 中的 WindowsBase 版本。 Now when I run my CLR i get the error " Could not load file or assembly 'WindowsBase, Version=4.0.0.0, ...' or one of its dependencies. The system cannot find the file specified. "现在,当我运行 CLR 时,出现错误“ Could not load file or assembly 'WindowsBase, Version=4.0.0.0, ...' or one of its dependencies. The system cannot find the file specified.

I set up FusLogVw to see what's going on and get the following output我设置了 FusLogVw 来查看发生了什么并得到以下输出

The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Binn\sqlservr.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
    LOG: DisplayName = WindowsBase, Version=4.0.0.0
    LOG: Appbase = file:///C:/Program Files/Microsoft SQL Server/MSSQL11.MSSQLSERVER/MSSQL/Binn/
    LOG: Initial PrivatePath = NULL
    LOG: Dynamic Base = NULL
    LOG: Cache Base = NULL
    LOG: AppName = sqlservr.exe
    Calling assembly : (Unknown).
    ===
    LOG: This bind starts in default load context.
    LOG: No application configuration file found.
    LOG: Using host configuration file: 
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
    LOG: Post-policy reference: WindowsBase, Version=4.0.0.0
    LOG: The same bind was seen before, and was failed with hr = 0x80070002.
    ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).

It would appear that the assembly loader is using the machine.config file to determine where it should look for the assembly.看起来程序集加载器正在使用 machine.config 文件来确定它应该在哪里查找程序集。 Based on this assumption I updated the machine.config with基于这个假设,我更新了 machine.config

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
             <assemblyIdentity name="WindowsBase"... />
              <codBase version="4.0.0.0"
                   href="./AdditionalAssemblies/WindowsBase.dll"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

I have tried with a relative path (relative to SQlservr.exe) and an absolute path but continue to get the same error mentioned above.我已尝试使用相对路径(相对于 SQlservr.exe)和绝对路径,但继续遇到上述相同的错误。 Any suggestions on how to set up the SQL CLR so that it refereneces a copy of WindowsBase that is outside the GAC without getting the above errors would be greatly appreciated.关于如何设置 SQL CLR 以便它引用 GAC 之外的 WindowsBase 副本而不会出现上述错误的任何建议将不胜感激。

~Bugz~ ~Bugz~

What you are attempting to do is not supported by SQL Server's CLR host. SQL Server 的 CLR 主机不支持您尝试执行的操作。 The CLR within SQL Server is highly restricted to prevent destabilizing SQL Server since it works differently than apps running on the OS. SQL Server 中的 CLR 受到严格限制,以防止破坏 SQL Server 的稳定性,因为它的工作方式与在操作系统上运行的应用程序不同。 So, there is a very limited set of DLLs that are supported (ie verified to work and guaranteed to stay working across updates to .NET).因此,支持的 DLL 集非常有限(即经过验证可以工作并保证在更新到 .NET 后仍能正常工作)。 WindowsBase is not one of them so you would need to load it manually as UNSAFE into SQL Server. WindowsBase 不是其中之一,因此您需要将其作为UNSAFE手动加载到 SQL Server 中。 But that leaves you with either the problem that you ran into of the version in the main GAC changing (DLLs that are common between the GAC and SQL Server's CLR host must be the same version), or worse, if the DLL becomes "mixed" (both unmanaged C++ and managed code) and is no longer "pure".但这会让您遇到主 GAC 中版本更改的问题(GAC 和 SQL Server 的 CLR 主机之间常见的 DLL 必须是相同版本),或者更糟的是,如果 DLL 变得“混合” (非托管 C++ 和托管代码)并且不再“纯”。 In that case the new version will not load and the old version gets the "wrong version" error so you have some work to do.在这种情况下,新版本不会加载,旧版本会出现“错误版本”错误,因此您需要做一些工作。

For more detailed information, please see the following articles / documentation:有关更多详细信息,请参阅以下文章/文档:

That set of links is taken from the "Additional Reading" section of an article I wrote: Stairway to SQLCLR Level 5: Development (Using .NET within SQL Server) .这组链接取自我写的文章的“附加阅读”部分: 通往 SQLCLR 级别 5:开发(在 SQL Server 中使用 .NET)的阶梯


For more information on working with SQLCLR in general, please visit my site: SQLCLR Info有关使用 SQLCLR 的更多信息,请访问我的网站: SQLCLR 信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集或其依赖项之一。 该系统找不到指定的文件。 (不允许GAC) - Could not load file or assembly or one of its dependencies. The system cannot find the file specified. (No GAC allowed) 为什么会出现此错误:“无法加载文件或程序集‘System.Runtime’或其依赖项之一。 系统找不到指定的文件。”? - Why do I get this error, “Could not load file or assembly 'System.Runtime' or one of its dependencies. The system cannot find the file specified.”? 具体:无法加载文件或程序集“xxxx”或其依赖项之一。 该系统找不到指定的文件 - A specific: Could not load file or assembly 'xxxx' or one of its dependencies. The system cannot find the file specified 无法加载文件或程序集“coba4”或其依赖项之一。 该系统找不到指定的文件 - Could not load file or assembly 'coba4' or one of its dependencies. The system cannot find the file specified 无法加载文件或程序集“ skmMenu”或其依赖项之一。 该系统找不到指定的文件 - Could not load file or assembly 'skmMenu' or one of its dependencies. The system cannot find the file specified 还有一个“无法加载文件或程序集......或其中一个依赖项。该系统找不到指定的文件” - Yet another “could not load file or assembly … or one of its dependencies. The system cannot find the file specified” Asp.Net 5,dnx:无法加载文件或程序集“ dnx.clr.managed”或其依赖项之一。 该系统找不到指定的文件 - Asp.Net 5 ,dnx : Could not load file or assembly 'dnx.clr.managed' or one of its dependencies. The system cannot find the file specified 无法加载文件或程序集“System.Net.Http.Formatting”或其依赖项之一。 该系统找不到指定的路径 - Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies. The system cannot find the path specified 生产中的Azure SDK 2.2:无法加载文件或程序集“msshrtmi”或其依赖项之一。 该系统找不到指定的文件 - Azure SDK 2.2 in Production: Could not load file or assembly 'msshrtmi' or one of its dependencies. The system cannot find the file specified “‘无法加载文件或程序集‘Elmah’或其依赖项之一。在 NuGet 中使用 Elmah.MVC 后,系统找不到指定的文件” - "'Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified'' after using Elmah.MVC in NuGet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM