简体   繁体   English

Visual Basic 2010 BadImageException

[英]Visual Basic 2010 BadImageException

the last days I got in touch with the .NET Framework and particulary with the Visual Basic programming language. 最后几天,我与.NET Framework取得了联系,特别是与Visual Basic编程语言取得了联系。 Today there appeared a Exception I cannot solve. 今天出现了一个我无法解决的异常。 It's a BadImageException - of course I asked my best friend Google for some support. 这是BadImageException-当然,我向我最好的朋友Google寻求了一些支持。 From the results I've extracted that it seems to be an error because of the wrong platform (x86 vs. x64). 从结果中我提取出这似乎是错误的,因为平台不正确(x86与x64)。 So I checked these settings and as I could get they're set to 'Any CPU' (obviously this must mean both x64 AND x86), so probably it cannot be the origin of my error. 因此,我检查了这些设置,并尽可能将它们设置为“ Any CPU”(显然这必须同时表示x64和x86),因此可能不是我的错误的根源。 Does anyone has another idea how to solve it? 有谁知道如何解决呢?

The VB division seems to be much smaller than the Java and C++ one eg nevertheless I hope that anyone can help me. VB部门似乎比Java和C ++小得多,但是我希望有人能帮助我。 Would make me happy and I'm looking forward for you answers. 让我高兴,我期待着您的答复。

Sorry, I forgot this. 对不起,我忘了这个。 I am using Childkat.ftp2 to connect to a ftp server. 我正在使用Childkat.ftp2连接到ftp服务器。

ftp As New Chilkat.Ftp2
Try 
    success = ftp.Connect() 
    If (success <> True) Then 
        Dim failReason As Integer 
        failReason = ftp.ConnectFailReason 
        MessageBox.Show(ftp.LastErrorText) 
        End 
    End If 
Catch e As BadImageFormatException 
End Try 

This exception is also raised when you have a dependency on an assembly that's marked as x86 or uses native 32-bit code. 当您依赖标记为x86或使用本机32位代码的程序集时,也会引发此异常。 High odds for this Chilkat component to have such a setting or dependency. 该Chilkat组件具有这样的设置或依赖关系的可能性很高。 They started out with ActiveX controls, the kind typically written in C++. 他们从ActiveX控件开始,这种控件通常是用C ++编写的。 Shipping a .NET version of it is easy, writing a .NET wrapper around C++ code isn't very hard when it started out as ActiveX. 交付.NET版本很容易,当它以ActiveX开头时,围绕C ++代码编写.NET包装器并不难。 Completely rewriting it so it only uses managed code is however a major investment. 完全重写它以便使用托管代码是一项重大投资。 So they probably didn't do that. 因此,他们可能没有这样做。

You cannot use AnyCPU as long as you use this component. 只要使用此组件,就不能使用AnyCPU。 Right-click your EXE project, Properties, Compile tab, scroll down. 右键单击您的EXE项目,在“属性”,“编译”选项卡上,向下滚动。 Click the Advanced Compile Options button and change the Target CPU setting from AnyCPU to x86. 单击高级编译选项按钮,然后将目标CPU设置从AnyCPU更改为x86。 Contact the vendor and ask for a 64-bit version if this bothers you. 请与供应商联系,并询问是否需要64位版本。 It shouldn't. 不应该这样

Your deployed ChillKat DLL was probably built against an older version of the dot net framework than the one your using. 您部署的ChillKat DLL可能是根据比您使用的旧版本的点网框架构建的。 I've seen this when updating libraries on my development machine and forgetting to update the corresponding versions in production. 在开发机器上更新库而忘记更新生产中的相应版本时,我已经看到了这一点。

This exception is thrown when the file format of a dynamic link library (.dll file) or an executable (.exe file) does not conform to the format that is expected by the common language runtime. 当动态链接库(.dll文件)或可执行文件(.exe文件)的文件格式与公共语言运行库期望的格式不符时,将引发此异常。 In particular, the exception is thrown under the following conditions: 特别是,在以下情况下会引发异常:

An earlier version of a .NET Framework utility, such as ILDasm.exe or installutil.exe, is used with an assembly that was developed with a later version of the .NET Framework. .NET Framework实用程序的早期版本(例如ILDasm.exe或installutil.exe)与通过更高版本的.NET Framework开发的程序集一起使用。

To address this exception, use the version of the tool that corresponds to the version of the .NET Framework that was used to develop the assembly. 若要解决此异常,请使用与用于开发程序集的.NET Framework版本相对应的工具版本。 This may require modifying the Path environment variable or providing a fully qualified path to the correct executable. 这可能需要修改Path环境变量或为正确的可执行文件提供完全限定的路径。

An attempt is made to load an unmanaged dynamic link library or executable (such as a Windows system DLL) as if it were a .NET Framework assembly. 试图加载非托管动态链接库或可执行文件(例如Windows系统DLL),就像它是.NET Framework程序集一样。

See http://msdn.microsoft.com/en-us/library/system.badimageformatexception.aspx 请参阅http://msdn.microsoft.com/en-us/library/system.badimageformatexception.aspx

For anyone else coming in via google, I found this link useful: 对于通过Google进入的其他人,我发现此链接很有用:

http://blogs.msdn.com/b/distributedservices/archive/2009/06/17/badimageformatexception-or-typeinitializationexception-when-using-mixed-mode-vc-dlls-in-managed-services-applications.aspx http://blogs.msdn.com/b/distributedservices/archive/2009/06/17/badimageformatexception-or-typeinitializationexception-when-using-mixed-mode-vc-dlls-in-managed-services-applications.aspx

My issue was a COM reference to a managed dll that had been compiled in .NET4 attempting to be loaded via a usercontrol running in .NET2. 我的问题是COM引用了已在.NET4中编译的托管dll的COM引用,试图通过在.NET2中运行的用户控件进行加载。 Windbg was very useful as the COM reference was buried in a 3rd party dll I didn't have the source for. Windbg非常有用,因为COM参考埋在了我没有提供源的第3方dll中。

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

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