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

Dar*_*Lee 3 c# windows media axhost media-player

我正在尝试将 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)'
Run Code Online (Sandbox Code Playgroud)

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

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

有什么我做错了吗?

小智 6

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

在我的头撞墙几个小时后,我意识到在项目 Properties -> Build -> Platform Target 中被设置为 x64(因为几个月前我在玩一些东西),许多这些旧的 COM程序集面向 32 位系统。无论如何,将我的平台目标切换为“任何 CPU”解决了这个问题。

尼克