CSharpCodeProvider.CompileAssemblyFromSource 不知道类型“List<>”

问题描述 投票:0回答:0

我正在使用 aspx 模板使用 VS 2022 和来自 nuget 包 Microsoft.CodeDom.Providers.DotNetCompilerPlatform 的 CSharpCodeProvider 创建(数据访问)类。在我开始像这样在代码中使用 List<> 之前,它工作正常:

<%@ Page Language="C#" %>

<%@ Import namespace="SubSonic.Utilities"%>
<%@ Import Namespace="SubSonic" %>

<%
    List<string> columnsToIgnore = new List<string> { "TimeStart", "TimeEnd" };
    ...

我打电话

codeProvider.CompileAssemblyFromSource(codeCompilerParameters, templateArray)

其中 codeCompilerParameters 包含必要的引用,例如。 G。 mscorlib.dll(其中包含 List<> 的 System.Collections.Generic 命名空间)。

但是编译器返回“找不到类型或命名空间名称‘List<>’(是否缺少 using 指令或程序集引用?)”。我错过了什么?

c# asp.net namespaces code-generation
© www.soinside.com 2019 - 2024. All rights reserved.