ASP.net UserControl 和 AppDomain TypeResolve
我使用 VirtualPathProvider 来包含编译时不可用的用户控件。 除了对实际包含控件的 dll 的引用之外,一切都工作正常。
当调用具有该控件的页面时,它无法找到控件类型,除非我将 dll 放在 bin 文件夹中。
错误: 解析器错误 描述:解析服务此请求所需的资源时发生错误。请查看以下特定解析错误详细信息并适当修改您的源文件。
解析器错误消息:无法加载类型 'App.Modules.ModuleA.Controls.Entity1Item'。
来源错误:
第 1 行:<%@ Control Language="C#" AutoEventWireup="true" CodeBehind =“Entity1Item.ascx.cs” Inherits="App.Modules.ModuleA.Controls.Entity1Item" %>
我尝试处理所有重要的 AppDomain 事件(AssemblyResolve、TypeResolve 和 ReflectionOnlyAssemblyResolve),但没有为我的类型调用任何事件。
我在 TypeResolve 文档中看到,只要执行 Type.GetType 并且未找到该类型,就会调用此函数。似乎 ASCX 在需要其类型时没有触发事件......为什么?
谢谢! 亚历克斯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AssemblyResolve 事件应该可以解决这个问题,但是您需要在类型名称中指定程序集名称,例如,
AssemblyResolve 事件将触发,要求您加载“YourDynamicAssemblyName”。
An AssemblyResolve event should solve this, but you need to specify the assembly name in the type name, e.g.
The AssemblyResolve event will then fire asking you to load 'YourDynamicAssemblyName'.
哪些内容可以虚拟化?
可浏览类型,例如 ASPX、母版页、ASCX 和主题,是唯一可以虚拟化的项...要虚拟化非默认可浏览内容,需要映射一个 BuildProvider 类。
”当一个 BuildProvider构建时,它会在临时 ASP.NET 文件文件夹中构建一个新类,添加到该文件夹的任何类都会自动可供您的应用程序使用。”因此,对我来说,您似乎需要映射 System.Web.Compilation.UserControlBuildProvider 来在运行时构建用户控件,而不是解析类型,但现在我不知道该怎么做。希望它仍然有用
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