无法加载文件或程序集'Microsoft.Data.Service'或其某个依赖项。系统找不到指定的文件。

3
我刚刚换了电脑,我的一个项目无法正常运行并抛出标题中的错误(您也可以在下面找到完整的错误消息)。它显然正在寻找错误的位置,但此时我不确定该改变什么。请给予建议。
一些需要注意的事实:
- 我没有更改源代码中的任何行。 - 它在新的生产服务器上工作正常,该服务器由VSTS部署。 - 我正在使用IISExpress运行它。 - 我正在使用Visual Studio 2015 v14.0.25431.01 Update 3。 - 与上一台计算机相比,这台计算机的主要区别是它安装了Visual Studio 2017 RC。(我不认为这会引起任何问题,但谁知道呢)
程序和功能:
以下应用程序存在:
- WCF Data Services 5.6.3工具
Bin目录:
以下文件存在:
- Microsoft.Data.Edm.dll - Microsoft.Data.OData.dll - Microsoft.Data.Services.Client.dll - Microsoft.Data.Services.dll
DataService.svc(完整)
<%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, Microsoft.Data.Services, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Service="Company.Project.Services.DataService" %>

Web.Config (partial)

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Data.Services" publicKeyToken="31bf3856ad364e35" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

错误页面

应用程序'/'中的服务器错误。

无法加载文件或程序集'Microsoft.Data.Services,Version=5.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35'或其一个依赖项。系统找不到指定的文件。

描述:当前Web请求执行期间发生未处理异常。请查看堆栈跟踪以获取有关错误的更多信息以及代码中出现位置。

异常详细信息:System.IO.FileNotFoundException:无法加载文件或程序集'Microsoft.Data.Services,Version=5.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35'或其一个依赖项。系统找不到指定的文件。

源错误:

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.

程序集加载跟踪:以下信息可能有助于确定为什么无法加载程序集 'Microsoft.Data.Services, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'。

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.Data.Services, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Source/github/company/repository/project/HubServices/
LOG: Initial PrivatePath = C:\Source\github\company\repository\project\HubServices\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Source\github\company\repository\project\HubServices\web.config
LOG: Using host configuration file: C:\Users\user\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: 5.0.0.0 redirected to 5.7.0.0.
LOG: Post-policy reference: Microsoft.Data.Services, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

堆栈跟踪:

[FileNotFoundException: Could not load file or assembly 'Microsoft.Data.Services, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]

[FileNotFoundException: Could not load file or assembly 'Microsoft.Data.Services, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +70
   System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +40
   System.Type.GetType(String typeName, Boolean throwOnError) +34
   System.ServiceModel.Activation.ServiceParser.GetType(String typeName) +55
   System.ServiceModel.Activation.ServiceParser.GetCompiledType(Assembly compiledAssembly) +76
   System.ServiceModel.Activation.ServiceParser.CreateParseString(Assembly compiledAssembly) +38
   System.ServiceModel.Activation.ServiceBuildProvider.GetCustomString(CompilerResults results) +33
   System.Web.Compilation.BuildProvider.CreateBuildResult(CompilerResults results) +182
   System.Web.Compilation.BuildProvider.GetBuildResult(CompilerResults results) +16
   System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +10098689
   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +294
   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +103
   System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate) +82
   System.Web.Compilation.BuildManager.GetCompiledCustomString(String virtualPath) +31
   System.ServiceModel.HostingManager.GetCompiledCustomString(String normalizedVirtualPath) +163
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +201
   System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +52
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +641

[ServiceActivationException: The service '/DataService.svc' cannot be activated due to an exception during compilation.  The exception message is: Could not load file or assembly 'Microsoft.Data.Services, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +481507
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +174
   System.ServiceModel.Activation.ServiceHttpHandler.EndProcessRequest(IAsyncResult result) +11
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129
1个回答

1
我不得不重新打开那个项目,发现程序集没有在加载的模块中。我检查了输出目录,发现它被设置为bin\{Configuration},将其改为bin后问题得到解决。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接