ASP.net UserControl and AppDomain TypeResolve

ⅰ亾dé卋堺 提交于 2019-12-10 15:53:29

问题


I'm using a VirtualPathProvider to include usercontrols that are not available at compile-time. Everything is working correctly except for the reference to the dll that actually contains the control.

When the page that has the control is called it can't find the control type unless I put the dll on the bin folder.

Error: Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'App.Modules.ModuleA.Controls.Entity1Item'.

Source Error:

Line 1: <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Entity1Item.ascx.cs" Inherits="App.Modules.ModuleA.Controls.Entity1Item" %>

I tried to handle all significant AppDomain events (AssemblyResolve, TypeResolve and ReflectionOnlyAssemblyResolve) but none get called for my type.

I saw in the TypeResolve documentation that this is called whenever a Type.GetType is executed and the type isn't found. Seem like the ASCX isn't triggering the event when it needs its type... why?

Thanks! Alex


回答1:


An AssemblyResolve event should solve this, but you need to specify the assembly name in the type name, e.g.

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Entity1Item.ascx.cs"
    Inherits="App.Modules.ModuleA.Controls.Entity1Item, YourDynamicAssemblyName" %>

The AssemblyResolve event will then fire asking you to load 'YourDynamicAssemblyName'.




回答2:


Which content can be virtualized? Browseable types, such as ASPX, master pages, ASCX, and themes, are the only items that can be virtualized ... To virtualize non-default browsable content, you need to map a BuildProvider class.

"When a BuildProvider builds, it builds a new class in the Temporary ASP.NET Files folder. Any class added to the folder becomes available to your application automatically." So for me it look's like you need to map System.Web.Compilation.UserControlBuildProvider to build your usercontrols at runtime instead of resolving type, but right now I don't know how to do it. Hope it's still useful



来源:https://stackoverflow.com/questions/6843152/asp-net-usercontrol-and-appdomain-typeresolve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!