ASP.net UserControl and AppDomain TypeResolve

I use VirtualPathProvider to enable usercontrols that are not available at compile time. Everything works correctly, with the exception of a DLL link that actually contains the control.

When a page with the specified control is called, it cannot find the type of control unless I put the dll in the bin folder.

Error: Error Parser Description. An error occurred while analyzing the resource needed to service this request. Review the following parsing details and modify the source file accordingly.

Parser error message: Failed to 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 the significant AppDomain events (AssemblyResolve, TypeResolve and ReflectionOnlyAssemblyResolve), but no one called my type.

I saw in the TypeResolve documentation that this is called whenever Type.GetType is executed and the type is not found. ASCX doesn't seem to fire an event when it needs its type ... why?

Thanks! Alex

+4
source share
2 answers

The AssemblyResolve event should solve this problem, but you need to specify the assembly name in the type name, for example.

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

Then, an AssemblyResolve event will occur asking to load "YourDynamicAssemblyName".

+3
source

What content can be virtualized? Available types, such as ASPX, master pages, ASCX, and themes, are the only elements that can be virtualized ... To virtualize content that is not viewed by default, you need to map the BuildProvider class.

"When BuildProvider builds, it creates a new class in the Temporary ASP.NET Files folder. Any class added to the folder becomes automatically available to your application." So for me it seems like you need to map System.Web.Compilation.UserControlBuildProvider to create your custom controls at runtime instead of type permission, but right now I don't know how to do it. I hope it is still useful

0
source

All Articles