2017-09-25 133 views
0

我經歷了許多答案,但之前回答我不幸運找到我的問題的解決方案。這無法加載文件或程序集'System.Web.WebPages.Razor,版本= 3.0.0.0,文化=中立,PublicKeyToken = 31bf3856ad364e35'和我使用的許多其他人。無法加載文件或程序集'System.Web.WebPages.Razor,版本= 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'ASP.NET MVC

****以下是運行時錯誤:****

無法加載文件或程序集「System.Web.WebPages.Razor,版本= 3.0.0.0,文化=中性公鑰= 31bf3856ad364e35 '或它的一個依賴關係。定位的程序集清單定義與程序集引用不匹配。 (從HRESULT異常:0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

異常詳細信息:System.IO.FileLoadException:無法加載文件或程序集「System.Web.WebPages.Razor,版本= 3.0.0.0,文化=中性公鑰= 31bf3856ad364e35'或其依賴項之一。定位的程序集清單定義與程序集引用不匹配。 (從HRESULT異常:0x80131040)

源錯誤:在當前web請求的執行過程中生成

未處理的異常。關於異常的來源和位置的信息可以使用下面的異常堆棧跟蹤來標識。

程序集加載跟蹤:以下信息可以幫助確定程序集「System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35」爲什麼無法加載。

===預綁定狀態信息=== LOG:DisplayName的= System.Web.WebPages.Razor,版本= 3.0.0.0,文化=中性公鑰= 31bf3856ad364e35 (完全指定的) LOG:應用平臺=文件:/// C:/ menupoly /阿卜杜拉/ MEN1/MenuSnaps/ LOG:初始PrivatePath = C:\ menupoly \阿卜杜拉\ MEN1 \ MenuSnaps \ BIN

調用組件:Microsoft.Web.Helpers,版= 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35。

LOG:此綁定在默認加載上下文中啓動。 日誌:使用應用程序配置文件:C:\ menupoly \ abdulla \ men1 \ MenuSnaps \ web.config LOG:使用主機配置文件:C:\ Users \ user \ Documents \ IISExpress \ config \ aspnet.config LOG:使用機器配置文件從C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ config \ machine.config。 日誌:後策略引用:System.Web.WebPages.Razor,版本= 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35 日誌:嘗試下載新的URL文件:/// C:/ Users/user/AppData/Local/Temp/Temporary ASP.NET Files/root/c0c49273/dff4168/System.Web.WebPages.Razor.DLL。 日誌:嘗試下載新的URL文件:/// C:/ Users/user/AppData/Local/Temp/Temporary ASP.NET Files/root/c0c49273/dff4168/System.Web.WebPages.Razor/System.Web。 WebPages.Razor.DLL。 日誌:試圖下載新的URL文件:/// C:/menupoly/abdulla/men1/MenuSnaps/bin/System.Web.WebPages.Razor.DLL。 WRN:比較彙編名稱導致不匹配:主版本 ERR:未完成彙編設置(hr = 0x80131040)。探測終止。

堆棧跟蹤:

[FileLoadException:未能加載文件或程序集「System.Web.WebPages.Razor,版本= 3.0.0。0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依賴項之一。定位的程序集清單定義與程序集引用不匹配。 (從HRESULT異常:0x80131040)] Microsoft.Web.Helpers.PreApplicationStartCode.Start()0

[InvalidOperationException異常:本申請前的啓動初始化方法開始於式Microsoft.Web.Helpers.PreApplicationStartCode拋出異常與以下錯誤消息:無法加載文件或程序集「System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35」或其某個依賴項。定位的程序集清單定義與程序集引用不匹配。 (從HRESULT異常:0x80131040)。] System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection的1 methods, Func 1個setHostingEnvironmentCultures)613個 System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1方法)141 的System.Web。 Compilation.BuildManager.CallPreStartInitMethods(字符串preStartInitListPath,布爾& isRefAssemblyLoaded)102 System.Web.Compilation.BuildManager.ExecutePreAppStart()157 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager AppManager的,IApplicationHost APPHOST,IConfigMapPathFactory configMapPathFactory,HostingEnvironmentParameters hostingParameters,PolicyLevel policyLevel,Exception appDomainCreationException)+531

