使用 ApplicationHost.CreateApplicationHost() 创建 Asp.Net 帖子,同时从另一个位置加载程序集
我正在尝试使用 CreateApplicationHost 为简单的 Web 服务器创建 Asp.Net 应用程序主机,但是当它尝试创建编组对象的实例时,我收到 System.IO.FileNotFoundException
:
host = (MyMarshaller)ApplicationHost.CreateApplicationHost((MyMarshaller), virtualDir, physicalDir);
我相信这个错误是因为它找不到包含 MyMarshaller 类的程序集 - 如果我将此程序集放在physicalDir 的 bin 目录中,那么一切都会正常工作,但是我不想这样做(我也不想将我的程序集放入 GAC 中)。
有什么方法可以控制 CreateApplicationHost 在哪里查找我的程序集? (请注意,MyMarshaller
类与上述代码行位于同一程序集中)
I'm trying to use CreateApplicationHost to create an Asp.Net application host for a simple web server, however I'm getting a System.IO.FileNotFoundException
when it attempts to create an instance of my marshalling object:
host = (MyMarshaller)ApplicationHost.CreateApplicationHost((MyMarshaller), virtualDir, physicalDir);
I believe that this error is because it cannot find the assembly containing the class MyMarshaller - if I put this assembly in the bin directory of physicalDir then everything works fine, however I don't want to do this (I also don't want to place my assembly in the GAC either).
Is there any way that I can control where CreateApplicationHost looks for my assembly? (Note that MyMarshaller
class is conted in the same assembly as the above line of code)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的答案是不可能做到这一点,但是 Cassini 源揭示了一种替代解决方案。
更新
上面的链接不再有效,但是 CassiniDev 项目 似乎非常接近(可能是衍生作品)并且包含相同的解决方案。
解决方案是避免使用 CreateApplicationHost 并“自己动手” - 在这种情况下,使用反射创建内部“BuildManagerHost”类型的实例并调用“RegisterAssembly”,如下所示
The short answer is that it isn't possible to do this, however the Cassini source revealed an alternative solution.
Update
The above link no longer works, however the CassiniDev project on CodePlex appears to be pretty close (possibly a derivative work) and contains the same solution.
The solution is to avoid using
CreateApplicationHost
and "do it yourself" instead - in this case use reflection to create an instance of the internal "BuildManagerHost" type and call "RegisterAssembly", like so