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

标签 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(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 Interop

 [Guid("")]
 [ProgId("ActiveXApplication.ActiveXControl")]
 [ComVisible(true)]
 public class ActiveXControl : System.Windows.Forms.UserControl { }
 public class MyGraphicsDeviceControl : MyGraphicsLibrary.GraphicsDeviceControl { }

ActiveXControl是我在 IE7/8 中使用 <object> 嵌入的应用程序的主 UI标签。托管控件的站点已添加到受信任的站点。 MyGraphicsDeviceControl根据传递给 ActiveXControl 的信息加载模型从网页。加载的模型是使用 MyModelProcessor 从 FBX 模型创建的并写成 MyModelContentWriter .我目前正在使用 XNA 3.0。

问题

MyGraphicsDeviceControl执行以下行:

this.contentManager.Load<MyModel>("modelName")

我收到以下错误:

Error loading "pathToModel\modelName". Cannot find ContentTypeReader MyGraphicsLibrary.MyModelReader, MyGraphicsLibrary.

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

问题

关于在 IE 中运行时尝试加载 MyModelReader 而不是 XNA 的 ModelReader 时 Type.GetType() 为何返回 null 的任何想法?

更新:

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

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

最佳答案

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

关于c# - XNA ActiveX 控件 - 在 IE 中运行时找不到自定义 ContentReader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4306759/

相关文章:

C# selenium 加载 html

c# - 如何防止DataGridView水平滚动时出现闪烁?

c# - asp.net 中服务器传输中的 ThreadAbortException

c# - 获取当前消息框

winforms - trap {}在winforms中不起作用

c# - 使用 LINQ to SQL 的条件投影

c# - 如何在 Windows 窗体中有 2 个连接字符串

Java/Selenium (ieDriver) - 如何避免在每次测试运行中重复 webapp 登录 Before Method (jUnit)

javascript - 如果浏览器不是 Internet Explorer 9 或更高版本,则显示一条消息

javascript - 为什么 IE 不显示此 alert()?