web-dev-qa-db-fra.com

'Impossible de charger le fichier ou l'assemblage' System.Web.Helpers 'ou l'une de ses dépendances

J'obtiens l'erreur de suivi lorsque j'essaie d'exécuter mon projet ASP.NET. Quelqu'un peut-il conseiller?

Could not load file or Assembly 'System.Web.Helpers' or one of its dependencies. The located Assembly's manifest definition does not match the Assembly reference. (Exception from 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. 

Exception Details: System.IO.FileLoadException: Could not load file or Assembly 'System.Web.Helpers' or one of its dependencies. The located Assembly's manifest definition does not match the Assembly reference. (Exception from HRESULT: 0x80131040)

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the Origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the Assembly 'System.Web.Helpers' could not be loaded.


=== Pre-bind state information ===
LOG: DisplayName = System.Web.Helpers
 (Partial)
WRN: Partial binding information was supplied for an Assembly:
WRN: Assembly Name: System.Web.Helpers | Domain ID: 2
WRN: A partial bind occurs when only part of the Assembly display name is provided.
WRN: This might result in the binder loading an incorrect Assembly.
WRN: It is recommended to provide a fully specified textual identity for the Assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.Microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = .../.../
LOG: Initial PrivatePath = \...\WebInterface\bin
Calling Assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: \...\WebInterface\web.config
LOG: Using Host configuration file: \Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based Assembly bind).
LOG: Attempting download of new URL /AppData/Local/Temp/Temporary ASP.NET Files/vs/0418a60d/21ffd41/System.Web.Helpers.DLL.
LOG: Attempting download of new URL /AppData/Local/Temp/Temporary ASP.NET Files/vs/0418a60d/21ffd41/System.Web.Helpers/System.Web.Helpers.DLL.
LOG: Attempting download of new URL .../.../bin/System.Web.Helpers.DLL.
LOG: Using application configuration file: \...\WebInterface\web.config
LOG: Using Host configuration file: \Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 2.0.0.0 redirected to 3.0.0.0.
LOG: Post-policy reference: System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL /AppData/Local/Temp/Temporary ASP.NET Files/vs/0418a60d/21ffd41/System.Web.Helpers.DLL.
LOG: Attempting download of new URL /AppData/Local/Temp/Temporary ASP.NET Files/vs/0418a60d/21ffd41/System.Web.Helpers/System.Web.Helpers.DLL.
LOG: Attempting download of new URL .../.../bin/System.Web.Helpers.DLL.
WRN: Comparing the Assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of Assembly (hr = 0x80131040). Probing terminated.

Stack Trace: 


[FileLoadException: Could not load file or Assembly 'System.Web.Helpers' or one of its dependencies. The located Assembly's manifest definition does not match the Assembly reference. (Exception from HRESULT: 0x80131040)]

[FileLoadException: Could not load file or Assembly 'System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located Assembly's manifest definition does not match the Assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +36
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +21
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: Could not load file or Assembly 'System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located Assembly's manifest definition does not match the Assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +738
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +217
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +92
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +290
   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): Could not load file or Assembly 'System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located Assembly's manifest definition does not match the Assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9963380
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

J'ai essayé ce qui suit sur la base d'autres réponses:

11
user2181948

La version référencée de System.Web.Helpers Assembly dans le projet peut ne pas correspondre à la version mentionnée dans le fichier web.config. Suivez les étapes mentionnées ci-dessous.

  1. Vérifiez la version référencée de System.Web.Helpers.
  2. Vérifiez le fichier web.config sous la racine de l'application Web et voyez s'il y a une entrée pour System.Web.Helpers et vérifiez-la comme celle de la version référencée.
  3. Vérifiez le fichier web.config sous le dossier "Vues" de l'application Web et voyez s'il y a une entrée pour System.Web.Helpers et vérifiez-la comme celle de la version référencée.
9
Pankaj Kapare

J'ai eu ce problème. Cela est dû au fait que j'ai ajouté une vue Razor à un projet Web Forms. En raison de cette action, Visual Studio a ajouté la version .Net 5 et a apporté de nombreuses autres modifications au projet.

J'ai résolu le problème en allant dans Solution Explorer > Pending Changes. J'ai observé un tas de fichiers inhabituels répertoriés. J'ai fait un clic droit sur l'un des fichiers et je suis allé à Source Control > Undo Pending Changes. J'ai sélectionné les fichiers inhabituels et Undo Changes et après une reconstruction, il a été corrigé.

J'ai vu ces fichiers supplémentaires être ajoutés (sans raison apparente) à d'autres moments également. Quelque chose de délirant que Visual Studio fait pour des raisons qui ne me paraissent pas claires.

5
HankCa

J'ai également rencontré ce problème lors de la création d'une nouvelle vue Razor. Le projet recherchait une version plus récente des DLL System.Web.Helper et System.Web.WebPages. J'ai résolu ce problème en modifiant mon web.config et en changeant la nouvelle version de 3.0.0.0 à 2.0.0.0. Vous pouvez également être en mesure de les supprimer entièrement du web.config comme je l'ai fait.

 <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
1
Ben