Script assembly build error

I have added the application to scripts and added links to assemblies that have version v2.0.50727. So when running the script file it is returned because the mixed mode assembly is built against the "v2.0.50727" runtime version and cannot be loaded in the 4.0 runtime.Setting attribute useLegacyV2RuntimeActivationPolicy = "true" in app.config can fix the problem in asp. net. but in scripts it doesn't work. Further searching reveals that above the useLegacyV2RuntimeActivationPolicy = "true" attribute should be added as scriptcs.exe.config. I have an application file named FMUpgrade.csx and how can we refer to this scriptcs.exe.config file in FMUpgrade.csx.scriptcs docs does not say anything about scriptcs.exe.config file. Also added a program.exe.config file with a .config attachment but still failed.

0


source to share


1 answer


After a lot of research, I came up with a workaround for the above problem. Using the ExeConfigurationFileMap class, we were able to get key values ​​from app.config without being able to work around a supported runtime error caused by a mixed mode build error. Server server = new server (new ServerConnection (con)); server.ConnectionContext.ExecuteNonQuery (script); An error occurs while executing the ExecuteNonQuery statement. Therefore, before executing the operator

if (RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully) server.ConnectionContext.ExecuteNonQuery (script);

Solution below using System.Runtime.CompilerServices; using System.Runtime.InteropServices; public static class RuntimePolicyHelper {public static bool LegacyV2RuntimeEnabledSuccessfully {get; private set; }



    static RuntimePolicyHelper()
    {
        ICLRRuntimeInfo clrRuntimeInfo =
        (ICLRRuntimeInfo)RuntimeEnvironment.GetRuntimeInterfaceAsObject(
        Guid.Empty,
        typeof(ICLRRuntimeInfo).GUID);
        try
        {
            clrRuntimeInfo.BindAsLegacyV2Runtime();
            LegacyV2RuntimeEnabledSuccessfully = true;
        }
        catch (COMException)
        {
            // This occurs with an HRESULT meaning
            // "A different runtime was already bound to the legacy CLR version 2 activation policy."
            LegacyV2RuntimeEnabledSuccessfully = false;
        }
    }

    [ComImport]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    [Guid("BD39D1D2-BA2F-486A-89B0-B4B0CB466891")]
    private interface ICLRRuntimeInfo
    {
        void xGetVersionString();
        void xGetRuntimeDirectory();
        void xIsLoaded();
        void xIsLoadable();
        void xLoadErrorString();
        void xLoadLibrary();
        void xGetProcAddress();
        void xGetInterface();
        void xSetDefaultStartupFlags();
        void xGetDefaultStartupFlags();

        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
        void BindAsLegacyV2Runtime();
    }
 } using System.Runtime.CompilerServices;

      

using System.Runtime.InteropServices; public static class RuntimePolicyHelper {public static bool LegacyV2RuntimeEnabledSuccessfully {get; private set; }

    static RuntimePolicyHelper()
    {
        ICLRRuntimeInfo clrRuntimeInfo =
        (ICLRRuntimeInfo)RuntimeEnvironment.GetRuntimeInterfaceAsObject(
        Guid.Empty,
        typeof(ICLRRuntimeInfo).GUID);
        try
        {
            clrRuntimeInfo.BindAsLegacyV2Runtime();
            LegacyV2RuntimeEnabledSuccessfully = true;
        }
        catch (COMException)
        {
            // This occurs with an HRESULT meaning
            // "A different runtime was already bound to the legacy CLR version 2 activation policy."
            LegacyV2RuntimeEnabledSuccessfully = false;
        }
    }

    [ComImport]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    [Guid("BD39D1D2-BA2F-486A-89B0-B4B0CB466891")]
    private interface ICLRRuntimeInfo
    {
        void xGetVersionString();
        void xGetRuntimeDirectory();
        void xIsLoaded();
        void xIsLoadable();
        void xLoadErrorString();
        void xLoadLibrary();
        void xGetProcAddress();
        void xGetInterface();
        void xSetDefaultStartupFlags();
        void xGetDefaultStartupFlags();

        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
        void BindAsLegacyV2Runtime();
    }
 }

      

0


source







All Articles