Media player and .NET 4.0
I have some WinForm code (.NET 2.0) using Windows Media Player uti开发者_如何学Golizing the COM (AxInterop.WMPLib.dll and Interop.WMPLib.dll).
I am trying to push it to .NET 4.0 but it doesn't load the DLL.
It seems that 4.0 doesn't support that specific version (or any version) of the WMP.
Does anyone know why? Is there any other way to deal with it? (Before I go to WPF)
You can copy C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\WMPLib.dll and AxInterop.WMPLib.dll to your bin directory and reference these assemblies. These assemblies are compiled for 'AnyCPU'.
If your error log shows "Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config"
You are loading a 32bit COM into a 64bit process. That will cause an exception . You need to switch to use the 64bit version of Windows Media Player, or change your process to target 32bit. i.e. Change your build settings from AnyCPU to x86 or X64, and reference the 32bit or 64bit of WMP accordingly.
精彩评论