我已经找出导致问题的原因但我仍然不知道为什么 - 它发生在我开始使用fmod
时,它必须与链接器决定引入和执行的方式有关静态库和.dll
的。我正在测试的代码是一个静态库;它引用fmodex_vc
,另一个静态库,在某些时候(虽然我不知道何时)决定加载其fmodex.dll
。 (与其他所有内容位于同一个目录中,所以我不知道为什么它找不到它。)据我所知,测试中的代码绝对不会调用fmod初始化函数,但是fmod可能有一些静态全局初始化器初始化自己并在DLL中加载?如果使用它的模块中的代码被使用,那么该代码才会被拉入?
我正在使用Visual Studio测试框架测试非托管C ++代码,当我开始使用fmod时,它停止工作:每个测试,甚至什么都不做的“测试”测试都会报告(为了可读性而包装):
Unable to get type SlidersTest.UnitTest1, SlidersTest.
Error: System.IO.FileNotFoundException:
The specified module could not be found.
(Exception from HRESULT: 0x8007007E)
经过大量的试验和错误,排除.cpp
个文件并重新添加它们后,我发现只有一个测试文件会引发问题;并且只有在调用此行时才会这样做:
EntityMgr::Init();
有趣的是,如果该行在代码中,则所有测试开始失败。 EntityMgr::Init()
是一个功能很少的功能:
EntityMgr* EntityMgr::instG = null;
和
void EntityMgr::Init()
{
instG = new EntityMgr;
}
和
class EntityMgr
{
private:
static EntityMgr* instG;
public:
EntityMgr() // does nothing beyond the default
{
}
static void Init();
static EntityMgr* Inst() { return instG; }
...
vector<Entity> entitiesG;
};
Entity
,FWIW,是一个非常香草的类,没有指针,只有各种float
的字段。
/clr
。如果我将调试器设置为中断任何异常,我会得到一些有趣的东西:
First-chance exception at 0x7c812aeb in vstesthost.exe: Microsoft C++ exception: HRException at memory location 0x05129890..
当然,该位置没有源代码。这是调用堆栈:
kernel32.dll!7c812aeb()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
kernel32.dll!7c812aeb()
[External Code]
msvcr80.dll!78158ed7()
msvcr80.dll!78158e34()
msvcr80.dll!78158047()
msvcr80.dll!7815850e()
msvcr80.dll!78158872()
msvcr80.dll!78158a57()
msvcr80.dll!78158b11()
ntdll.dll!7c9032a8()
ntdll.dll!7c90327a()
ntdll.dll!7c92a9ef()
ntdll.dll!7c90e46a()
kernel32.dll!7c812aeb()
kernel32.dll!7c812aeb()
kernel32.dll!7c812aeb()
msvcr80.dll!78139c4d()
msvcr80.dll!781323ff()
msctf.dll!74755764()
msctf.dll!74721557()
ws2_32.dll!71ab12bb()
ntdll.dll!7c90118a()
ntdll.dll!7c91b084()
ntdll.dll!7c90de7c()
ntdll.dll!7c90d04c()
ntdll.dll!7c90e43f()
kernel32.dll!7c80b713()
这是mstest报告的堆栈跟踪 - 我没有得到任何有用的东西。
Unable to get type SlidersTest.game_EntityMgr_test, SlidersTest. Error: System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.GetType(UnitTestElement unitTest, String type)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.ResolveMethods().
为什么fmod这样做?
答案 0 :(得分:1)
我建议在Dependency Walker的配置文件模式(http://www.dependencywalker.com/)下运行您的应用程序。它可以记录加载DLL和EXE的所有尝试,以及产生的错误代码 - 听起来可能是File not Found错误来自间接依赖 - 可能是从链接FMod中提取的。
如果是这种情况,使用Dependency Walker分析您的应用程序将显示一个或多个加载库的失败尝试。其中一个将是负责该错误的人。
答案 1 :(得分:0)
也许某个属性已针对该文件进行了修改?可能已经看过这个,但要确保所有设置都来自Visual Studio中的“从父级继承”。
杰
答案 2 :(得分:0)
我最好的猜测,从你发布的内容到目前为止,异常是在CLR类型加载器中的某个地方抛出 - 它看起来像是一个你间接依赖的程序集不在GAC中,或者没有被复制到测试目录。
测试结果中是否有实际的堆栈跟踪?这可能有助于缩小其尝试加载的类型。
答案 3 :(得分:0)
既然你说这种情况突然发生了,我认为使用这行代码的测试在以前工作得很好。这可能是一个激进的选择,但在没有其他解决方案的情况下,也许你会考虑重新安装visual studio(一个很长的程序来确定)
答案 4 :(得分:0)
是否可以将Visual Studio设置为中断所有异常,无论它们在调试过程中来自何处?
听起来好像宇宙射线或有故障的硬盘驱动器导致测试.dll变得腐败,或者你正在构建的dll是否已损坏(始终如一)。在重新安装所有Visual Studio之前,您可能要求它进行修复,这应该检查当前安装与安装介质上的内容之间的不一致。
答案 5 :(得分:0)
FMod .dll如何进入您的测试目录?您是否已将其设置为将其复制到mstest希望测试发生的位置?请注意,“复制到输出目录”实际上并不能实现此目的。还有一些其他的方法,虽然我不记得它是什么。
答案 6 :(得分:0)
我在调试器中运行它并检查运行输出 - 特别是“加载路径\ fmodex.dll”行以查看它是否正在加载正确的dll。
在混合不同配置的dll时,我发现了类似的错误。