C#Windows Media Player AxHost错误:无法创建compopnent“AxHost”

时间:2016-03-29 03:52:40

标签: c# windows media-player media axhost

我正在尝试将Windows Media Player对象添加到我的Windows窗体中,但会弹出错误:

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)'

但是,如果我要创建一个新项目并添加Windows Media Player,它可以正常工作。

我尝试了一些在线解决方案,例如在新项目(使用Windows Media Player)打开时添加Windows Media Player,将现有表单添加到项目等但无济于事。

我做错了什么吗?

3 个答案:

答案 0 :(得分:2)

不确定您是否仍在为此寻找解决方案,但也许这会帮助其他人。我试图嵌入一个不同的COM对象时遇到了同样的问题。

在我的头撞墙几个小时后,我意识到在项目属性 - >构建 - >平台目标被设置为x64(因为我正在玩几个月前的东西),并且许多这些旧的COM组件以32位系统为目标。无论如何,将我的平台目标切换到“任何CPU”解决了这个问题。

的Nik

答案 1 :(得分:0)

我通过从引用中删除“ AxWMPLib”,“ WMPLib”引用来解决了此问题。 然后。 再次在表单上添加Media Player。

答案 2 :(得分:0)

对于像我这样的菜鸟 从引用中删除“ AxWMPLib”,“ WMPLib”引用,并从工具箱中删除“ Windows Media Player”,然后关闭项目(Visual Studio),然后再次打开项目,然后转到“属性”->“编译”->“目标CPU = x86和平台= x86” 通过工具箱添加Windows Media Player,然后重新生成项目。通过拖放使用工具箱添加Media Player控件。...解决问题^ _ ^