Viewbag.Title错误:编译一个动态的前pression所需的一个或多个类型不能被发现。是否缺少一个参考? [英] Viewbag.Title error: One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?
问题描述
我有一个ASP.NET MVC 5 Web应用程序。在每一个.cshtml视图文件,我得到了以下错误的 Viewbag 的编译一个动态的前pression所需的一个或多个类型不能被发现。是否缺少一个参考?
I have an ASP.NET MVC 5 web application. In every .cshtml view file i get the following error for Viewbag: One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?
我要Microsoft.CSharp.dll和System.Core.dll引用。
I have references to Microsoft.CSharp.dll and System.Core.dll.
下面是我的根web.config文件:
Here is my root web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="***" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="RouteDebugger:Disabled" value="true" />
</appSettings>
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<globalization culture="ro-RO" uiCulture="ro" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.AspNet.Identity.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.AspNet.Identity.EntityFramework" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.0.0" newVersion="3.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
下面是从浏览文件夹中的web.config:
Here is the web.config from the Views folder:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
我可以生成解决方案,以及Web应用程序正常工作,但我不断收到在IDE这个错误,这是非常烦人。我整天都试图解决这个问题。有人可以告诉我怎么解决?
I can build the solution, and the web application works as expected, but I keep getting this error in the IDE and it's very annoying. I spent the entire day trying to solve this issue. Can someone please tell me how to fix it?
当一切正常,当我浏览到定义ViewBag的(F12),我得到的大会System.Web.Mvc.dll程序,v5.1.0.0
从 Recipes.Web \\ BIN \\ System.Web.Mvc.dll程序
并有4 using语句,其中一个是 System.Runtime.CompilerServices
。
When everything works well, when I navigate to definition (F12) of the ViewBag, I get the Assembly System.Web.Mvc.dll, v5.1.0.0
from Recipes.Web\Bin\System.Web.Mvc.dll
and there are 4 using statements, one of which is System.Runtime.CompilerServices
.
当出现错误,当我浏览到定义ViewBag的(F12),我得到同样的大会System.Web.Mvc.dll程序,v5.1.0.0
从 Recipes.Web \\ BIN \\ System.Web.Mvc.dll程序
,但只有3 using语句, System.Runtime.CompilerServices
已经一去不复返了。
When the error appears, when I navigate to definition (F12) of the ViewBag, I get the same Assembly System.Web.Mvc.dll, v5.1.0.0
from Recipes.Web\Bin\System.Web.Mvc.dll
, BUT there are only 3 using statements, System.Runtime.CompilerServices
is gone.
有时,错误不会出现,但是如果我关闭解决方案和Visual Studio然后重新打开解决方案,再次出现错误。我甚至不重建或做其他任何事情。
Sometimes, the error doesn't appear, but if I close the solution and Visual Studio then reopen the solution, the error appears again. I don't even rebuild or do anything else.
为什么会出现这种情况?
Why is this happening?
推荐答案
我不运行的VS 2012以管理员身份的时候有这个问题。
I do not have this problem when running VS 2012 as administrator.
否则,什么工作对我来说:
Otherwise, what worked for me:
-
在根web配置增加了推荐参考纠正装配为编辑节点的子
&LT;&的System.Web GT; &LT;编译调试=&QUOT;真&QUOT; targetFramework =&QUOT; 4.5&QUOT;&GT; &LT;&集会GT; &LT;添加组件= QUOT; System.Core程序,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089&QUOT; /&GT; &LT; /组件&GT;&LT; /编译&GT; &LT; /system.web>
集抄为
属性和 System.Core程序
本地=真微软.CSharp
这篇关于Viewbag.Title错误:编译一个动态的前pression所需的一个或多个类型不能被发现。是否缺少一个参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!