不能定义使用“dynamic”的类或成员,因为编译器需要类型为“system . run - time. compiler services . dynamicattribute”

时间:2022-08-18 20:17:48

I'm trying to run a .NET MVC application on my local computer that I got from GitHub.

我正在尝试在我的本地计算机上运行。net MVC应用程序,这是我从GitHub上获得的。

When I hit run on Visual Studio, everything complies and a new browser window opens with the error:

当我在Visual Studio上运行时,所有的内容都是一致的,一个新的浏览器窗口会出现错误:

CS1980: Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute'

CS1980:无法定义使用“动态”的类或成员,因为编译器需要类型“system . runtime.compile . dynamicattribute”

The compiler section in the same window, shows the following error:

同一窗口中的编译器部分显示如下错误:

不能定义使用“dynamic”的类或成员,因为编译器需要类型为“system . run - time. compiler services . dynamicattribute”

I've checked on google and this seems to be the same error.

我检查了谷歌,这似乎是同一个错误。

This guy was using a dynamic type himself, on the other hand I'm not using any dynamic type, this is being auto generated by .NET's compiler, and I'm using .net 4.5 which should has support for dynamics.

这家伙自己使用的是动态类型,另一方面,我没有使用任何动态类型,这是由。net的编译器自动生成的,我使用。net 4.5应该支持动态。

I tried to apply the same solution (Changing all System.Core references to 4.0) but the thing is that all of them are version 4.0 already.

我尝试应用相同的解决方案(改变所有的系统)。核心参考4.0)但问题是所有的都已经是4.0版本了。

Do you have any idea how could I resolve this?

你知道我该怎么解决这个问题吗?

5 个解决方案

#1


15  

I had a similar error on a project I was trying to migrate. Try re-targeting the framework of the project back a version or two, and once you find a target version where you do not get the error, re-target back to the version you originally had trouble with.

我试图迁移的一个项目也有类似的错误。尝试将项目的框架重新定位为一个或两个版本,一旦你找到了一个目标版本,你就不会得到错误,重新回到原来的版本。

I was getting the same error on a website project targeted for 4.6.2 that was referencing some older libraries, re-targeted it back to 4.5.1 and that resolved the error. I immediately re-targeted back to 4.6.2 and did not encounter the error again.

我在一个针对4.6.2的网站项目中得到了同样的错误,该项目引用了一些旧的库,将其重新定位到4.5.1,从而解决了错误。我立即重新定位到4.6.2,没有再次遇到错误。

#2


8  

I got this error suddenly a couple days after updating to VS2015.3 using 'traditional' MVC app (not new .NET Core / vNext app).

我在更新到VS2015.3的几天后突然出现了这个错误,使用的是“传统的”MVC应用程序(不是新的。net核心/ vNext应用程序)。

Turns out this error can be a complete red herring.

事实证明,这个错误完全是在转移注意力。

Make sure:

确保:

  • You haven't got any other errors at all
  • 你没有任何其他错误
  • You've checked the output window for any errors that don't show in the 'Output' window.
  • 您已经检查了输出窗口中没有显示在“输出”窗口中的错误。
  • Make sure you don't have any conflicting references
  • 确保你没有任何相互冲突的引用

In my case I had a typescript error that was causing an error and for some reason triggering this weird 'red herring' dynamic error too.

在我的例子中,我有一个导致错误的打字稿错误,出于某种原因也触发了这个奇怪的“红鲱鱼”动态错误。

不能定义使用“dynamic”的类或成员,因为编译器需要类型为“system . run - time. compiler services . dynamicattribute”

My fix was to go into the .csproj file and update the typescript tools version to 1.8 (need to unload project and edit by hand). As I said this is unrelated to the error, but I mention the specifics because someone else may end up with this same problem.

我的修改是进入.csproj文件并将打字稿工具版本更新为1.8(需要手动卸载项目和编辑)。正如我说的,这与错误无关,但我提到了细节,因为其他人可能最终会遇到同样的问题。

I believe that 1.7 didn't accept 'None' for the typescript module system whereas 1.8 does, hence the error.

我认为1.7不接受打字稿模块系统的'None',而1.8接受'None',因此出现了错误。

#3


5  

Adding a reference to System.Dynamic.Runtime did it for me.

添加对System.Dynamic的引用。运行时为我做的。

#4


4  

I had this same issue, but none of the answers here solved it, but did point me in the right direction. I think I didn't update the .NET version on my machine to the newer one. After installing it, I rolled back the targeted framework (as was suggested), retargeted the newer framework, and did a few extra things also:

