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 的引用


基础教程推荐
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 如果条件可以为空 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 将数据集转换为列表 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01