简体   繁体   English

使用RazorTemplates库时发生错误:'CS0012:类型'System.Attribute'在未引用的程序集中定义'

[英]Error when using RazorTemplates library: 'CS0012: The type 'System.Attribute' is defined in an assembly that is not referenced'

On some machines, executing a razor template via RazorTemplates works OK. 在某些计算机上,通过RazorTemplates执行剃刀模板可以RazorTemplates工作。

On others, I receive the following message: 在其他情况下,我收到以下消息:

TemplateCompilationException

error CS0012: The type 'System.Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Info: 信息:

  • This is within a WPF application running on .NET 4.7. 这是在.NET 4.7上运行的WPF应用程序中。
  • The assembly has a reference to System.Runtime.4.3.0\\lib\\net462\\System.Runtime.dll (v4.1.1.0) 该程序集具有对System.Runtime.4.3.0 \\ lib \\ net462 \\ System.Runtime.dll(v4.1.1.0)的引用
  • However at runtime, this assembly does not show up in the 'Modules' list. 但是,在运行时,该程序集不会显示在“模块”列表中。

It seems the Attribute object exists in both System.Runtime and mscorlib. 似乎Attribute对象同时存在于System.Runtime和mscorlib中。

Looks like this is an underlying issue somewhere between win10 and the RazorTemplates library. 看起来这是win10和RazorTemplates库之间某个潜在的问题。

In the end i switched from RazorTemplates to RazorEngine: https://github.com/Antaris/RazorEngine 最后,我从RazorTemplates切换到RazorEngine: https : //github.com/Antaris/RazorEngine

And there is a page here that explains how to fix the problem via a Resolver: 这里有一个页面,说明如何通过解析器解决问题:

https://github.com/Antaris/RazorEngine/issues/416 https://github.com/Antaris/RazorEngine/issues/416

System.Runtime is part of the .Net Framework and is installed in the GAC during framework installation. System.Runtime是.Net Framework的一部分,并且在框架安装期间安装在GAC中。

This could happen for two possible reasons: 发生这种情况可能有两个原因:

  1. It's not on the machine. 它不在机器上。
  2. It's the wrong version. 版本错误。

For the machines this fails on check what version of the .Net runtime they have and/or inspect the GAC for this file and version. 对于机器,这无法检查它们具有的.Net运行时版本和/或检查GAC的文件和版本。

Missing the framework, install it. 缺少框架,请安装它。 :-) :-)

If machines have a version but it's not the expected version do either: 如果计算机具有版本,但不是预期的版本,请执行以下任一操作:

  1. Install the correct framework version 安装正确的框架版本
  2. Use a binding redirect in your config file 在配置文件中使用绑定重定向

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误CS0012:类型“DbConnection”在未引用的程序集中定义 - Error CS0012: The type 'DbConnection' is defined in an assembly that is not referenced 错误CS0012:类型'TaskAwaiter <>'在未引用的程序集中定义 - error CS0012: The type 'TaskAwaiter<>' is defined in an assembly that is not referenced CS0012 C#类型“ HttpContext”在未引用的程序集中定义 - CS0012 C# The type 'HttpContext' is defined in an assembly that is not referenced CS0012 类型“EventLogEntryType”在未引用的程序集中定义 - CS0012 The type 'EventLogEntryType' is defined in an assembly that is not referenced 错误CS0012:类型&#39;ConnectionStringSettings&#39;在升级到Visual Studio 2015后未引用的程序集中定义 - error CS0012: The type 'ConnectionStringSettings' is defined in an assembly that is not referenced after upgrading to Visual Studio 2015 .Net Core-CS0012&#39;对象&#39;在未引用的程序集中定义 - .Net Core - CS0012 'Object' is defined in an assembly that is not referenced CS0012 System.enum在未针对.NET 4.5的构建服务器上引用的程序集中定义 - CS0012 System.enum is defined in an assembly not referenced on build server targeting .NET 4.5 FluentAssertions 错误 CS0012:您必须添加对程序集 System.Data 的引用 - FluentAssertions error CS0012: You must add a reference to assembly System.Data MSBuild错误CS0012 - MSBuild Error CS0012 CS0012构建入门Xamarin Android应用程序时出错 - CS0012 Error when building the getting started Xamarin Android app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM