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.

我google了很多,发现在下面添加可以解决问题(不适合我)

 <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 回答