在asp.net中动态加载程序集
我目前正在尝试从 asp.net httphandler 中动态加载程序集。我有一个作为单独库的一部分构建的 dll,我的项目包含对所述 DLL 的引用,并与 CopyLocal true 的服务一起部署。我创建了一个一次性对象来获取程序集路径,并且已确认 Temporary ASP.NET Files 文件夹中存在该 dll,但调用 GetTypes() 会引发异常。
我做了类似的事情:
string assemblyPath = new SomeClassInAssembly().GetType().Assembly.Location;
Type[] types = System.Reflection.Assembly.LoadFrom(assemblyPath).GetTypes();
我无法将程序集添加到 GAC,因为这会破坏我尝试对服务执行的操作(认为必要时加载程序集的沙箱服务),并且我找不到任何能够解决我的问题的东西远的。
作为参考,我使用的是 VS 2008。
I'm currently trying to dynamically load an assembly from within a asp.net httphandler. I have a dll that is built as part of a seperate library and my project contains a reference to said DLL and is deployed along with the service with CopyLocal true. I create a throwaway object to get the assembly path and I have confirmed the existence of the dll within the Temporary ASP.NET Files folder, but calling GetTypes() throws an exception.
I do something like:
string assemblyPath = new SomeClassInAssembly().GetType().Assembly.Location;
Type[] types = System.Reflection.Assembly.LoadFrom(assemblyPath).GetTypes();
I cannot add the assembly to the GAC since that would defeat what I am trying to do with the service (think sandbox service that loads assemblies when necessary) and I cannot find anything that has been able to fix my problem thus far.
For reference I'm using VS 2008.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您使用对程序集的引用来编译 Web 应用程序,因此我认为您不需要使用 Assembly.LoadFrom 加载它。 GetTypes 应该可以使用:
Since you compile your web application with a reference to the assembly i don't see your need to load it using Assembly.LoadFrom. The GetTypes should be available using:
哦,我终于连接到了异常并查看了 LoaderMessage,我缺少一个引用的程序集。
Doh, I finally hooked up to the exception and looked at the LoaderMessage and I was missing a referenced assembly.