ASP .NET VirtualPathProvider HttpCompileException

允我心安 提交于 2019-12-22 10:39:32

问题


I have a VirtualPathProvider that is loading my aspx file content from a DB. All seems to be well and good except when my aspx file has a reference to a namespace or assembly that is not explicitly mentioned in my web.config.

The solution seems easy right? Add assembly and import directives to the page... But that doesn't seem to work. I still get the following HttpCompileException:

    c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET 
Files\app.server\70480a40\2a773b44\App_Web_test.aspx.e7cf0b6b.mzeindht.0.cs(183): error CS0234: 
The type or namespace name 'Model' does not exist in the namespace 'MyApp.Data' (are you missing an assembly reference?)

Even though, in my test.aspx page saved in the DB I have:

<%@ Assembly Name="MyApp.Data" %>
<%@ Import Namespace="MyApp.Data" %>
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyApp.Data.Model.TestModel>" %>

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>

Now, I already know that MyApp.Data has already been loaded into the AppDomain (I've verified at runtime by checking AppDomain.CurrentDomain.GetAssemblies()) and I know that no failed request is getting made to load the MyApp.Data assembly (because I've bound to the AppDomain.ResolveAssembly event and it's not firing right before the exception occurs). Also, if I change the name in the assembly directory to MyApp.Data123 (a bogus name), the page bombs out trying to load the assembly.

If I remove the assembly directive from the page entirely, then I get the namespace The type or namespace name 'MyApp' could not be found...so having the assembly directive there does seem to help a little bit...

Any idea what I'm missing here? Thanks.


回答1:


Possible duplicate of .NET VirtualPathProviders and Pre-Compilation

If a Web site is precompiled for deployment, content provided by a VirtualPathProvider
instance is not compiled, and no VirtualPathProvider instances are used by the precompiled 
site.


来源:https://stackoverflow.com/questions/3649091/asp-net-virtualpathprovider-httpcompileexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!