我有窗口应用程序,制作了一些
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);
对我来说以下工作有效:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
我也有同样的问题。如果有人能指出什么可以解决这个问题,非常感激。
我找到了答案:)。为我工作。