I have added an application in scriptcs and added some references to assemblies which have the version v2.0.50727. So while running the scriptcs file it returns as Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime.Setting attribute useLegacyV2RuntimeActivationPolicy="true" in app.config may resolve the issue in asp.net web application. but in scriptcs its not working. further searching reveals that above attribbute useLegacyV2RuntimeActivationPolicy="true" should be added as scriptcs.exe.config. I have an application file named FMUpgrade.csx and how can we reference this scriptcs.exe.config in the FMUpgrade.csx file.scriptcs docs doesn't say much about scriptcs.exe.config.Also added program.exe.config with app.config but still not success.
After much research I got a workaround solution to the above problem. By make use of class ExeConfigurationFileMap we could able to get the key values from app.config, its not able to bypass the supported runtime error caused by mixed mode assembly error. Server server = new Server(new ServerConnection(con)); server.ConnectionContext.ExecuteNonQuery(script); The error is caused while executing the statement ExecuteNonQuery. So before executing the statement
if( RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully ) server.ConnectionContext.ExecuteNonQuery(script);
Solution is below using System.Runtime.CompilerServices; using System.Runtime.InteropServices; public static class RuntimePolicyHelper { public static bool LegacyV2RuntimeEnabledSuccessfully { get; private set; }
using System.Runtime.InteropServices; public static class RuntimePolicyHelper { public static bool LegacyV2RuntimeEnabledSuccessfully { get; private set; }