C# 异常在构造函数中抛出(而不是在构造函数中)
在构造函数调用处(而不是在构造函数调用中)引发异常:
controller = new Controller(classInstance); // Won't let me step in, exception thrown immediately.
异常描述为:
System.BadImageFormatException: Could not load file or assembly 'ClassLib, Version=1.0.4314.17265, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
classInstace
不为 null,并且我无法单步进入构造函数。我以前从未经历过这种情况。知道这可能是什么吗?
谢谢!
An exception is being thrown at (not in) a constructor call:
controller = new Controller(classInstance); // Won't let me step in, exception thrown immediately.
The exception description is:
System.BadImageFormatException: Could not load file or assembly 'ClassLib, Version=1.0.4314.17265, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
classInstace
isn't null and I cannot step into the constructor. I have never experienced this before. Any idea what this could be?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用Fusion 日志查看器 ( fuslogvw.exe)以查看哪个程序集与 ClassLib 匹配。正如 Jon Skeet 所说,这可能是文件损坏、32 位与 64 位问题或奇怪的运行时不匹配。
Try using the Fusion Log Viewer (fuslogvw.exe) to see which assembly's being matched to ClassLib. Like Jon Skeet said, it's probably either a corrupted file, a 32 vs/ 64-bit issue, or a weird runtime mismatch.
是的 - 它找不到可能包含
Controller
的ClassLib
程序集 - 或其依赖项之一。BadImageFormatException
表明您可能有一个损坏的文件(复制失败?),或者您可能正在尝试将 .NET 4 程序集加载到 .NET 2 CLR 中。 (我不知道这是否会给出例外,但我不会感到惊讶。)您还没有说这是什么类型的项目,但基本上检查了所有依赖项。
Yes - it can't find the
ClassLib
assembly which presumably containsController
- or one of its dependencies. TheBadImageFormatException
suggests that maybe you've got a broken file (copy failed?) or possibly you're trying to load a .NET 4 assembly into a .NET 2 CLR. (I don't know whether that gives that exception or not, but I wouldn't be surprised.)You haven't said what kind of project this is, but basically check all of your dependencies.
它无法加载类构造函数中的代码引用的程序集。
It couldn't load an assembly referenced by the code in the class's constructor.