首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >启用- x64项目中的迁移获取System.BadImageFormatException

启用- x64项目中的迁移获取System.BadImageFormatException
EN

Stack Overflow用户
提问于 2014-05-15 07:15:57
回答 3查看 7.4K关注 0票数 25

我有一个项目设置为x64 (它使用了一些仅64位的Nuget包)。一切运行和部署都很好,但是尝试在包管理器控制台运行EF的enable-migrations会得到一个System.BadImageFormatException。完整的例外:

代码语言:javascript
复制
PM> enable-migrations
System.BadImageFormatException: Could not load file or assembly  or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.LoadAssembly(String name)
   at System.Data.Entity.Migrations.Design.ToolingFacade.GetContextTypeRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.GetContextType(String contextTypeName)
   at System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String contextTypeName)
   at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)

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].

Could not load file or assembly  or one of its dependencies. An attempt was made to load a program with an incorrect format.

注意:我已经从错误消息中删除了项目名称,这既是为了让google更容易使用,也是因为它与这个问题无关。

EN

回答 3

Stack Overflow用户

发布于 2017-12-20 01:38:46

正如微软支持所说的:“解决办法是在生成/运行迁移之前切换到AnyCPU或x86,然后切换回来”。

他们还建议:“将模型/迁移重构为一个单独的项目,即AnyCPU”。

票数 6
EN

Stack Overflow用户

发布于 2015-08-17 11:42:22

核心问题是围绕着x64。在我的场景中,我尝试使用Azure移动服务Todo参考解决方案。在此解决方案中,有一个服务解决方案和两个前端客户端( Windows 8和Windows Phone )解决方案。

在试验该解决方案时,我添加了离线支持。离线支持实施SQLite,而SQLite要求将解决方案配置为对各自的本机客户端使用x64或ARM。

因此,更改CPU目标以解决SQLite支持,我必须已经修改了服务上的CPU x64,并保存。当我看到我的服务使用x64的错误时,我改回了任何CPU。

这一切导致了..。当我下一次尝试添加迁移时,根据这篇文章中的信息,我的服务.csproj文件被“损坏”了。在我的示例中,我在服务的.csproj文件中进行了以下更改/更新:

代码语言:javascript
复制
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

在我的情况下,

代码语言:javascript
复制
<PlatformTarget/> 

仍设置为x64。

票数 2
EN

Stack Overflow用户

发布于 2018-03-02 10:55:52

转到IIS管理器>查看应用程序池>默认应用程序工具>高级设置...>将32位设置为true

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23666716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档