[HttpException(0x80004005):預應用程序啓動初始化方法啓動類型Microsoft.Web.Helpers.PreApplicationStartCode拋出一個異常,並顯示以下錯誤消息:無法加載文件或程序集'System.Web.WebPages.Razor,版本= 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依賴項之一。定位的程序集清單定義與程序集引用不匹配。 (從HRESULT異常:0x80131040)。] System.Web.HttpRuntime.FirstRequestInit(HttpContext的上下文)9946024 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext的上下文)90 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest WR,HttpContext的上下文)+261

**This is the portion of my Web.Config** 

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebMatrix.WebData" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 

I verified the version of each on Reference are the same as on Web.Config. Please help me. Thank you for your help. 
+0

有時這種類型的錯誤發生在解決方案構建中時出現錯誤。先修復構建錯誤,然後重新啓動IIS。 – yyou

回答

3

你在web.config中,其中提到剃刀2.0此綁定重定向被用來代替剃刀3.0,而你試圖用剃刀3.0組件,它不綁定到任何東西:

<dependentAssembly> 
    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
</dependentAssembly> 

第一個你應該做的事情,更改綁定重定向使用3.0版本而不是:

<dependentAssembly> 
    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
</dependentAssembly> 

還要確保在web.config中存在Views文件夾內的這些配置行:

<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> 

如果還不行工作&您不確定Razor軟件包是否安裝正確,請嘗試使用NuGet Gallery/Package Manager控制檯命令(使用-reinstall開關)重新安裝所需的軟件包,然後執行上述步驟:

Update-Package –reinstall Microsoft.AspNet.WebPages 

Update-Package -reinstall Microsoft.AspNet.Razor 

NB - 該組件結合表明正在使用MVC 4:

<dependentAssembly> 
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
</dependentAssembly> 

我推薦給你的MVC項目升級到5.0.0版本和更新剃刀綁定到3.0版本。0作爲建議在此引用:

How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2 (Microsoft Docs)

類似的問題:

Runtime error: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0

Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0

+0

我嘗試了所有的建議,但沒有幸運。我決定從全新安裝一切,從頭開始也許會有所幫助。謝謝 – user3136941

0

我得到了同樣的錯誤,前幾天。搜索了整整一天後,我找到了解決方案。

可能這會幫助你。

1. Check your Server's Path "C:\Program Files (x86)\Microsoft ASP.NET". 
    Is there any folder named "ASP.NET MVC 4" ? 

2. If not you need to install ASP.NET Framework 4 in your server. 
    (if your project is in Framework 4.0) 
0

當你遇到這種在部署你這不是開發機IIS服務器上的應用程序相關的MVC錯誤的,這是因爲你可能沒有安裝在目標機器上運行時的MVC。

您可以看看服務器的文件夾C:\ Program Files(x86)\ Microsoft ASP.NET \ ASP.NET MVC 4。你應該在幾個文件夾中找到,包括一個「組件」。

如果沒有,您可以從MS網站下載運行時。我想這個可以工作: https://www.microsoft.com/en-us/download/details.aspx?id=30683&751be11f-ede8-5a0c-058c-2ee190a24fa6=True但你必須檢查。 您還應該能夠從Web Platform Installer安裝MVC。

另外,您也可避免安裝運行時,如果你不想或者如果您不能:

爲了使應用程序工作,而對服務器的請求運行時,在「參考」文件夾視覺工作室,你可以選擇所有有問題的程序集,併爲他們每個人,設置爲「真正的」「複製本地」。 你將不得不爲MVC DLL,但可能爲其他幾個,例如:System.Net.Http,System.Net.Http.Formatting.dll,System.Net.Http.WebRequest,System.Web。 Http.dll,System.Web.Http.WebHost.dll等 因此,它可能需要幾次嘗試(幸運的是,您只需在啓動時讀取錯誤消息以獲取「下一個」缺少的DLL的名稱)。

相關問題