动态加载页面类/组件:类型或名称不能在全局命名空间中发现 [英] Dynamically Loading Page Class/Assembly: Type or name could not be found in the global namespace

查看:197
本文介绍了动态加载页面类/组件:类型或名称不能在全局命名空间中发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求我试图创建一个存储它的内容(ASPX / ASCX和组件)的地方不是文件系统以外的ASP.Net Web应用程序(内部服务,例如)并加载它们的动态。

I am trying to create an ASP.Net Web application that stores it's "content" (ASPX/ASCX and assemblies) somewhere other than the file system (Inside a service, for example) and loads them in dynamically as required.

我已成功创建的VirtualPathProvider,它利用读护理ASPX /主/从备用位置ASCX文件,但我遇到问题时,这些ASPX页面继承一个类 - 即:当他们有code后面

I have successfully created a VirtualPathProvider that takes care of reading ASPX/Master/ASCX files from alternate locations but I am running into problems when those ASPX pages Inherit a class - ie: when they have code behind.

由于在另一个问题我现在能够成功的组件加载到应用程序在运行时。但是,当我运行时尝试编译我的网页我收到以下错误:

Thanks to answers in another question I am now successfully able to load the assemblies into the application at run time. But when my the runtime attempts to compile my page I get the following error:

编译器错误信息:CS0400:本
  类型或命名空间名称网页无法
  在全局命名空间中找到(是
  缺少程序集引用?)

"Compiler Error Message: CS0400: The type or namespace name 'Web' could not be found in the global namespace (are you missing an assembly reference?)"

[System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
  公共类default_aspx
  :。全球网站:: code codeBehind,
  System.Web.SessionState.IRequiresSessionState,
  System.Web.IHttpHandler

[System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()] public class default_aspx : global::Web.Code.CodeBehind, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler

我有我的code归结到了什么错误,这样很容易给你看一个简单的例子。 你可以在这里下载这code。

I have boiled down my code to a simple example of what is going wrong so that it is easy for you to see. You can download this code here.

的组件被加载在在运行时动态使用AppDomain.AssemblyResolve事件。这是在Global.asax,看起来像这样:

The assembly is being loaded in dynamically at run time using the AppDomain.AssemblyResolve event. This is in the global.asax and looks like this:

protected void Application_Start(object sender, EventArgs e)
{
    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Assembly_Resolve);
}

Assembly Assembly_Resolve(object sender, ResolveEventArgs args)
{
    Assembly assembly = AppDomain.CurrentDomain.Load(Resources.Web_Code);
    if (args.Name == assembly.FullName)
    {
        return assembly;
    }
    return null;
}

任何想法?

修改
如果出于任何原因,你需要更新Web code组件 - 你需要将它复制到Web项目对于那些更改生效的ReferencedAssemblies文件夹中。

EDIT If for any reason you need to update the Web.Code assembly - you will need to copy it into the "ReferencedAssemblies" folder of the web project for those changes to take effect.

推荐答案

我试图从数据库加载组件(和使用AssemblyResolve事件)时遇到了同样的问题。但似乎,如果你从磁​​盘加载组件或至少某处保存在磁盘上的.dll文件的副本,做工精细。

I encountered the same problem when trying to load assemblies from DB (and using the AssemblyResolve event). But it seems to work fine if you load assemblies from disk or at least save a copy of the .dll file somewhere on the disk.

这篇关于动态加载页面类/组件:类型或名称不能在全局命名空间中发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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