简体   繁体   English

在C ++ / CLI项目中识别有问题的依赖项

[英]Identifying problematic dependencies in C++/CLI project

My application compiles fine, but I get the following runtime error: 我的应用程序编译正常,但我得到以下运行时错误:

System.IO.FileNotFoundException was unhandled
  HResult=-2147024770
  Message=Could not load file or assembly {Wrapper} or one of its dependencies. The specified module could not be found.

The reference to Wrapper in the calling Application looks correct. 调用Application中对Wrapper的引用看起来是正确的。 The Wrapper dll exists in the correct location. Wrapper dll存在于正确的位置。

This project used to build and run on someone else's system, I saw it demonstrated several times. 这个项目用于在别人的系统上构建和运行,我看过几次。 That person/computer is no longer available. 该人/计算机不再可用。 Some paths of some dependencies have changed since the last time it was successfully built and run, I have fixed all compile errors related to this. 自上次成功构建和运行以来,某些依赖项的某些路径已更改,我已修复与此相关的所有编译错误。

Just to clarify my project structure: 只是为了澄清我的项目结构:

图形

Digraph G
{
    App [ label = "My C# Application"]
    Wrapper [ label = "C++/CLI Wrapper"]
    Lib [ label = "C++ Library"]
    Dll [ label = "My helper C# DLL"]
    CDep [ label = "Series of deep C++ dependencies managed \n by CMake for Lib, hard coded relative paths for Wrapper."]
    App->Wrapper->Lib->CDep;
    App->Dll->Wrapper->CDep;
}

Wrapper is a C++/CLI wrapper around a C++ library. Wrapper是围绕C ++库的C ++ / CLI包装器。 The error is triggered when we try to load a class in the Application that has a using statement for the Wrapper. 当我们尝试在Application中加载具有Wrapper的using语句的类时,会触发该错误。

Wrapper does have a lot of dependencies, but the error message does not indicate which dependency is problematic. Wrapper确实有很多依赖项,但错误消息并不表示哪个依赖项存在问题。 This is a large, complicated system, most of which is built by other teams. 这是一个庞大而复杂的系统,其中大部分由其他团队构建。 The C++ components use CMake to get all the dependencies correct, but CMake does not natively support C#. C ++组件使用CMake来使所有依赖项都正确,但CMake本身不支持C#。

I tried using fuslogvw to find the binding error, but it showed me absolutely nothing until I changed settings to include all binds, and then it only showed successful binds. 我尝试使用fuslogvw来查找绑定错误,但在我更改设置以包含所有绑定之前,它绝对没有显示任何内容,然后它只显示成功的绑定。 http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.100).aspx http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.100).aspx

The paths are long, but not over 256 characters. 路径很长,但不超过256个字符。

I had a warning in the compile for Dll (see graph above): Warning 1 There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "{cli_wrapper.dll}", "AMD64". 我在Dll的编译中发出警告(见上图):警告1正在构建的项目的处理器体系结构“MSIL”与参考“{cli_wrapper.dll}”,“AMD64”的处理器体系结构不匹配”。 This mismatch may cause runtime failures. 这种不匹配可能会导致运行时故障。 Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. 请考虑通过Configuration Manager更改项目的目标处理器体系结构,以便在项目和引用之间调整处理器体系结构,或者依赖于具有与项目的目标处理器体系结构相匹配的处理器体系结构的引用。

In Configuration Manager, the Dll is building for Platform "Any CPU" and Wrapper is building for "x64". 在Configuration Manager中,Dll正在为“任何CPU”构建平台,而Wrapper正在为“x64”构建。 I changed the dll to x64. 我将dll更改为x64。 I still get the runtime error. 我仍然得到运行时错误。

Could not load file or assembly or one of its dependencies Performed a clean, deleted build directory contents. 无法加载文件或程序集或其依赖项之一执行干净,已删除的构建目录内容。 No change. 没变。 Re-opened Visual Studio. 重新打开Visual Studio。 No change. 没变。 Tried changing assembly name, default namespace, and project name to match. 尝试更改要匹配的程序集名称,默认名称空间和项目名称。 No change. 没变。

