无法加载文件或程序集'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache'或它的一个依赖关系

问题描述:

我正在研究与TFS交互的Web应用程序。当我将应用程序上传到Windows Azure云时,我收到了此错误消息。无法加载文件或程序集'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache'或它的一个依赖关系

感谢您的意见,以解决此问题。

粘贴下面是我收到

Server Error in '/' Application. 
-------------------------------------------------------------------------------- 


Could not load file or assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' or one of its dependencies. An attempt was made to load a program with an incorrect format. 
    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.BadImageFormatException: Could not load file or assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' or one of its dependencies. An attempt was made to load a program with an incorrect format. 

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 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' could not be loaded. 



WRN: Assembly binding logging is turned OFF. 
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. 
Note: There is some performance penalty associated with assembly bind failure logging. 
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. 



Stack Trace: 



[BadImageFormatException: Could not load file or assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' or one of its dependencies. An attempt was made to load a program with an incorrect format.] 
    System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 
    System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +567 
    System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +192 
    System.Reflection.Assembly.Load(String assemblyString) +35 
    System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +123 

[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' or one of its dependencies. An attempt was made to load a program with an incorrect format.] 
    System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11568240 
    System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +485 
    System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +79 
    System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +337 
    System.Web.Compilation.BuildManager.CallPreStartInitMethods() +280 
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1167 

[HttpException (0x80004005): Could not load file or assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' or one of its dependencies. An attempt was made to load a program with an incorrect format.] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11700976 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4869205 




-------------------------------------------------------------------------------- 
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272 

这是因为,你的项目正试图在64位环境中使用32位的DLL(蔚蓝)

为了解决这类问题,创建一个启动脚本

复制下面的启动脚本到一个文本文件,下面给出的命令,保存为“setup.cmd”。 然后包括这个文件到您的Web角色项目,将“复制本地” =真 然后打开给定的启动命令下面的ServiceDefinition.csdef中webrole标签内

<webrole > --your webrole 
    <Startup> 
       <Task commandLine="setup.cmd" executionContext="elevated" /> 
      </Startup> 
</webrole > 

启动脚本粘贴如下:

%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.enable32BitAppOnWin64:"True" /commit:apphost 
+1

此处也确认,运行脚本可解决问题。在ASP.NET应用启动时执行.cmd的任何方式? – AlexVPerl

+9

在应用程序池中,单击“高级设置”,然后将“启用32位应用程序”设置为true。重新启动应用程序池。 – Jeppen

BadImageFormat异常几乎总是32位的dll试图加载了一个64位的DLL或DLL或可执行之间的问题加载为64位的错误消息程序集,但它包含32位功能或资源。

尝试编译应用程序到x86或反之亦然,让我知道如何工作的

+0

事实上,我已经选择了平台“任何CPU”,平台的目标是“任何CPU”选项的项目属性。这是你的意思吗 ? – Millar

+0

我也尝试将平台目标设置为x86,但仍然出现同样的错误,一旦我部署到Azure – Millar

+0

这对我有效。谢谢 – Jeppen

我解决了这个问题,通过从我的asp.net web项目的bin文件夹中删除相应的DLL。

感谢和问候,

+1

请您的答案更详细。例如一个示例代码。 – Luv

+8

似乎这个答案是清晰的 - “从DLL文件夹中删除DLL” - 为我工作,没有示例代码等需要 –

+3

如果BIN文件夹中的文件与服务器上安装的内容相冲突,可能会导致问题。如果TFS dll已经在服务器上,则不需要bin部署dll。在我的情况下,这是真的,并从垃圾箱删除他们解决了这个问题。 –

我通过设置在该网站使用的应用程序池的Advanced SettingsEnable 32-Bit applications选项True解决了这个。

+0

谢谢。我尝试了很多解决方案,但这对我有用。 – SeeTheC