darrenleeyx
darrenleeyx

Reputation: 492

C# Windows Media Player AxHost Error: Failed to create compopnent 'AxHost'

I am trying to add a Windows Media Player object to my Windows form but it pops out an error:

Failed to create compopnent 'AxHost'. The error message follows:
'System.Reflection.ReflectionTypeLoadException: Unable to load
one or more of the requested types. Retrieve the LoaderExceptions
property for more information.
  at
System.Windows.Forms.Design.DocumentDesigner.AxToolboxItem.
CreateComponentsCore(IDesignerHost host)
  at
System.Drawing.Design.ToolboxItem.CreateComponentsCore(IDesignerHost 
host, IDictionary defaultValues)
  at
System.Drawing.Design.ToolboxItem.CreateComponents(IDesignerHost
host, IDictionary defaultValues)
  at
System.Windows.Forms.Design.OleDragDropHandler.CreateTool(ToolboxItem
tool, Control parent, int32 x, int32 width, int32
height, Boolean hasLocation, Boolean hasSize,
ToolboxSnapDragDropEventArgs e)'

However, if I were to create a new project and add the Windows Media Player, it works perfectly fine.

I have tried some solutions online such as adding the Windows Media Player while the new project (With Windows Media Player) is open, adding the existing form to the project etc. but to no avail.

Is there anything that I have done wrongly?

Upvotes: 5

Views: 4233

Answers (4)

osbuilder
osbuilder

Reputation: 216

This is how I solved the problem under VB, Since windows media player is based on x86 binaries by default, the following trick is used to use it under x64 application:

  1. Set Project build type as Any CPU
  2. Add Windows Media Player control, it is not available in the toolbox, right click on the toolbox, select "Choose items", the From COM components tab, select Media Player.
  3. Change project build type to x86 and run it, it will copy the required binaries into obj/x86/debug
  4. From project properties->References, remove references to the AxInterop.WMPLib and Interop.WMPLib that are automatically added by VB. Then manually add the same binaries by selecting them from the obj/x86/debug folder.
  5. Change project build type to x64 or any other type. There will be no Designer error after re-loading the project.

Upvotes: 0

Adam
Adam

Reputation: 323

For Noobs Like Me Remove 'AxWMPLib',"WMPLib" reference from references and also "Windows Media Player" from ToolBox then Close Project (Visual Studio) Then Open Project Again then go to Properties -> Compile -> Target CPU = x86 and Platform = x86 Then Add Windows Media Player Thru The ToolBox then Rebuild The Project. Add Media Player Control using the toolbox via Drag and Drop.... Problem Solve ^_^

Upvotes: 1

uniqueSolutions
uniqueSolutions

Reputation: 163

I solved this problem by removing 'AxWMPLib',"WMPLib" reference from references. Then. Again adding Media Player On the Form.

Upvotes: 6

Nik
Nik

Reputation: 61

Not sure if you're still looking for a solution for this, but maybe this will help someone else. I was just having the same issue with trying to embed a different COM object.

After banging my head against the wall for a couple hours, I realized that in the project Properties -> Build -> Platform Target was set to x64 (because I was playing with something a couple of months back), and many of these old COM assemblies target 32 bit systems. Anyways, switching my Platform target to "Any CPU" solved the issue.

Nik

Upvotes: 6

Related Questions