vb.net 无法加载文件或程序集 X 或其依赖项之一。不是有效的Win32应用程序。(结果:0x800700C1)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26324181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not load file or assembly X or one of its dependencies. is not a valid Win32 application. (HRESULT: 0x800700C1)
提问by 21CmOfPain
OS: Windows 8.1 64
操作系统:Windows 8.1 64
I tried to play multiple sounds in VB.Net with DirectX, there are no errors in my code. The problem is whenever the event is fired I get this error
我尝试使用 DirectX 在 VB.Net 中播放多个声音,我的代码中没有错误。问题是每当触发事件时我都会收到此错误
System.BadImageFormatException was unhandled Message: An unhandled exception of type 'System.BadImageFormatException' occurred in System.Windows.Forms.dll Additional information: Could not load file or assembly 'Microsoft.DirectX.AudioVideoPlayback.dll' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
System.BadImageFormatException 未处理 消息:System.Windows.Forms.dll 中发生类型为“System.BadImageFormatException”的未处理异常 附加信息:无法加载文件或程序集“Microsoft.DirectX.AudioVideoPlayback.dll”或其依赖项之一。不是有效的Win32应用程序。(来自 HRESULT 的异常:0x800700C1)
Then I set Target CPU to x86 and I got this error
然后我将目标 CPU 设置为 x86 并出现此错误
System.IO.FileLoadException was unhandled Message: An unhandled exception of type 'System.IO.FileLoadException' occurred in System.Windows.Forms.dll Additional information: Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
System.IO.FileLoadException 未处理 消息:System.Windows.Forms.dll 中发生类型为“System.IO.FileLoadException”的未处理异常附加信息:混合模式程序集是针对运行时的“v1.1.4322”版本构建的,不能无需附加配置信息即可在 4.0 运行时加载。
So far I have tried uninstalling-reinstalling DirectX SDK, Installing everything that has to do with DirectX and different sound files (.wav).
Also I had to browse to load the .dlls, I couldn't find them under Reference Manager>Assemblies but now I cant even load them through browse so I use Imports Microsoft.DirectX.AudioVideoPlaybackIt will let me Import the rest .dlls except(Reference Manager wont even open them):
到目前为止,我已经尝试卸载-重新安装 DirectX SDK,安装与 DirectX 和不同声音文件 (.wav) 有关的所有内容。此外,我不得不浏览以加载 .dll,我在 Reference Manager>Assemblies 下找不到它们,但现在我什至无法通过浏览加载它们,所以我使用Imports Microsoft.DirectX.AudioVideoPlayback它会让我导入其余的 .dll,除了(Reference Manager 甚至不会打开)他们):
Microsoft.DirectX.AudioVideoPlayback.dll
Microsoft.DirectX.dll
Microsoft.DirectX.DirectSound.dll
the ones that I need. Is there a way to clean re-install them?
我需要的那些。有没有办法清理重新安装它们?
Target Framework: .Net Framework 4.5
目标框架:.Net Framework 4.5
CODE:
代码:
Dim MySound1 As New Microsoft.DirectX.AudioVideoPlayback.Audio("D:\path\sound_file.mp3")
MySound1.Play()
Let me know if you need to know anything else.
如果您还需要了解任何其他信息,请告诉我。
UPDATE:I changed the Target Frameworkto .Net Framework 3.5and it works fine but only if the CPU Targetis set to x86! Why is that?
更新:我将 更改 Target Framework为.Net Framework 3.5并且它工作正常,但前提CPU Target是设置为x86! 这是为什么?
回答by Hans Passant
You are using the olden Managed DirectXwrappers. Targeted to run on .NET 1.1, a framework version that never supported 64-bit code. These wrappers have been deprecated a long time ago, the 2.0 version never made it out of beta.
您正在使用旧的托管 DirectX包装器。目标是在 .NET 1.1 上运行,这是一个从不支持 64 位代码的框架版本。这些包装器很久以前就被弃用了,2.0 版本从未脱离测试版。
Changing your EXE's Platform Target to x86 is required, there is no 64-bit version of Managed DirectX and the DLLs contain native 32-bit code written in Managed C++. Furthermore, if you target .NET 4.0 or higher then you have to use a .config file that says that it is okay to load such an ancient assembly that expects native code to run well on .NET 1.1. It should look like this:
需要将 EXE 的平台目标更改为 x86,没有 64 位版本的托管 DirectX,DLL 包含用托管 C++ 编写的本机 32 位代码。此外,如果您面向 .NET 4.0 或更高版本,那么您必须使用一个 .config 文件,该文件表明可以加载这样一个古老的程序集,该程序集期望本机代码在 .NET 1.1 上运行良好。它应该是这样的:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
The useLegacyV2RuntimeActivationPolicyattribute suppresses the error message you got. Whether it can actually run on 4.0+ isn't that clear, nobody uses these wrappers anymore. The usual advice is to switch to SharpDX or SlimDX instead.
该useLegacyV2RuntimeActivationPolicy属性可以禁止你得到了错误信息。它是否真的可以在 4.0+ 上运行并不是很清楚,没有人再使用这些包装器了。通常的建议是改用 SharpDX 或 SlimDX。

