C# 异常在构造函数中抛出(而不是在构造函数中)

发布于 2024-12-11 12:12:18 字数 523 浏览 0 评论 0原文

在构造函数调用处(而不是在构造函数调用中)引发异常:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绮烟 2024-12-18 12:12:18

尝试使用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.

快乐很简单 2024-12-18 12:12:18

是的 - 它找不到可能包含 ControllerClassLib 程序集 - 或其依赖项之一。 BadImageFormatException 表明您可能有一个损坏的文件(复制失败?),或者您可能正在尝试将 .NET 4 程序集加载到 .NET 2 CLR 中。 (我不知道这是否会给出例外,但我不会感到惊讶。)

您还没有说这是什么类型的项目,但基本上检查了所有依赖项。

Yes - it can't find the ClassLib assembly which presumably contains Controller - or one of its dependencies. The BadImageFormatException 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.

柳絮泡泡 2024-12-18 12:12:18

它无法加载类构造函数中的代码引用的程序集。

It couldn't load an assembly referenced by the code in the class's constructor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文