【发布时间】:2011-07-29 08:53:55
【问题描述】:
如果我从 MVC 视图中引用 internal 类,AssemblyBuilder 会抱怨它无法在此处访问该类(这是有道理的):
System.Web.Compilation.AssemblyBuilder.Compile()
我已尝试为以下对象添加 InternalsVisibleTo 属性:
SystemSystem.WebSystem.Core
但我无法让它工作。这有可能吗?
演示:
internal static class InternalClass
{
public static string Foo = "bar";
}
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<%: InternalClass.Foo %>
堆栈跟踪:
Compiler Error Message: CS0122: 'InternalClass' is inaccessible due to its protection level
at System.Web.Compilation.AssemblyBuilder.Compile()
at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp)
编辑:请不要提出替代方法,这不是我要的。
谢谢!
【问题讨论】: