C# XNA ActiveX控件-在IE中运行时找不到自定义ContentReader

C# XNA ActiveX控件-在IE中运行时找不到自定义ContentReader,c#,winforms,internet-explorer,activex,xna,C#,Winforms,Internet Explorer,Activex,Xna,我拥有的 MyGraphicsLibrary.Content.Pipeline.dll public class MyModelProcessor { } public class MyModelContent { } [ContentTypeWriter] public class MyModelContentWriter : ContentWriter<MyModelContent> { protected override void Write(ContentWrite

我拥有的

MyGraphicsLibrary.Content.Pipeline.dll

public class MyModelProcessor { }
public class MyModelContent { }

[ContentTypeWriter]
public class MyModelContentWriter : ContentWriter<MyModelContent>
{
   protected override void Write(ContentWriter output, MeshDataContent value)
   {
       value.Write(output);
   }

   public override string GetRuntimeType(TargetPlatform targetPlatform)
   {
       return "MyGraphicsLibrary.MyModel, MyGraphicsLibrary";
   }

   public override string GetRuntimeReader(TargetPlatform targetPlatform)
   {
       return "MyGraphicsLibrary.MyModelReader, MyGraphicsLibrary";
   }
}
ActiveXControl
是我在IE7/8中嵌入的带有
标记的应用程序的主UI。控件所在的站点已添加到受信任的站点
mygraphicsdevicontrol
根据从网页传递到
ActiveXControl
的信息加载模型。加载的模型是使用
MyModelProcessor
从FBX模型创建的,并使用
MyModelContentWriter
编写。我目前正在使用XNA3.0

问题

MyGraphicsDeviceControl
执行以下行时:

this.contentManager.Load<MyModel>("modelName")
this.contentManager.Load(“modelName”)
我收到以下错误:

加载“pathToModel\modelName”时出错。找不到ContentTypeReader MyGraphicsLibrary.MyModelReader,MyGraphicsLibrary

在Windows窗体应用程序中使用
ActiveXControl
时不会发生此错误。使用默认XNA模型类时,不会发生错误(我尝试使用自定义模型类,而不是滥用XNA模型类的Tag属性)。使用Reflector,我通过
ContentManager.Load
查找异常源,发现XNA试图调用
Type.GetType()
时,使用在
MyModelContentWriter.GetRuntimeReader()
中定义的字符串(返回null)调用异常

问题

在IE中运行时,有没有想过为什么Type.GetType()在尝试加载MyModelReader而不是XNA的ModelReader时返回null

更新:

在进一步研究了这个问题之后,我找到了一种在IE中运行时加载自定义模型类的方法。通过为
AppDomain.AssemblyResolve
添加一个处理程序,我能够返回包含
MyModelReader
的程序集,该程序集允许XNA代码中的
Type.GetType()
调用成功


根据我读到的关于反射和程序集加载的信息,我假设我能够毫无问题地使用XNA模型类,因为XNA程序集是在GAC中注册的,而我的程序集不是。但是,
MyGraphicsLibrary.dll
已加载到
AppDomain
,因此我不完全确定它为什么无法解析程序集。我假设它与加载它的上下文有关,但我不确定在IE中运行程序集时加载的是哪个上下文。

将ContentManager.RootDirtory设置为abs路径。

将ContentManager.RootDirtory设置为abs路径。

您尝试过使用完整的,内容读取器类型的程序集限定名称?我注意到内容编写器的
GetRuntimeReader
覆盖没有指定公钥令牌、区域性或版本

我以前也遇到过类似您的问题,所有这些问题都是由于我没有正确指定运行时类型造成的

这可以通过
typeof().AssemblyQualifiedName
获得

Type.GetType(string)
方法在找不到类型时返回null,因此:

  • 传递的字符串没有给出名称的完全限定类型(我猜是这样),或者

  • 尚未在您试图从中加载内容的应用程序的运行时上下文中加载类型的包含程序集。您是否已将对内容管道扩展的引用添加到主项目中


  • 您是否尝试过使用内容读取器类型的完整程序集限定名称?我注意到内容编写器的
    GetRuntimeReader
    覆盖没有指定公钥令牌、区域性或版本

    我以前也遇到过类似您的问题,所有这些问题都是由于我没有正确指定运行时类型造成的

    这可以通过
    typeof().AssemblyQualifiedName
    获得

    Type.GetType(string)
    方法在找不到类型时返回null,因此:

  • 传递的字符串没有给出名称的完全限定类型(我猜是这样),或者

  • 尚未在您试图从中加载内容的应用程序的运行时上下文中加载类型的包含程序集。您是否已将对内容管道扩展的引用添加到主项目中


  • ContentManager的根目录不是这里的问题;内容管道的内部工作正在查找原始.xnb格式的内容,但找不到将其反序列化为目标类型实例所需的类型;内容管道的内部工作正在查找原始.xnb格式的内容,但找不到将其反序列化为目标类型实例所需的类型。
     [Guid("")]
     [ProgId("ActiveXApplication.ActiveXControl")]
     [ComVisible(true)]
     public class ActiveXControl : System.Windows.Forms.UserControl { }
     public class MyGraphicsDeviceControl : MyGraphicsLibrary.GraphicsDeviceControl { }
    
    this.contentManager.Load<MyModel>("modelName")