【问题标题】:XNA ActiveX Control - Cannot find custom ContentReader when running in IEXNA ActiveX 控件 - 在 IE 中运行时找不到自定义 ContentReader
【发布时间】: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 是我使用&lt;object&gt; 标签嵌入到 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&lt;T&gt; 跟踪寻找异常的来源,并发现它发生在 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


    【解决方案1】:

    将 ContentManager.RootDirctory 设置为绝对路径。

    【讨论】:

    • ContentManager 的 RootDirectory 不是这里的问题;内容管道的内部工作是查找原始 .xnb 格式的内容,但找不到将其反序列化为目标类型实例所需的类型。
    【解决方案2】:

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

    我之前也遇到过类似你的问题,都是我没有正确指定运行时类型造成的。

    可以通过typeof(&lt;your content reader type&gt;).AssemblyQualifiedName获取。

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 2021-09-20
      相关资源
      最近更新 更多