4

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

AlexCode
  • 4,055
  • 4
  • 33
  • 46
  • I'm having the same problem - when I trace AppDomain.GetAssemblies() it lists the assembly containing the type, hence I'm not sure it actually needs to fire the TypeResolve event, however when loading the UserControl it throws the "Could not load type..." exception. – lukiffer Aug 02 '11 at 18:42
  • You wrote "I'm using a VirtualPathProvider to include usercontrols that are not available at compile-time". Note that user controls (ascx files) are never needed at compile time, and are always processed at runtime. So you should not need a VPP. You may need to clarify what you're trying to do. – David Ebbo Aug 02 '11 at 19:36
  • I'm not sure about the original questioner's project, but I'm retrieving the ascx file (embedded resource) from an assembly (precompiled site), thus the use of a VPP. – lukiffer Aug 02 '11 at 19:39
  • Also, can you clarify where that Entity1Item type is defined? What assembly is it in, and where is that assembly? – David Ebbo Aug 02 '11 at 19:40
  • Lukiffer: yes, VPP makes sense if your ascx is not on the file system. But the issue here seems to related more to the assembly that contains the base class than to the ascx itself. – David Ebbo Aug 02 '11 at 19:42
  • David Ebbo: agreed, it appears that the difference is whether or not the assembly containing the base class is a Dynamic Assembly. If I add the path where that DLL is contained to the probing paths in the runtime section of web.config, rather than relying on the AssemblyResolve event, it works fine. – lukiffer Aug 03 '11 at 18:43

2 Answers2

3

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

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
0

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

elevener
  • 1,097
  • 7
  • 20