无法加载文件或程序集&System; ServiceModel,Version = 4.0.0.0

时间:2017-11-07 20:51:35

标签: c# asp.net .net asp.net-web-api

我最近在VS 2017上的WebAPI项目中开始出现此错误。如果我在另一台机器上运行相同的项目,它可以正常工作。我尝试重新安装VS 2017,重新安装.net 4.0和4.5。我也尝试将项目目标更改为4.7,其中没有任何工作。这是一个类似的问题,但我没有运行.net core 2.0(ASP.NET Core 2.0 Could not load file or assembly System.ServiceModel)任何帮助将不胜感激。

我也尝试将此DLL添加到项目中并通过webconfig添加它但没有改变任何内容。

DLL在我的系统上 - > C:\的Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ System.ServiceModel.dll

  

无法加载文件或程序集&System; ServiceModel,Version = 4.0.0.0,   Culture = neutral,PublicKeyToken = b77a5c561934e089'或其中一个   依赖。该模块应该包含一个程序集清单。

     

描述:执行期间发生了未处理的异常   当前的网络请求。请查看堆栈跟踪了解更多信息   有关错误的信息以及它在代码中的起源。

     

异常详细信息:System.BadImageFormatException:无法加载文件   或汇编&System; ServiceModel,Version = 4.0.0.0,Culture = neutral,   公钥= b77a5c561934e089'或其中一个依赖项。该   模块应该包含一个程序集清单。

     

来源错误:

     

执行期间生成了未处理的异常   当前的网络请求。有关的来源和位置的信息   可以使用下面的异常堆栈跟踪来识别异常。

     

装配加载跟踪:以下信息可能对您有所帮助   确定程序集&System; ServiceModel,Version = 4.0.0.0的原因,   Culture = neutral,PublicKeyToken = b77a5c561934e089'无法加载。

     

装配管理器从以下位置加载:   C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ clr.dll正在运行   可执行文件C:\ Program Files(x86)\ IIS Express \ iisexpress.exe   ---详细的错误日志如下。

     

===预绑定状态信息=== LOG:DisplayName = System.ServiceModel,Version = 4.0.0.0,Culture = neutral,   PublicKeyToken = b77a5c561934e089(完全指定)LOG:Appbase =   file:/// C:/ Users / Michael / Desktop / Project / API / LOG:   初始PrivatePath = C:\ Users \ Michael \ Desktop \ Project \ API \ bin调用程序集:(未知)。   ===日志:此绑定在默认加载上下文中启动。日志:使用应用程序配置文件:C:\ Users \ Michael \ Desktop \ Project \ API \ web.config日志:使用主机配置文件:   C:\ Users \ Michael \ Documents \ IISExpress \ config \ aspnet.config日志:使用   来自的机器配置文件   C:\ WINDOWS \ Microsoft.NET \框架\ v4.0.30319 \ CONFIG \ machine.config中。   日志:后策略引用:System.ServiceModel,Version = 4.0.0.0,   Culture = neutral,PublicKeyToken = b77a5c561934e089

     

堆栈追踪:

     

[BadImageFormatException:无法加载文件或程序集   ' System.ServiceModel,Version = 4.0.0.0,Culture = neutral,   公钥= b77a5c561934e089'或其中一个依赖项。该   模块预计包含一个装配清单。]
  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,   证据集合安全,StackCrawlMark& stackMark,IntPtr   pPrivHostBinder,Boolean forIntrospection)+77
  System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,   证据集合安全,StackCrawlMark& stackMark,布尔   forIntrospection)+21 System.Reflection.Assembly.Load(String   assemblyString)+28
  System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串   assemblyName,布尔starDirective)+38

     

[ConfigurationErrorsException:无法加载文件或程序集   ' System.ServiceModel,Version = 4.0.0.0,Culture = neutral,   公钥= b77a5c561934e089'或其中一个依赖项。该   模块预计包含一个装配清单。]
  System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串   assemblyName,布尔starDirective)+738
  System.Web.Configuration.CompilationSection.LoadAssembly(集信息   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,Version = 4.0.0.0,Culture = neutral,   公钥= b77a5c561934e089'或其中一个依赖项。该   模块预计包含一个装配清单。]
  System.Web.HttpRuntime.FirstRequestInit(HttpContext context)+10042604   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)+95   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest   wr,HttpContext context)+254

1 个答案:

答案 0 :(得分:1)

我最终复制了" C:\ Windows \ Microsoft.NET"来自朋友计算机的目录,之后它运行良好。很奇怪。