【发布时间】:2010-11-29 18:23:22
【问题描述】:
我有什么
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";
}
}
MyGraphicsLibrary.dll:强命名
public class GraphicsDeviceControl : System.Windows.Forms.Panel { }
public class MyModel { }
public class MyModelReader : ContentTypeReader<MyModel> { }
GraphicsDeviceControl 基于this XNA sample。
ActiveXApplication.dll:强命名,为 COM 互操作注册
[Guid("")]
[ProgId("ActiveXApplication.ActiveXControl")]
[ComVisible(true)]
public class ActiveXControl : System.Windows.Forms.UserControl { }
public class MyGraphicsDeviceControl : MyGraphicsLibrary.GraphicsDeviceControl { }
ActiveXControl 是我使用<object> 标签嵌入到 IE7/8 中的应用程序的主 UI。托管控件的站点已添加到受信任的站点。 MyGraphicsDeviceControl 根据从网页传递给 ActiveXControl 的信息加载模型。加载的模型是使用 MyModelProcessor 从 FBX 模型创建的,并使用 MyModelContentWriter 编写。我目前正在使用 XNA 3.0。
问题
当MyGraphicsDeviceControl 执行以下行时:
this.contentManager.Load<MyModel>("modelName")
我收到以下错误:
加载“pathToModel\modelName”时出错。找不到 ContentTypeReader MyGraphicsLibrary.MyModelReader、MyGraphicsLibrary。
在 Windows 窗体应用程序中使用 ActiveXControl 时不会发生此错误。使用默认 XNA 模型类时,不会发生错误(我正在尝试使用自定义模型类而不是滥用 XNA 模型类的 Tag 属性)。使用 Reflector,我通过 ContentManager.Load<T> 跟踪寻找异常的来源,并发现它发生在 XNA 尝试使用 MyModelContentWriter.GetRuntimeReader() 中定义的返回 null 的字符串调用 Type.GetType() 时。
问题
对于在 IE 中运行时尝试加载 MyModelReader 而不是 XNA 的 ModelReader 时为什么 Type.GetType() 返回 null 有什么想法吗?
更新:
在进一步研究了这个问题之后,我找到了一种方法来让我的自定义模型类在 IE 中运行时加载。通过为AppDomain.AssemblyResolve 添加处理程序,我能够返回包含MyModelReader 的程序集,这使得XNA 代码中的Type.GetType() 调用成功。
根据我阅读的有关反射和程序集加载的信息,我假设我能够毫无问题地使用 XNA 模型类,因为 XNA 程序集已在 GAC 中注册,而我的则没有。但是,MyGraphicsLibrary.dll 已经加载到 AppDomain 中,所以我不完全确定为什么它无法解析程序集。我认为它与加载它的上下文有关,但我不确定在 IE 中运行时程序集正在加载哪个上下文。
【问题讨论】:
标签: c# winforms internet-explorer activex xna