开发者

ASP.net UserControl and AppDomain TypeResolve

开发者 https://www.devze.com 2023-03-23 10:17 出处:网络
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.

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


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'.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消