簡體   English   中英

錯誤1001 system.badimageformatexception無法在創建安裝項目Visual Studio 2013時加載文件或程序集

[英]Error 1001 system.badimageformatexception could not load file or assembly on creation of a setup project visual studio 2013

我在Visual Studio 2013中有一個項目,該項目使用wpf和Entity Framework,並連接到SQL Server Express R2數據庫,該項目已完成,我需要為其創建安裝程序,我正在使用本教程
因此我創建了腳本(帶有數據)作為數據庫的嵌入式資源,安裝程序類(名為SetupInstaller)並將項目的輸出添加到安裝程序中,所有內容均生成無誤,但是當我嘗試安裝項目時,我收到了錯誤

錯誤1001 System.BadImageFormatException無法加載文件或程序集

我做了幾次更改,這只是在創建自定義操作時發生的,但是當我不使用它時,不會創建數據庫

我的連接線去了

<connectionStrings>    
   <add name="Bulldog_Gym.Properties.Settings.BulldogGymConnectionString" 
     connectionString="Data Source=.;Initial Catalog=BulldogGym;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

我的SetupInstaller類是這樣的

[RunInstaller(true)]
public partial class SetupInstaller : System.Configuration.Install.Installer
{
    SqlConnection masterConnection = new SqlConnection();
    public SetupInstaller()
        : base()
    {
        InitializeComponent();
    }
    private string GetSql(string Name)
    {

        try
        {
            // Gets the current assembly.
            Assembly Asm = Assembly.GetExecutingAssembly();

            // Resources are named using a fully qualified name.
            Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + Name);

            // Reads the contents of the embedded file.
            StreamReader reader = new StreamReader(strm);
            return reader.ReadToEnd();

        }
        catch (Exception ex)
        {
            MessageBox.Show("In GetSQL: " + ex.Message);
            throw ex;
        }
    }

    private void ExecuteSql(string DatabaseName, string Sql)
    {
        System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand(Sql, masterConnection);

        // Initialize the connection, open it, and set it to the "master" database
        masterConnection.ConnectionString = Properties.Settings.Default.BulldogGymConnectionString;
        Command.Connection.Open();
        Command.Connection.ChangeDatabase(DatabaseName);
        try
        {
            Command.ExecuteNonQuery();
        }
        finally
        {
            // Closing the connection should be done in a Finally block
            Command.Connection.Close();
        }
    }

    protected void AddDBTable(string strDBName)
    {
        try
        {
            // Creates the database.
            ExecuteSql("master", "CREATE DATABASE " + strDBName);

            // Creates the tables.
            ExecuteSql(strDBName, GetSql("bulldog.txt"));

            // Creates the stored procedure.
            //ExecuteSql(strDBName, GetSql("getproduct.txt"));

        }
        catch (Exception ex)
        {
            // Reports any errors and abort.
            MessageBox.Show("In exception handler: " + ex.Message);
            throw ex;
        }
    }


    public override void Install(System.Collections.IDictionary stateSaver)
    {
        base.Install(stateSaver);
        AddDBTable("BulldogGym");
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);
        ExecuteSql("master", "DROP DATABASE BulldogGym");
    }
}

還有我的txt與數據庫

我已經將數據庫更改為非數據腳本,將主服務器添加到連接字符串,將目標從x64(當前)更改為Any CPU,但這似乎都不起作用,請我提供一些指導。 謝謝!

聽起來這與位不匹配有關。 我在這里回答了類似的問題:

BadImageFormatException

您的帶有安裝程序類的程序集是64位,但是嘗試運行它的installutil.exe必須是32位,這會導致問題。 您需要以某種方式執行64位版本的installutil.exe。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM