我有窗口应用程序,已经做了一些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);