Could not load file or assembly 'xxx' or one of its dependencies. 无法加载文件或程序集“xxx”或其依赖项之一。 An attempt was made to load a program with an incorrect format I believe we have to compile for 64 bit. 试图加载一个格式不正确的程序,我相信我们必须编译为64位。 We are dependant on a 64 bit C++ library. 我们依赖于64位C ++库。

Could not load file or assembly ... The parameter is incorrect I am local administrator. 无法加载文件或程序集...参数不正确我是本地管理员。

How to enable assembly bind failure logging (Fusion) in .NET Tried the registry settings, but they appear to just be fuslogvw settings. 如何在.NET中启用程序集绑定失败日志记录(Fusion)尝试了注册表设置,但它们似乎只是fuslogvw设置。 No improvement in available log data. 可用日志数据没有改进。

Many other similar questions had ASP or service install specific answers. 许多其他类似问题有ASP或服务安装特定答案。

I found the problem. 我发现了这个问题。 There was more than one version of the library available to me, and I was using the include files from one version and the compiled library of the other. 我可以使用多个版本的库,我使用的是一个版本的包含文件和另一个版本的编译库。 Dependancy Walker was key to finding which library had the problem, and if Aschratt had posted that as an answer rather than as a comment I would have accepted his answer. Dependancy Walker是找到哪个图书馆存在问题的关键,如果Aschratt发布了这个作为答案而不是评论,我会接受他的回答。

I had the same error with a similar project earlier this week. 本周早些时候我在类似项目中遇到了同样的错误。 First, when using C++/CLI, "Any CPU" doesn't exist. 首先,使用C ++ / CLI时,“Any CPU”不存在。 I had to build both for x86 to get through things. 我必须为x86构建两个以完成任务。

Also, though my wrapper's dependencies were satisfied, it's the wrapper's exception that is caught by the CLR so it claims that the wrapper is missing a dependency. 此外,虽然我的包装器的依赖项得到满足,但它是CLR捕获的包装器异常,因此它声称包装器缺少依赖项。 I was actually missing a dependency for the C++ DLL my wrapper wrapped (in my case, it was just a matter of forgetting to drop SDL2.dll and OpenAL32.dll in my new "Release" configuration output folder... I'd previously only worked with the Debug configuration where I'd already dropped those DLLs. 我实际上错过了我的包装器包装的C ++ DLL的依赖项(在我的情况下,这只是忘记在我的新“Release”配置输出文件夹中丢弃SDL2.dll和OpenAL32.dll的问题...我以前仅适用于我已经删除了这些DLL的Debug配置。

If you're positive you've got your wrapper's dependencies worked out, I'd recommend using Dependency Walker to check out the native DLL's dependencies. 如果你肯定你已经解决了你的包装器的依赖关系,我建议使用Dependency Walker来检查本机DLL的依赖关系。 You could use Assembly.GetReferencedAssemblies with an outside script/program to double-check your wrapper as well (or ILSpy: http://ilspy.net/ ). 您可以将Assembly.GetReferencedAssemblies与外部脚本/程序一起使用来仔细检查您的包装器(或ILSpy: http ://ilspy.net/)。

Last but not least, take a look at this: http://www.codeproject.com/Articles/442784/Best-gotchas-of-Cplusplus-CLI . 最后但同样重要的是,请看一下: http//www.codeproject.com/Articles/442784/Best-gotchas-of-Cplusplus-CLI He details the first two recommendations I made as well as some others. 他详述了我提出的前两条建议以及其他一些建议。

Good luck! 祝好运!

我之前遇到的另一个根本原因是我正在使用的应用程序使用模拟,而模拟用户没有权限访问GAC或某些dll所在的文件夹。您需要要么为该用户授予权限,要么在模拟开始之前更改模拟加载依赖项的方式。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM