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

4

5

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?

Spahi answered 29/3, 2016 at 3:52 Comment(0)
C
6

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

Citystate answered 15/11, 2016 at 0:46 Comment(2)
Thanks. This got me in the right direction, but I also had to check the box to "Allow unsafe code".Chellman
This doesn't work in VS2022. Is there any other solutionCommixture
G
5

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

Gorged answered 19/8, 2018 at 19:0 Comment(1)
This worked. Thanks!Pepin
T
1

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 ^_^

Tub answered 29/7, 2020 at 22:23 Comment(0)
A
0

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.
Antoniaantonie answered 27/9 at 11:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.