CompilerParameters.ReferencedAssemblies -- Add reference to System.Web.UI.WebControls(CompilerParameters.ReferencedAssemblies -- 添加对 System.Web.UI.WebControls 的引用)
问题描述
我正在使用 CodeDomProvider
类在运行时编译类.这适用于仅使用 System
命名空间的类:
I am compiling classes at run-time using the CodeDomProvider
class. This works fine for classes only using the System
namespace:
using System;
public class Test
{
public String HelloWorld()
{
return "Hello World!";
}
}
如果我尝试使用 System.Web.UI.WebControls
编译一个类,我会收到此错误:
If I try to compile a class using System.Web.UI.WebControls
though, I get this error:
{错误 CS0006:找不到元数据文件System.Web.UI.WebControls"}System.CodeDom.Compiler.CompilerError
{error CS0006: Metadata file 'System.Web.UI.WebControls' could not be found} System.CodeDom.Compiler.CompilerError
这是我的代码片段:
var cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.Web.UI.WebControls");
如何引用 System.Web.UI.WebControls
命名空间?
How do I reference the System.Web.UI.WebControls
namespace?
推荐答案
您引用程序集,而不是命名空间.您应该使用 MSDN 来查找包含您需要使用的类的程序集的名称:在这种情况下,它将是:
You reference assemblies, not namespaces. You should use MSDN to look up the name of the assembly that contains the classes you need to use: in this case it's going to be:
var cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.Web.dll");
这篇关于CompilerParameters.ReferencedAssemblies -- 添加对 System.Web.UI.WebControls 的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CompilerParameters.ReferencedAssemblies -- 添加对 System.Web.UI.WebControls 的引用


基础教程推荐
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01