ASP.NET卸载程序集中的程序集 [英] ASP.NET unloading assemblies in the bin

查看:117
本文介绍了ASP.NET卸载程序集中的程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ASP.NET应用程序通过在完全限定的字符串引用上使用Type.GetType()并实例化该类型的对象来利用模块"系统.

My ASP.NET application utilises a "Modules" system by using Type.GetType() on a fully-qualified string reference, and instantiating an object of that type, as you do.

但是,最近它因无法找到类型而抛出异常-只是偶尔出现.我无法随意复制,但是通常会在对非Bin相关的内容(例如母版页或ASCX标记)进行简单更改后发生.在我重建站点或重新启动IIS之前,它不会对其进行排序.更改web.config不能解决该问题.

However, recently it has been throwing exceptions at not being able to find the types - but only occasionally. I haven't been able to replicate at will, but it usually happens after a simple change to something non-bin-related like a Master Page or ASCX markup. It doesn't sort itself until I rebuild the site or restart IIS. Making a change to the web.config does not fix it.

在web.config中为程序集添加显式引用,而不是希望使它位于bin目录中,这样可以减少问题的发生,但并不能完全阻止问题的发生.不知何故,某处某处认为删除我的程序集是个好主意.

Adding an explicit reference to the assembly in the web.config rather than making hoping it gets found sitting in the bin directory reduces the occurrence of the issue, but does not prevent it from happening entirely. Somehow, something somewhere is thinking it's a good idea to remove my assembly.

我已经调试到无法找到类型的地方,并且正确地进行了调试,尽管在前一页页面加载中,程序集似乎从Thread.GetDomain().GetAssemblies()中消失了.显然,当应用程序处于活动状态时,我不能冒险发生这种情况,因此我在DLL上手动调用了Assembly.LoadAssembly(),我知道它只需要看看是否值得创建一个尝试找到程序集的方法即可.这也不起作用,因为当我尝试使用该类时,它引发了以下错误:

I've debugged into where it fails to find the type and right enough, despite being there on the previous page load, the assembly seems to disappear out of the Thread.GetDomain().GetAssemblies(). Clearly, I can't risk this happening when the application is live so I manually called Assembly.LoadAssembly() on the DLL I knew it needed just to see if it would be worth creating a method that would try to locate the assembly. This didn't work either, as it then threw the following error when I tried to use the class:

[A] xxx.Modules.CustomCaseStudy无法 被铸成 [B] xxx.Modules.CustomCaseStudy. A型 源自'xxx.Modules, 版本= 1.0.0.0,文化=中性, 上下文中的PublicKeyToken = null' 位置均不加载 'C:\ Development \ xxx \ xxx.Web \ bin \ xxx.Modules.dll'. 类型B源自'xxx.Modules, 版本= 1.0.0.0,文化=中性, 上下文中的PublicKeyToken = null' 位置为默认" 'C:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ Temporary ASP.NET 文件\ root \ fff474e0 \ 8c6aec7e \ assembly \ dl3 \ 325b4335 \ 009dbd67_b2fbc901 \ xxx.Modules.DLL'.

[A]xxx.Modules.CustomCaseStudy cannot be cast to [B]xxx.Modules.CustomCaseStudy. Type A originates from 'xxx.Modules, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location 'C:\Development\xxx\xxx.Web\bin\xxx.Modules.dll'. Type B originates from 'xxx.Modules, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\fff474e0\8c6aec7e\assembly\dl3\325b4335\009dbd67_b2fbc901\xxx.Modules.DLL'.

一直以来,所需的DLL位于bin文件夹中,等待-否,恳求使用,更不用说web.config中的显式引用了.

All the while, the required DLL is sitting in the bin folder, waiting - nay, begging to be used, not to mention the explicit reference in the web.config.

任何跟踪罪魁祸首的信息,甚至是不得已时如何将程序集加载到默认"上下文中的信息,都将不胜感激!

Any information in tracking down the culprit, or even as a last resort how to load that assembly into the "Default" context would be greatly appreciated!

推荐答案

添加以下行:

<add assembly="*"/>

到web.config并使用该网站超过两个星期,我再也没有遇到这个问题.我希望它无论如何都将垃圾箱中的所有内容加载,因此它没有看上去那么肮脏的暴力解决方案!

to the web.config and used the site for over two weeks, I haven't run into this problem again. I want it to load everything in the bin anyway, so it's not as dirty a brute-force solution as it may look!

这篇关于ASP.NET卸载程序集中的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