ASP.NET加载bin中的所有程序集来查找用户控件

发布于 2024-09-28 22:07:48 字数 3586 浏览 1 评论 0原文

我们的 Web 应用程序的一部分使用了内部 Web 控制组件。该程序集包含多个 Web 用户控件,其中多个控件由同一程序集中的其他 Web 控件使用。

该程序集被构建为带有 Web 部署项目的网站。

主 Web 应用程序的页面通过服务动态编译为单个程序集,并放入适当的 bin 文件夹中。在我们的开发服务器中,旧程序集并不总是被整理和删除,这意味着文件夹中充满了旧程序集。

当使用内部 Web 控件程序集(上面提到的)的页面运行时,asp.net 实例会抛出内存不足的错误,因为它会加载所有旧程序集,试图确定哪个程序集包含对正在使用的用户控件的引用。由同一程序集中的其他用户控件使用。

我们一直在顶级用户控件中使用以下内容来注册其他控件

<%@ Register Src="~/....ascx" TagPrefix="UC" TagName="...."  %>

当然,当应用程序运行时,这不会提供有关它可以在哪个程序集中找到它的信息。

以前有人遇到过这个问题吗? 这并不是一个真正的问题,因为我们的实时服务器使用清理工具来删除旧程序集,但仍然存在潜在的情况,我们可能会因此而导致内存不足(例如该工具停止工作!),所以这会很好来解决这个问题。

谢谢

这是堆栈跟踪

[OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
   System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +54
   System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +8812786
   System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +128
   System.Web.Compilation.BuildManager.CompileCodeDirectories() +265
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +320

[HttpException (0x80004005): Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +58
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +512
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +729

[HttpException (0x80004005): Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8894095
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +259

Part of a web application we have uses an in-house web control assembly. This assembly contains several web user controls where several of these are used by other web controls within the same assembly.

The assembly is built as a website with a web deployment project.

The main web application's pages are dynamically compiled through a service into a single assembly and placed into the appropriate bin folder. In our development server the old assemblies aren't always tidied up and removed, meaning the folder gets full of old assemblies.

When the page that uses the in-house web control assembly (mentioned above) runs, the asp.net instance throws an out of memory as it loads all the old assemblies in an attempt to determine which assembly houses the reference to the user control being used by the other user control inside the same assembly.

We've been using the following inside the top level user controls to register the other controls

<%@ Register Src="~/....ascx" TagPrefix="UC" TagName="...."  %>

Of course when the application runs this gives no information as to which assembly it can find it in.

Is there anyone that's come across this problem before?
It's not really a problem as our live servers use a clean up tool to remove old assemblies, but there are still potential situations where we could get out of memory caused by this (for example the tool stops working!), so it would be nice to resolve this problem.

Thanks

Here is the stack trace

[OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
   System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +54
   System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +8812786
   System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +128
   System.Web.Compilation.BuildManager.CompileCodeDirectories() +265
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +320

[HttpException (0x80004005): Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +58
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +512
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +729

[HttpException (0x80004005): Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8894095
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +259

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

快乐很简单 2024-10-05 22:07:49

对于这些情况,我会在 web.config 中注册控件。

    <pages>
        <controls>
            <add tagPrefix="yourPrefix" namespace="Your.Lib.Controls" assembly="Your.Lib.Controls"/>
        </controls>
    </pages>

For those cases I do the registration of the controls in my web.config.

    <pages>
        <controls>
            <add tagPrefix="yourPrefix" namespace="Your.Lib.Controls" assembly="Your.Lib.Controls"/>
        </controls>
    </pages>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文