简体   繁体   中英

Error Mixed mode assembly against version 'v2.0.50727' .. when creating tables while running setup , Installer class

I have window application,have made some custom action , Edit userinterface retrieving values from user while installing application and further in installer class while creating tables am getting below error message

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.

I google a lot and found that adding below will solve problem (Not worked for me)

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

previously my app.confg look like

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

Code : 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();
            }   


        }

While debugging i get to know error occur at server.ConnectionContext.ExecuteNonQuery(strupdatescript);

For me the following worked:

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

I am having the same EXACT issue. If anyone can bring to light what could resolve this, most appreciated.

I found the/an answer :). Worked for me.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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