简体   繁体   English

Windows 应用程序部署与 SQL 服务器数据库和实体框架错误

[英]Windows application deployment with SQL Server database and Entity Framework error

I have a Windows app which I developed with Entity Framework and a code-first approach.我有一个使用实体框架和代码优先方法开发的 Windows 应用程序。 It's working perfectly on my own computer.它在我自己的电脑上完美运行。 But when I try to deploy the app to a client who has SQL Server installed, it throws the following error.但是,当我尝试将应用程序部署到安装了 SQL 服务器的客户端时,它会引发以下错误。 What am I missing here?我在这里想念什么?

System.BadImageFormatException: Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. System.BadImageFormatException:无法加载文件或程序集“EntityFramework,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”或其依赖项之一。 The module was expected to contain an assembly manifest.该模块应包含程序集清单。
File name: 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' at BLL.BLMasters.BLCompany..ctor()文件名:'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' at BLL.BLMasters.BLCompany..ctor()

Here is my app.config file:这是我的app.config文件:

<configuration>
    <configSections>
        <section name="entityFramework"
                 type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                 requirePermission="false"/>
    </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
    </startup>
    <connectionStrings>
        <add name="MyDBConnectionString" 
             providerName="System.Data.SqlClient"
             connectionString="Data Source=DESKTOP-NMSSFU8;Initial Catalog=AMSDEV;Integrated Security=True; Max Pool Size=200;" />
    </connectionStrings>
    <entityFramework>
        <providers>
            <provider invariantName="System.Data.SqlClient" 
                      type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
        </providers>
    </entityFramework>
</configuration>

在此处输入图像描述

Can you please check if the project properties of all your projects are set to correct target platform?您能否检查一下您所有项目的项目属性是否设置为正确的目标平台?

Goto your project properties → Build → Target Platform.转到您的项目属性 → 构建 → 目标平台。

Check this is set to either of the values for all your projects: x86, x64, Any CPU.检查这是否设置为所有项目的任一值:x86、x64、任何 CPU。

Try selecting "Any CPU" for all projects in your solution and then deploy it to client machine and check.尝试为解决方案中的所有项目选择“任何 CPU”,然后将其部署到客户端计算机并检查。

This error generally occurs when you have different CPU architecture then the compiled version of the target machine.当您的 CPU 架构与目标机器的编译版本不同时,通常会发生此错误。 Selecting Any CPU generally solves the issue.选择任何 CPU 通常可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM