ASP.net UserControl 和 AppDomain TypeResolve [英] ASP.net UserControl and AppDomain TypeResolve

查看:23
本文介绍了ASP.net UserControl 和 AppDomain TypeResolve的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VirtualPathProvider 来包含在编译时不可用的用户控件.除了对实际包含该控件的 dll 的引用之外,一切正常.

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.

当调用具有控件的页面时,它无法找到控件类型,除非我将 dll 放在 bin 文件夹中.

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.

解析器错误消息:无法加载类型'App.Modules.ModuleA.Controls.Entity1Item'.

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

源错误:

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

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

我尝试处理所有重要的 AppDomain 事件(AssemblyResolve、TypeResolve 和 ReflectionOnlyAssemblyResolve),但没有为我的类型调用.

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

我在 TypeResolve 文档中看到,只要执行 Type.GetType 并且找不到类型,就会调用它.似乎 ASCX 在需要它的类型时没有触发事件......为什么?

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?

谢谢!亚历克斯

推荐答案

AssemblyResolve 事件应该可以解决这个问题,但是你需要在类型名称中指定程序集名称,例如

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" %>

然后会触发 AssemblyResolve 事件,要求您加载YourDynamicAssemblyName".

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

这篇关于ASP.net UserControl 和 AppDomain TypeResolve的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