C# Dynamic Types Break When Upgrading to Visual Studio 2012

▼魔方 西西 提交于 2019-12-11 03:26:10

问题


I have a project that was originally developed using Visual Studio 2010 with .Net 4.0. It is a class library that implements a custom MVC 3 controller and it uses a dynamic type. If I open the project in Visual Studio 2012 RTM, without making any changes to the project, I get the following error on the dynamic types:

One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?

I am also getting another error, which is:

Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember'

They seem to be related issues. I am not sure why Visual Studio 2012 is confused. The Microsoft.CSharp assembly is in the references. If I open the project again in Visual Studio 2010 it compiles just fine. Has anyone come across this issue and know a solution to it?


回答1:


In my case reference to Microsoft.CSharp assembly was missing. I got this error when trying to use JSON.NET, dynamic types and Visual Studio 2012.




回答2:


The answer turned out to be in a warning that was present when compiling in either VS 2010 and 2012. The warning was:

The predefined type 'System.Runtime.CompilerServices.CallSite' is defined in multiple assemblies in the global alias; using definition from '..\IronJS.Core.0.2.0.1\lib\net40\Microsoft.Scripting.Core.dll'

The project used IronJS and it had a a copy of Microsoft.Scripting and Microsoft.Dynamic in its package that were being referenced. I removed these references and referenced the versions in the global assemblies and everything works fine. Not sure why VS 2012 had a problem with this when VS 2010 did not. Or why it caused the obscure errors.



来源:https://stackoverflow.com/questions/12782951/c-sharp-dynamic-types-break-when-upgrading-to-visual-studio-2012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!