我有一个项目设置为x64 (它使用了一些仅64位的Nuget包)。一切运行和部署都很好,但是尝试在包管理器控制台运行EF的enable-migrations
会得到一个System.BadImageFormatException
。完整的例外:
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更容易使用,也是因为它与这个问题无关。
发布于 2017-12-20 01:38:46
正如微软支持所说的:“解决办法是在生成/运行迁移之前切换到AnyCPU或x86,然后切换回来”。
他们还建议:“将模型/迁移重构为一个单独的项目,即AnyCPU”。
发布于 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文件中进行了以下更改/更新:
<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>
在我的情况下,
<PlatformTarget/>
仍设置为x64。
发布于 2018-03-02 10:55:52
转到IIS管理器>查看应用程序池>默认应用程序工具>高级设置...>将32位设置为true
https://stackoverflow.com/questions/23666716
复制相似问题