【问题标题】:Targetting x64 platform with entity framework 4.1 in Visual Studio 2010在 Visual Studio 2010 中使用实体框架 4.1 定位 x64 平台
【发布时间】:2012-11-19 14:02:13
【问题描述】:

我有一个引用 Entity Framework 4.1 的数据库应用程序。在项目的属性窗口中,ConfigurationPlatform 选择选项均被禁用。我不想将此应用程序仅针对 x64 系统。

同一解决方案中还有一些其他项目,它们只有 x86 选项可用作平台。

我不明白为什么我不能专门针对 x64 系统。我的电脑上运行的是 Windows 7 64 位。

关于如何专门针对基于 x64 的系统的任何线索。所有项目都参考 .Net Framework 4。

仅显示“任何 CPU”选项的项目屏幕截图

编辑 1:为什么我需要针对 x64 系统。

实际上,我正在开发的 dll 必须在 Autocad x64 系统中加载。但是当我尝试将 dll 加载到 Autocad 中时,它会拒绝 dll 并出现以下错误

NETLOAD Cannot load assembly. Error details: System.BadImageFormatException: 
Could not load file or assembly 
'file:///D:\RailwayProjects\RelayAnalysis_New\RelayAnalysis_Autocad\bin\Debug\Gl
obalArea.dll' or one of its dependencies. An attempt was made to load a program 
with an incorrect format.
File name: 
'file:///D:\RailwayProjects\RelayAnalysis_New\RelayAnalysis_Autocad\bin\Debug\Gl
obalArea.dll'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String 
codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, 
StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean 
forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName 
assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean 
forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, 
Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm 
hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, 
StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(String fileName)
   at loadmgd()
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].

我强烈怀疑 Autocad x64 拒绝 dll,因为它不是 x64 格式,尽管我在这里可能错了。所以现在我将问题的范围扩大到包括 AutoCAD,因为问题的根源是在 AutoCAD 中加载 dll。我在网上搜索了一下,发现 AutoCAD 对 x32 和 x64 类型非常挑剔。用于开发 Autocad 插件的原生开发环境 AutoCAD.net 也可在 x32 和 x64 类型下单独使用,我认为使用 x32 开发的插件不会在 x64 类型的 Autocad 版本中运行,反之亦然反之亦然。所以,我需要具体说明 Autocad 插件的目标平台

【问题讨论】:

  • 您为什么要这样做?如果您的程序集与平台无关(EntityFramework 也是如此,因为它是纯 IL),它可以在 64 位和 32 位进程中运行。由于 IL 是在代码首次执行时在运行时编译的,因此它的行为就像是为此平台编写的一样。同样,我想知道将平台设置为 x64 会给你带来什么。
  • 我已对问题进行了编辑,以包含我具体定位平台的原因。

标签: visual-studio-2010 entity-framework-4.1 autocad autocad-plugin


【解决方案1】:

在配置管理器中,有一个创建新配置的选项,我们可以在其中选择 x64 作为目标平台。

关于 AutoCAD 2012,它对平台类型非常严格。 64 位 AutoCAD 2012 将接受 "Any CPU"x64 目标插件,但不接受 x86。这与我们可以在 x64 系统上运行 x86 应用程序的约定有些不同。我将所有项目都定位到 x64 并在 AutoCAD 中加载它们而没有任何错误。

所以我的问题解决了。

【讨论】:

  • 这是因为在 Windows 上 64 位处理器可以模拟 32 位处理器(Windows 上的所谓 Windows),但 32 位处理器显然不能模拟 64 位处理器。因此,您可以在 64 位处理器上运行 32 位应用程序。任何 CPU 都适用于纯 IL,因为它是在运行时编译的,具体取决于您使用的架构。在单个程序集中拥有 PInvoke 或混合代码(本机和托管)后,您需要针对特定​​平台对其进行编译。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-24
  • 1970-01-01
  • 2013-01-10
相关资源
最近更新 更多