'无法加载文件或程序集'System.Web.Helpers'或其依赖项之一

时间:2017-03-12 23:04:05

标签: c# asp.net asp.net-mvc iis

尝试运行ASP.NET项目时出现以下错误。有人可以建议吗?

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

我根据其他答案尝试了以下内容:

4 个答案:

答案 0 :(得分:8)

项目中System.Web.Helpers程序集的引用版本可能与web.config文件中提到的版本不匹配。按照下面提到的步骤。

  1. 检查System.Web.Helpers的引用版本。
  2. 检查Web应用程序根目录下的web.config文件,查看是否有System.Web.Helpers条目,并验证其与引用版本的条目相同。
  3. 检查Web应用程序“Views”文件夹下的web.config文件,查看是否有System.Web.Helpers条目,并验证其与引用版本的条目相同。

答案 1 :(得分:3)

我有这个问题。它是在我向Web窗体项目添加Razor视图时引起的。由于此操作,Visual Studio添加了.Net版本5,并对项目进行了大量其他修改。

我通过进入Solution Explorer > Pending Changes来解决问题。我观察到了一大堆不寻常的文件。我右键单击任何文件并转到Source Control > Undo Pending Changes。我选择了不寻常的文件和Undo Changes,并在重建后修复了它。

我已经看到这些额外的文件在其他时候也被添加(没有明显的)原因。 Visual Studio做的一些乱涂乱画的事情是出于我不清楚的原因。

答案 2 :(得分:1)

在创建新的Razor视图时,我也遇到了这个问题。该项目正在寻找System.Web.Helper和System.Web.WebPages dll的较新版本。我通过编辑web.config并将newVersion从3.0.0.0更改为2.0.0.0解决了此问题。您也可以像我一样从web.config中完全删除它们。

public class Test5 {

    public static void main(String[] args) {

        List<String> list1 = List.of("Tabu", "Gina", "protijayi", "Gini", "Gini","North Calcutta");
        List<String> list2 = List.of("Soudipta", "Gina", "Gina", "upto");
        List<String> list3 = List.of("Soudipta", "Gina", "protijayi", "Tabu","South Calcutta");
        List<List<String>> listres = List.of(list1, list2, list3);
        System.out.println(listres);
/*
 [[Tabu, Gina, protijayi, Gini, Gini, North Calcutta], 
[Soudipta, Gina, Gina, upto],
 [Soudipta, Gina, protijayi, Tabu, South Calcutta]]

 */



        Map<String, List<Long>> FirstKeyThenValue1 = listres.stream().flatMap(
                // mapper

                list -> list.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
                        .entrySet().parallelStream()

        ).collect(Collectors.groupingBy(Entry::getKey, Collectors.mapping(
                // mapper, downstream

                Entry::getValue, Collectors.toList())));
        System.out.println("FirstKeyThenValue1  -> " + FirstKeyThenValue1);
        /*
         {
  upto=[1],
   Soudipta=[1, 1],
    Gina=[1, 2, 1], 
    Tabu=[1, 1],
     North Calcutta=[1], 
     South Calcutta=[1], 
     protijayi=[1, 1], 
     Gini=[2]}
         */

        Map<Long, List<String>> FirstValueThenkey1 = listres.stream().flatMap(
                // mapper

                list -> list.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
                        .entrySet().stream()

        ).collect(

                Collectors.groupingBy(Entry::getValue, Collectors.mapping(


                        Entry::getKey, Collectors.toList()

                ))

        );

        System.out.println(" FirstValueThenkey1 => " + FirstValueThenkey1);

        /*


  {
  1=[Gina, Tabu, North Calcutta, protijayi, upto, Soudipta,
   Soudipta, Gina, Tabu, South Calcutta, protijayi],

 2=[Gini, Gina]
 }
         */





    }// main
}

答案 3 :(得分:0)

在解决方案资源管理器中选择System.Web.Helpers,而不是在属性面板中,将“复制本地”设置更改为“假”。这对我有用。

enter image description here

相关问题