我也遇到过同样的问题,但是没有一个答案可以解决这个问题,但是我确实找到了正确的方向。我想我没有更新我机器上的。net版本到更新的版本。安装之后,我回滚了目标框架(正如建议的那样),重新定位了新框架,还做了一些额外的事情:

  1. Reinstalled ALL packages by running this in the package manager:

    通过在包管理器中运行这个来重新安装所有包:

    update-package -reinstall

    更新包安装

I also compared my project to one that was working for 4.5 and did this:

我还将我的项目与一个4.5的项目进行了比较,并这样做了:

  1. Opened my project file and removed all "BCL" related elements.
  2. 打开我的项目文件并删除所有的“BCL”相关元素。
  3. Uninstalled all "BCL" packages in the NuGet package manager for the project (guess it's not needed moving to 4.5+...?)
  4. 在项目的NuGet包管理器中卸载所有的“BCL”包(猜测不需要迁移到4.5+…?)
  5. Removed an old package version of System.Net.Http, which did not get updated for some reason (see web.config - versions should show oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0").
  6. 删除了一个旧的软件包版本的System.Net。Http,由于某些原因而没有更新(参见web)。配置-版本应该显示旧版本="0.0.0 -4.0.0 "新版本="4.0.0 ")。
  7. Have to restart VS.
  8. 必须重启VS。
  9. Rebuild solution.
  10. 重建方案。
  11. Error is now gone. ;)
  12. 错误是现在不见了。,)

One other thing I did to resolve some other errors was to clear the component cache by deleting all files in here:

我解决其他一些错误的另一件事是通过删除这里的所有文件来清除组件缓存:

C:\Users\{USERNAME}\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache\

微软当地C:\Users\ { USERNAME } \ AppData \ \ \ VisualStudio \ 14.0 \ ComponentModelCache \

[rant] Wasted a whole day with all this. Thanks to MS for stealing one more day of my life fixing senseless issues that should never be. Every time I upgrade I always get a wonderful surprise, and a lovely game of fix the red herring. Would it not hurt to detect these conflicts for those upgrading old projects? Perhaps better error traces when things go wrong? I doubt it would be that difficult. Perhaps even something like AsmSpy, but more advanced, built in to VS? [/rant]

这一切都浪费了一整天。感谢MS,她又偷走了我生命中的一天,帮我解决了一些本不应该发生的毫无意义的问题。每次升级,我总能得到一个美妙的惊喜,和一个可爱的游戏修复转移注意力。对于那些升级旧项目的人来说,发现这些冲突不是件坏事吗?当事情出错时,也许更好的错误跟踪?我怀疑这有多难。甚至可能是像AsmSpy这样更先进的,内置到VS中?[/咆哮]

#5


0  

A little bit later but anyway for those who still meet this problem. My solution was to correct the version of MVC in web.config under Views folder. E.g. the project referenced MVC assembly version 5.2.2.0 but in the Views/web.config file was version 5.2.4.0 (see image).

稍微晚一点,但是对于那些仍然遇到这个问题的人来说。我的解决方案是纠正web中的MVC版本。配置视图文件夹下。例如,项目引用了MVC组装版本5.2.2.0,但是在视图/web中。配置文件是5.2.4.0版本(见图)。

Image

图像

#1


15  

I had a similar error on a project I was trying to migrate. Try re-targeting the framework of the project back a version or two, and once you find a target version where you do not get the error, re-target back to the version you originally had trouble with.

我试图迁移的一个项目也有类似的错误。尝试将项目的框架重新定位为一个或两个版本,一旦你找到了一个目标版本,你就不会得到错误,重新回到原来的版本。

I was getting the same error on a website project targeted for 4.6.2 that was referencing some older libraries, re-targeted it back to 4.5.1 and that resolved the error. I immediately re-targeted back to 4.6.2 and did not encounter the error again.

我在一个针对4.6.2的网站项目中得到了同样的错误,该项目引用了一些旧的库,将其重新定位到4.5.1,从而解决了错误。我立即重新定位到4.6.2,没有再次遇到错误。

#2


8  

I got this error suddenly a couple days after updating to VS2015.3 using 'traditional' MVC app (not new .NET Core / vNext app).

我在更新到VS2015.3的几天后突然出现了这个错误,使用的是“传统的”MVC应用程序(不是新的。net核心/ vNext应用程序)。

Turns out this error can be a complete red herring.

事实证明,这个错误完全是在转移注意力。

Make sure:

确保:

  • You haven't got any other errors at all
  • 你没有任何其他错误
  • You've checked the output window for any errors that don't show in the 'Output' window.
  • 您已经检查了输出窗口中没有显示在“输出”窗口中的错误。
  • Make sure you don't have any conflicting references
  • 确保你没有任何相互冲突的引用

