• 未能加载文件或程序集''file:///D:/Program Files (x86)/ArcGIS/DeveloperKit10.0/DotNet/ESRI.ArcGIS.ADF.Local.dll'' 或它的某一个依赖项。试图加载格式不正确的程序。


    阅读:http://www.cnblogs.com/hans_gis/archive/2011/07/22/2114013.html

    转载:http://resources.arcgis.com/zh-cn/content/kbase?fa=articleShow&d=37879

    Technical Article   Error:  ArcGIS Engine Controls fail to build using Visual Studio 2010 on a 64-bit OS

    Article ID: 37879
    Software:  ArcGIS Engine Developer Kit 10
    Platforms:  Windows 2003Server, 2008Server, Win 7

     

      

     

    Error Message

    When building ArcGIS Engine Controls-based applications on a supported 64-bit Operating System (OS) targeting the Microsoft .NET 3.5 framework in Visual Studio 2010, the following error may occur:
       当在64位操作系统上,Vs2010中编译AE控件程序,目标平台.net3.5,可能出现如下错误:
    "Could not load file or assembly 'file:///C:/Program Files (x86)/ArcGIS/DeveloperKit10.0/DotNet/ESRI.ArcGIS.3DAnalyst.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    Line 162, position 5. C:\temp\Projects\MyArcGISControlApp\Form1.resx"

     The error message may differ from the above error message depending on how the project is set up, what assemblies are referenced, and the install location of the ArcObjects .NET SDK on the machine being used.

    Microsoft is aware of this problem and has provided the following knowledge base article as a solution to this problem:
    Article ID: 2028833: "MSBuild 4.0 or Visual Studio 2010 may fail to compile a 32-bit application targeted for .Net Framework 3.5, 3.0 or 2.0 on x64 machine."

       微软发现了这个问题,并且在Article ID: 2028833文章中提出了解决方法。

    Cause

    This issue occurs when a Visual Studio project contains a resource file (.resx) that is referencing a 32-bit (x86) assembly and is compiled against .NET 3.5 in Visual Studio 2010. Visual Studio uses an executable called 'ResGen.exe' during the build process. This executable is marked as MSIL (Any CPU) and runs as a 64-bit (x64) process on a 64-bit OS. Since the Esri Controls are 32-bit and marked as such, it attempts to load the 32-bit assembly and fails.

      问题发生在Vs2010中, vs项目包含一个.resx文件引用了一个32位程序集 并且(compiled against)是用.net3.5编译的。vs在创建过程中使用一个称作'ResGen.exe'的可执行程序。这个可执行被标记为MSIL(Any CPU)并作为一个64位进程运行在64bit系统上。当Esri的32bit控件被标记为64位时,ResGen.exe试图加载32位程序集结果报错。

    Solution or Workaround

    The instructions provided in the Microsoft article (Article ID: 2028833) are sufficient to correct the problem. It involves changing the CorFlags section of the header of the executable to force it to run as a 32-bit application.
      引言中提供的微软的文章可以解决这个问题,他需要改变可执行程序头的CorFlags部分强制可执行程序以32位方式运行。
    To understand what this is doing refer to the following scenario. If a developer creates .NET executable and sets the target platform to 'Any CPU', this essentially creates a header file in the executable that tells the Common Language Runtime (CLR) to load and run the executable in the same process space it was run in. When running the executable on a 32-bit machine, it would run as a 32-bit application; and on a 64-bit machine, it would run as a 64-bit application.
      为了理解都发生了什么参考下面的脚本。如果开发者创建了一个.net可执行文件,并设置目标平台Any CPU,必不可少的创建了一个头文件在可执行文件中来告诉CLR来加载和运行在同样的程序空间。当运行在32位的机器,他以32位程序运行,在64位以64bit运行。
    When creating an executable that references assemblies of a particular process's space, such as an ArcGIS Engine ArcObjects application, the process space should always be set to x86. Because the ArcObjects’ assemblies are only 32-bit, this forces the executable to always run as a 32-bit process regardless of the target machine and allows it to load the assemblies that are only 32-bit.
      当创建一个可执行文件引用一个特定程序空间的程序集,比如AE或者AO,进程空间应该一直被设置为X86,因为AO程序集只是32位的,这要求可执行程序一直以32位运行而不管目标机器,允许可执行程序加载的程序集只能是32位的。
    The workaround uses CorFlags.exe to change the header file of ResGen.exe so that it runs as a 32-bit application and allows it to correctly load the Esri 32-bit assemblies.
      运用CorFlags改变ResGen的头文件,这样就可以以32位的方式运行,并且保证了正确的加载Esri32bit程序集。
    The steps detailed in the Microsoft article (Article ID: 2028833) can be automated within the project itself. For this to work correctly Visual Studio must and should be run as Administrator.
      注意以管理员方式运行。
    The following solution adds a custom build step to the Visual Studio project that temporarily changes the CorFlags section of the 'Resgen.exe' header file, so that the application compiles and then changes it back when finished.
      接下来的方案给VS项目增加自定义build步骤,临时改变‘Resgen.exe’的头文件的CorFlags部分,这样程序编译成功后改回原来的头文件。
     The following instructions will make changes to essential Microsoft Visual Studio files and may potentially contain a security risk. Continue at your own risk!

    These instructions are an adaptation of a solution provided by Microsoft. Esri is not responsible for any damage that this may cause to your Visual Studio install. It is recommended that you back up the <install location>\Microsoft SDKs\Windows\v7.0A\bin\ResGen.exe before proceeding.
    警告: 备份<install location>\Microsoft SDKS...
    1. In Visual Studio 2010 right-click on the project and select 'Unload Project'.
    2. Right-click the project again and select 'Edit <project name>'. The XML for the project file can be edited from this location.
    3. Add the following XML anywhere in the project. Preferably at the end, just above the closing '</Project>' tag, where it is easy to find.
      关闭项目。右击xxx.csproj,用记事本打开。将下面的XML文本粘贴到 '</Project>' tag结束标签之前,保存,重新加载。
    <!--
    Workaround for VS2010 .NET 3.5 application referencing x86 assembly in resx file on 64-bit OS
    http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/e5900710-9849-4d10-aa28-48b734d06bf2
    -->
    <PropertyGroup>
    <ForceResGen32Bit Condition="'$(MSBuildToolsVersion)'=='4.0' And '$(PROCESSOR_ARCHITEW6432)'!='' And '$(TargetingClr2Framework)'=='true' And '$(PlatformTarget)'=='x86'">true</ForceResGen32Bit>
    </PropertyGroup>
    <Target Name="BeforeResGen" Condition="'$(ForceResGen32Bit)' == 'true'">
    <PropertyGroup>
    <ResGenSdkToolsPath>$(IntermediateOutputPath)ResGenForced32Bit\</ResGenSdkToolsPath>
    </PropertyGroup> <!-- Copy resgen.exe to intermediate working directory for UAC settings -->
    <Copy SourceFiles="$(TargetFrameworkSDKToolsDirectory)ResGen.exe"
    DestinationFiles="$(ResGenSdkToolsPath)ResGen.exe" /> <!-- corflags.exe resgen.exe /32BIT+ /Force-->
    <Exec WorkingDirectory="$(ResGenSdkToolsPath)"
    Command="&quot;$(TargetFrameworkSDKToolsDirectory)corflags.exe&quot; ResGen.exe /32BIT+ /Force" />
    <!-- GenerateResource Task parameters
    Using the non-64bit Tracker.exe and indicate resgen.exe has been forced to x86 -->
    <PropertyGroup>
    <ResGenTrackerSdkPath>$(SDK40ToolsPath)</ResGenTrackerSdkPath>
    <ResGenToolArchitecture>Managed32Bit</ResGenToolArchitecture>
    <CacheTargetFrameworkSDKToolsDirectory>$(TargetFrameworkSDKToolsDirectory)</CacheTargetFrameworkSDKToolsDirectory>
    <TargetFrameworkSDKToolsDirectory>$(ResGenSdkToolsPath)</TargetFrameworkSDKToolsDirectory>
    </PropertyGroup>
    </Target>
    <Target Name="AfterResGen" Condition="'$(ForceResGen32Bit)' == 'true'">
    <PropertyGroup>
    <TargetFrameworkSDKToolsDirectory>$(CacheTargetFrameworkSDKToolsDirectory)</TargetFrameworkSDKToolsDirectory>
    </PropertyGroup>
    <RemoveDir Directories="$(ResGenSdkToolsPath)" Condition="Exists('$(ResGenSdkToolsPath)')" />
    </Target>

       4. Right-click the project and select 'Reload Project'.

       5. Build the project.

    Related Information

    Created: 6/15/2010
    Last Modified: 7/2/2010

     

    文章未经说明均属原创,学习笔记可能有大段的引用,一般会注明参考文献。 欢迎大家留言交流,转载请注明出处。
  • 相关阅读:
    java编程思想-接口总结
    java编程思想-复用类总结
    oracle dos命令
    循环插入记录,id每次加1
    android studio 的Error:No such property: packageApplicationTask for class: com.android.build.gradle.internal.variant.ApkVariantOutputData解决方法
    AngularJS 初学笔记(理论基础)
    在Linux添加PYTHONPATH方法以及修改环境变量方法
    基于Redis的三种分布式爬虫策略
    函数指针 如:void (*oper)(ChainBinTreee *p)
    typedef struct 使用
  • 原文地址:https://www.cnblogs.com/yhlx125/p/3010520.html
Copyright © 2020-2023  润新知