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


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 输入按键事件处理程序 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01