2016-06-17 3 views
0

scriptcs에 응용 프로그램을 추가하고 v2.0.50727 버전의 어셈블리에 대한 참조를 추가했습니다. 따라서 스크립트 파일을 실행하는 동안 혼합 모드 어셈블리가 런타임 버전 'v2.0.50727'에 대해 빌드되고 4.0 런타임에로드 될 수 없기 때문에 반환됩니다. app.config의 useLegacyV2RuntimeActivationPolicy = "true"속성은 ASP에서 문제를 해결할 수 있습니다. .net 웹 응용 프로그램. 하지만 스크립트에서는 작동하지 않습니다. 추가 검색은 위의 attribbute useLegacyV2RuntimeActivationPolicy = "true"가 scriptcs.exe.config로 추가되어야 함을 나타냅니다. FMUpgrade.csx라는 응용 프로그램 파일이 있는데 FMUpgrade.csx 파일에서이 scriptcs.exe.config를 어떻게 참조 할 수 있습니까? scripts.scriptcs docs는 scriptcs.exe.config.Also에 대해 많이 말하지 않습니다. 또한 app.exe.config와 app .config하지만 여전히 성공하지 못했습니다.scriptcs 혼합 모드 어셈블리 오류

답변

0

많은 연구 끝에 위의 문제에 대한 해결책을 찾았습니다. 클래스 ExeConfigurationFileMap을 사용하여 app.config에서 키 값을 가져올 수 있었고, 혼합 모드 어셈블리 오류로 인해 지원되는 런타임 오류를 우회 할 수 없었습니다. 서버 서버 = 새 서버 (새 ServerConnection (con)); server.ConnectionContext.ExecuteNonQuery (스크립트); ExecuteNonQuery 문을 실행하는 동안 오류가 발생합니다. 그래서 문

경우를 실행하기 전에 (RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully) server.ConnectionContext.ExecuteNonQuery (스크립트);

해결 방법은 입니다. System.Runtime.CompilerServices; using System.Runtime.InteropServices; 공공 정적 클래스 RuntimePolicyHelper { 공개 정적 bool 레거시 V2RuntimeEnabledSuccessfully {get; 개인 집합; }

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; 공공 정적 클래스 RuntimePolicyHelper { 공개 정적 bool 레거시 V2RuntimeEnabledSuccessfully {get; 개인 집합; }

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