In my case I had a typescript error that was causing an error and for some reason triggering this weird 'red herring' dynamic error too.

在我的例子中,我有一个导致错误的打字稿错误,出于某种原因也触发了这个奇怪的“红鲱鱼”动态错误。

不能定义使用“dynamic”的类或成员,因为编译器需要类型为“system . run - time. compiler services . dynamicattribute”

My fix was to go into the .csproj file and update the typescript tools version to 1.8 (need to unload project and edit by hand). As I said this is unrelated to the error, but I mention the specifics because someone else may end up with this same problem.

我的修改是进入.csproj文件并将打字稿工具版本更新为1.8(需要手动卸载项目和编辑)。正如我说的,这与错误无关,但我提到了细节,因为其他人可能最终会遇到同样的问题。

I believe that 1.7 didn't accept 'None' for the typescript module system whereas 1.8 does, hence the error.

我认为1.7不接受打字稿模块系统的'None',而1.8接受'None',因此出现了错误。

#3


5  

Adding a reference to System.Dynamic.Runtime did it for me.

添加对System.Dynamic的引用。运行时为我做的。

#4


4  

I had this same issue, but none of the answers here solved it, but did point me in the right direction. I think I didn't update the .NET version on my machine to the newer one. After installing it, I rolled back the targeted framework (as was suggested), retargeted the newer framework, and did a few extra things also:

我也遇到过同样的问题,但是没有一个答案可以解决这个问题,但是我确实找到了正确的方向。我想我没有更新我机器上的。net版本到更新的版本。安装之后,我回滚了目标框架(正如建议的那样),重新定位了新框架,还做了一些额外的事情:

  1. Reinstalled ALL packages by running this in the package manager:

    通过在包管理器中运行这个来重新安装所有包:

    update-package -reinstall

    更新包安装

I also compared my project to one that was working for 4.5 and did this:

我还将我的项目与一个4.5的项目进行了比较,并这样做了:

  1. Opened my project file and removed all "BCL" related elements.
  2. 打开我的项目文件并删除所有的“BCL”相关元素。
  3. Uninstalled all "BCL" packages in the NuGet package manager for the project (guess it's not needed moving to 4.5+...?)
  4. 在项目的NuGet包管理器中卸载所有的“BCL”包(猜测不需要迁移到4.5+…?)
  5. Removed an old package version of System.Net.Http, which did not get updated for some reason (see web.config - versions should show oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0").
  6. 删除了一个旧的软件包版本的System.Net。Http,由于某些原因而没有更新(参见web)。配置-版本应该显示旧版本="0.0.0 -4.0.0 "新版本="4.0.0 ")。
  7. Have to restart VS.
  8. 必须重启VS。
  9. Rebuild solution.
  10. 重建方案。
  11. Error is now gone. ;)
  12. 错误是现在不见了。,)

One other thing I did to resolve some other errors was to clear the component cache by deleting all files in here:

我解决其他一些错误的另一件事是通过删除这里的所有文件来清除组件缓存:

C:\Users\{USERNAME}\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache\

微软当地C:\Users\ { USERNAME } \ AppData \ \ \ VisualStudio \ 14.0 \ ComponentModelCache \

[rant] Wasted a whole day with all this. Thanks to MS for stealing one more day of my life fixing senseless issues that should never be. Every time I upgrade I always get a wonderful surprise, and a lovely game of fix the red herring. Would it not hurt to detect these conflicts for those upgrading old projects? Perhaps better error traces when things go wrong? I doubt it would be that difficult. Perhaps even something like AsmSpy, but more advanced, built in to VS? [/rant]

这一切都浪费了一整天。感谢MS,她又偷走了我生命中的一天,帮我解决了一些本不应该发生的毫无意义的问题。每次升级,我总能得到一个美妙的惊喜,和一个可爱的游戏修复转移注意力。对于那些升级旧项目的人来说,发现这些冲突不是件坏事吗?当事情出错时,也许更好的错误跟踪?我怀疑这有多难。甚至可能是像AsmSpy这样更先进的,内置到VS中?[/咆哮]

#5


0  

A little bit later but anyway for those who still meet this problem. My solution was to correct the version of MVC in web.config under Views folder. E.g. the project referenced MVC assembly version 5.2.2.0 but in the Views/web.config file was version 5.2.4.0 (see image).

稍微晚一点,但是对于那些仍然遇到这个问题的人来说。我的解决方案是纠正web中的MVC版本。配置视图文件夹下。例如,项目引用了MVC组装版本5.2.2.0,但是在视图/web中。配置文件是5.2.4.0版本(见图)。

Image

图像