CS7069:对“CodeCompileUnit”类型的引用声称它在“系统”中定义,但无法找到

时间:2018-05-16 13:26:02

标签: c# asp.net .net razor codedom

我正在尝试编译razor html模板,以便在Microsoft .net Framework 4开发中的webbrowser控件中使用。一切都很好,直到我想调用“codeProvider.GenerateCodeFromCompileUnit”。 IDE说类型CodeCompileUnit的类型引用是在System中进行的,即使我能够自己声明一个CodeCompileUnit ......

我已经检查了引用,清理了解决方案,试图重新启动IDE和类似的东西,但似乎没有什么可以解决问题。

我真的不知道该怎么做。这是当前的代码:

public static Assembly Compile(IEnumerable<RazorTemplateModel> models)
{
  var builder = new StringBuilder();
  var codeProvider = new CSharpCodeProvider();
  using (var writer = new StringWriter(builder))
  {
    foreach (var razorTemplateModel in models)
    {
      GeneratorResults generatorResults = GenerateCode(razorTemplateModel);
      codeProvider.GenerateCodeFromCompileUnit(generatorResults.GeneratedCode, writer, new CodeGeneratorOptions());
    }
  }

  var result = codeProvider.CompileAssemblyFromSource(BuildCompilerParameters(), new[] { builder.ToString() });
  if (result.Errors != null && result.Errors.Count > 0)
    throw new RazorTemplateCompileException(result.Errors, builder.ToString());

  return result.CompiledAssembly;
}

代码的第10行显示以下错误消息:

ErrorMessage

以下是项目中系统参考的屏幕截图:

SystemReferences

有人可以帮忙吗?

编辑:忘记提及我在Mono.Android项目中使用Xamarin.Android.Support.v4中的引用

1 个答案:

答案 0 :(得分:0)

* def integrationName = 'hello' * def tenantID = 'world' * def recRef = 'fld_[' + tenantID + ']_stage00.documenttypes:sum2' # by the way this is also possible as an embedded expression #('fld_[' + tenantID + ']_stage00.documenttypes:sum2') * string signature = {"sig_in":{"rec_ref":"#(recRef)","field_type":"recref","node_type":"record","field_dim":"0"},"sig_out":{"field_type":"record","node_type":"record","field_dim":"0"}} * def xml = """ <xml xmlns="http://www.w3.org/1999/xhtml"> <block type="start_block" id="foOIiCF5aZGnie1GzBDB" deletable="false" x="150" y="25"> <field name="ORCH_NAME">Add2NumDocInputs</field> <field name="SVC_SIGNATURE">#(signature)</field> <field name="AUDIT_SETTINGS"></field> <statement name="ADD_BLOCKS"> <block type="service_block_math" id="aUqb0MAozTHQFuHj5rma"> <field name="SERVICE">pub.math:addInts</field> <field name="SERVICE_DESC_FIELD"></field> <field name="SERVICE_DETAILS">{"service":"pub.math:addInts","map":[{"sourcePath":"/n2;1;0","targetPath":"/num2;1;0"},{"sourcePath":"/n1;1;0","targetPath":"/num1;1;0"}]}</field> </block> </statement> </block> </xml> """ * xmlstring xml = xml * def json = """ { "integration": { "serviceData": { "integrationService": { "name": "#(integrationName)", "description": "#(tenantID)", "serviceData": "#(xml)" } } } } """ * match json == """ { "integration": { "serviceData": { "integrationService": { "name": "hello", "description": "world", "serviceData": "#string" } } } } """ * match json.integration.serviceData.integrationService.serviceData contains '"rec_ref":"fld_[world]_stage00.documenttypes:sum2"' 命名空间下出现,因此您可能需要添加System.CodeDOM。见https://msdn.microsoft.com/en-us/library/system.codedom.codecompileunit(v=vs.110).aspx

另外,您可以查看您引用的using System.CodeDOM; dll版本吗?