entity-framework - 尝试在生产环境中运行 EF Code first Migrate.exe 工具失败

标签 entity-framework entity-framework-migrations

我正在使用 EntityFramework 版本 6.1.3。

我将 migrate.exe 从 EntityFramework 版本 6.1.3 包工具文件夹复制到我网站的 bin 文件夹。

我的网站编译并发布到使用 x86 CPU 和目标框架 4.5.1 的生产环境

我运行以下命令:

D:\Sites\MatrixPortal\bin>migrate.exe d:\sites\MatrixPortal\bin\MatrixPortal.BL.dll /startUpDirectory="d:\Sites\MatrixPortal\bin" /startUpConfigurationFile="d:\Sites\MatrixPortal\Web.config"



我收到以下错误:

ERROR: Could not load file or assembly 'd:\sites\MatrixPortal\bin\MatrixPortal.BL' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)



编辑:

当我尝试这个时:

migrate MatrixPortal.BL.dll /verbose



我收到其他错误:

System.BadImageFormatException: Could not load file or assembly 'MatrixPortal.BL' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: 'MatrixPortal.BL' 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.BaseRunner.FindConfiguration() at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run() at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.Data.Entity.Migrations.Console.Program.Run() at System.Data.Entity.Migrations.Console.Program.Main(String[] args)

=== Pre-bind state information === LOG: DisplayName = MatrixPortal.BL (Partial) WRN: Partial binding information was supplied for an assembly: WRN: Assembly Name: MatrixPortal.BL | Domain ID: 2 WRN: A partial bind occurs when only part of the assembly display name is provided. WRN: This might result in the binder loading an incorrect assembly. WRN: It is recommended to provide a fully specified textual identity for the assembly, WRN: that consists of the simple name, version, culture, and public key token. WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue. LOG: Appbase = file:///D:/Sites/MatrixPortal/bin/ LOG: Initial PrivatePath = NULL Calling assembly : EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\guy_b\AppData\Local\Temp\tmpC402.tmp LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///D:/Sites/MatrixPortal/bin/MatrixPortal.BL.DLL. ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

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



也试过这个:
http://www.azurefromthetrenches.com/command-line-entity-framework-code-first-migrations/

并创建了一个名为 Redirect.config 的文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
                                <bindingRedirect oldVersion="0.0.0-6.1.3" newVersion="6.1.3" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

但得到了与上面相同的错误:(

最佳答案

解决了!

我已经用 x86 objective-c pu 发布了网站项目,显然它不是真正的 x86,我不知道为什么,也许是一个错误?

将 Publish 更改为任何有效的 cpu 后。我能够使用以下参数运行 migrate.exe 没有错误:

migrate.exe MatrixPortal.BL.dll /verbose /startUpDataDirectory="D:\Sites\MatrixPortal" /startUpConfigurationFile="D:\Sites\MatrixPortal\Web.config"

关于entity-framework - 尝试在生产环境中运行 EF Code first Migrate.exe 工具失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34384305/

相关文章:

c# - 无法将匿名类型 #1[] 隐式转换为匿名类型 #2[]

.net - ObjectContext.SaveChanges() 因 SQL CE 失败

entity-framework - EF 迁移问题

visual-studio - 指定的 LocalDB 实例名称无效 : Able to create migrations but not run them

c# - Entity Framework 关系结果Web Api序列化错误

c# - 如何使用 EF 查看和编辑 DataGrid 中多个表的数据?

entity-framework-core - 使用 EF 核心设置 -TargetMigration

entity-framework - 如何重命名应用于数据库的最后一个 Entity Framework 迁移

c# - EntityFramework 不创建表

c# - 更新实体列表的有效方法