问题描述
我最近开始在VS 2017上的WebAPI项目上遇到此错误.如果我在另一台计算机上运行相同的项目,则可以正常工作.我尝试过重新安装VS 2017,重新安装.net 4.0和4.5.我还尝试将项目目标更改为4.7,但没有任何效果.这是一个类似的问题,但是我没有运行.net core 2.0(),我们将不胜感激.
I recently started getting this error on my WebAPI project on VS 2017. If I run the same project on another machine it works fine. I have tried reinstalling VS 2017, reinstalling .net 4.0 and 4.5. I also tried changing the project target to 4.7 in which nothing worked. This is a similar issue but I am not running .net core 2.0 (ASP.NET Core 2.0 Could not load file or assembly System.ServiceModel) Any help will be much appreciated.
我还尝试将此DLL添加到项目中,并通过webconfig添加它,但未进行任何更改.
I also tried adding this DLL to the project and adding it via the webconfig but didn't change anything.
DLL在我的系统上-> C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ System.ServiceModel.dll
The DLL is on my system -> C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.ServiceModel.dll
描述:执行以下操作时发生未处理的异常当前的Web请求.请查看堆栈跟踪以获取更多信息有关错误及其在代码中起源的信息.
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.BadImageFormatException:无法加载文件或程序集'System.ServiceModel,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089'或其依赖项之一.这该模块应包含一个程序集清单.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The module was expected to contain an assembly manifest.
源错误:
在执行过程中生成了未处理的异常当前的Web请求.有关原产地和位置的信息可以使用下面的异常堆栈跟踪来识别异常.
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.
装配体负载跟踪:以下信息可能对以下方面有所帮助:确定为什么程序集'System.ServiceModel,Version = 4.0.0.0,Culture = neutral,无法加载PublicKeyToken = b77a5c561934e089'.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' could not be loaded.
装配管理器从以下位置加载:C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ clr.dll在以下目录下运行可执行C:\ Program Files(x86)\ IIS Express \ iisexpress.exe---详细的错误日志如下.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable C:\Program Files (x86)\IIS Express\iisexpress.exe --- A detailed error log follows.
===预绑定状态信息===日志:DisplayName = System.ServiceModel,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089(完全指定)LOG:Appbase =文件:///C:/Users/Michael/Desktop/Project/API/LOG:初始PrivatePath = C:\ Users \ Michael \ Desktop \ Project \ API \ bin调用程序集:(未知).=== LOG:此绑定在默认的加载上下文中启动.日志:使用应用程序配置文件:C:\ Users \ Michael \ Desktop \ Project \ API \ web.config日志:使用主机配置文件:C:\ Users \ Michael \ Documents \ IISExpress \ config \ aspnet.config日志:使用机器配置文件来自C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ config \ machine.config.日志:政策后参考:System.ServiceModel,版本= 4.0.0.0,文化=中性,PublicKeyToken = b77a5c561934e089
=== Pre-bind state information === LOG: DisplayName = System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 (Fully-specified) LOG: Appbase = file:///C:/Users/Michael/Desktop/Project/API/ LOG: Initial PrivatePath = C:\Users\Michael\Desktop\Project\API\bin Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\Michael\Desktop\Project\API\web.config LOG: Using host configuration file: C:\Users\Michael\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
堆栈跟踪:
[BadImageFormatException:无法加载文件或程序集'System.ServiceModel,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089'或其依赖项之一.这该模块应包含一个程序集清单.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName,字符串codeBase,证据程序集安全性,运行时程序集locationHint,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,布尔throwOnFileNotFound,用于自省的布尔值,布尔值hibitSecurityChecks)+0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName,字符串codeBase,证据程序集安全性,运行时程序集locationHint,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,布尔throwOnFileNotFound,用于自省的布尔值,布尔值抑制安全性检查)+36
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyNameassemblyRef,证据assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,布尔throwOnFileNotFound,用于自省的布尔值,布尔值抑制(SecurityChecks)+152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,证据集安全性,StackCrawlMark&stackMark,IntPtrpPrivHostBinder,用于自省的布尔值)+77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,证据集安全性,StackCrawlMark&stackMark,布尔值forIntrospection)+21 System.Reflection.Assembly.Load(字符串assemblyString)+28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串assemblyName,布尔型starDirective)+38
[BadImageFormatException: Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The module was expected to contain an assembly manifest.]
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:无法加载文件或程序集'System.ServiceModel,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089'或其依赖项之一.这该模块应包含一个程序集清单.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串assemblyName,布尔型starDirective)+738
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfoai)+57
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSectioncompConfig)+170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()+92 System.Web.Compilation.BuildManager.CallPreStartInitMethods(字符串preStartInitListPath,布尔值和isRefAssemblyLoaded)+290
System.Web.Compilation.BuildManager.ExecutePreAppStart()+157
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManagerappManager,IApplicationHost,appHost,IConfigMapPathFactoryconfigMapPathFactory,HostingEnvironmentParametershostingParameters,PolicyLevel policyLevel,异常appDomainCreationException)+549
[ConfigurationErrorsException: Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The module was expected to contain an assembly manifest.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +738
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +57
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) +549
[HttpException(0x80004005):无法加载文件或程序集'System.ServiceModel,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089'或其依赖项之一.这该模块应包含一个程序集清单.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext上下文)+10042604System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext上下文)+95System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequestwr,HttpContext上下文)+254
[HttpException (0x80004005): Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The module was expected to contain an assembly manifest.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10042604 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
推荐答案
我最终从朋友计算机上复制了"C:\ Windows \ Microsoft.NET"目录,此后它运行良好.很奇怪.
I ended up copying the "C:\Windows\Microsoft.NET" directory from a friends computer and it worked fine after that. Very strange.
这篇关于无法加载文件或程序集'System.ServiceModel,版本= 4.0.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!