0

私はウィンドウアプリケーションを持っています、いくつかを作りました、 アプリケーションのインストール中にユーザーから値を取得する custom action編集、さらにテーブルの作成中にインストーラークラスでエラーメッセージを下回っていますuserinterface

Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot
be loaded in the 4.0 runtime without additional configuration information.

私はたくさんグーグルして、以下を追加することで問題が解決することがわかりました(私にはうまくいきませんでした)

 <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    <supportedRuntime version="v2.0.50727"/>
  </startup>

以前の私のapp.confgは次のようになります

<startup>
      <supportedRuntime version="v2.0.50727"/>
  </startup>

コード:Installer1.cs

public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
            string targetDirectory = Context.Parameters["targetdir"];
            string servername = Context.Parameters["dbservername"];
            string dbname = Context.Parameters["dbname"];
            string strconnectionstring = "Data Source='" + servername + "';Initial Catalog='" + dbname + "';Integrated Security=True";

            if (servername == "")
            {
                throw new InstallException("You did not Specify SQL Servername!");
            }

            else if (dbname == "")
            {
                throw new InstallException("You did not specify the database name!");
            }

            string exePath = string.Format("{0}abc..exe", targetDirectory);
            System.Configuration.Configuration conf = ConfigurationManager.OpenExeConfiguration(exePath);
            conf.ConnectionStrings.ConnectionStrings["abc"].ConnectionString = strconnectionstring;
            conf.Save(ConfigurationSaveMode.Modified);


            using (SqlConnection con1 = new SqlConnection(strconnectionstring))
            {
                System.Diagnostics.Debugger.Break();
                string getScript = "Use " + dbname + "; CREATE TABLE supportContacts ( id int identity primary key,  type varchar(20),  details varchar(30)  )";
               // string strscript = getScript;
                Server server = new Server(new ServerConnection(con1));
                server.ConnectionContext.ExecuteNonQuery(getScript );
                con1.Close();
            }   


        }

デバッグ中にエラーが発生することを知るようになります server.ConnectionContext.ExecuteNonQuery(strupdatescript);

4

2 に答える 2

1

私にとっては、以下が機能しました:

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
于 2012-08-20T16:22:48.487 に答える
0

私は同じ正確な問題を抱えています。誰かがこれを解決できるものを明らかにすることができれば、最も感謝しています。

私は答えを見つけました:)。私のために働いた。

http://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/

于 2012-08-29T14:10:22.430 に答える