当运行调用C++/CLI程序集的C#代码,该程序集又调用纯C DLL时,如果实例化调用纯C DLL函数的对象,就会出现“System.IO.FileNotFoundException:找不到指定的模块”的错误。
BackingStore is pure C. CPPDemoViewModel is C++/CLI calling BackingStore it has a reference to BackingStore.
我尝试了最简单的情况-添加一个新的C#单元测试项目,尝试创建在CPPDemoViewModel中定义的对象。我从C#项目中添加了一个对CPPDemoViewModel的引用。
一个C++/CLI测试项目只添加了对CPPDemoViewModel的引用就可以正常工作,所以这与语言之间的差异有关。
我正在使用带有.Net 3.5 SP1的Visual Studio 2008 SP1。我正在Vista x64上构建,但我已经小心翼翼地确保我的平台目标设置为x86。
这感觉像是我忽略了某些愚蠢而显而易见的东西,但如果我浪费时间尝试私下解决它,那将更加愚蠢,所以我在这里出丑!
这是一个测试项目,用于移植大量旧版 C 代码,我将其保存在 DLL 中,并在 C++/CLI 中实现 ViewModel。
edit After checking directories, I can confirm that the BackingStore.dll has not been copied.
我已经创建了标准的独特项目文件夹,并使用典型的多项目解决方案。
WPFViewModelInCPP BackingStore CPPViewModel CPPViewModelTestInCS bin Debug Debug
更高级别的Debug似乎是C和C++ / CLI项目常用的一个共同文件夹,令我惊讶。
WPFViewModelInCPPDebug包含BackingStore.dll、CPPDemoViewModel.dll、CPPViewModelTest.dll及其关联的.ilk和.pdb文件。
WPFViewModelInCPPCPPViewModelTestInCSinDebug contains CPPDemoViewModel and CPPViewModelTestInCS .dll and .pdb files but not BackingStore. However, manually copying BackingStore into that directory did not fix the error.
CPPDemoViewModel has the property Copy Local set which I assume is responsible for copying its DLL when if is referenced. I can t add a reference from a C# project to a pure C DLL - it just says A Reference to Backing Store could not be added.
I m not sure if I have just one problem or two.
我可以使用老式的复制构建步骤将BackingStore.dll复制到任何给定的C#项目目录中,尽管我希望新的.net模型不需要这样做。
DependencyWalker 告诉我缺失的文件是 GPSVC.dll,这可能表明有安全设置问题,但我怀疑这是一个误导。
edit2 With a manual copy of BackingStore.dll to be adjacent to the executable, the GUI now works fine. The C# Test Project still has problems which I suspect is due to the runtime environment of a test project but I can live without that for now.