2014-09-11 5 views
1

두 가지 버전의 어셈블리를로드해야하는 .net Windows 서비스가 있습니다. 서버 2012 R2 상자에서 실행됩니다..net Windows 서비스에서 바인딩 리디렉션의 SideBySide 오류

:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <linkedConfiguration href="file://E:\my-service\runtime.config" /> 
</assemblyBinding> 

내 runtime.config 실제 바인딩 리디렉션을 포함 : 나는 닫는 </configuration> 노드하기 전에이 작업을 사용하여 메인의 app.config에로드 별도의 .config 파일에 바인딩 리디렉션 (see MSDN doc)를 사용하고 있습니다

<configuration> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" /> 
     <codeBase version="0.4.0.126" href="AutoMapper.dll" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" /> 
     <codeBase version="3.2.1.0" href="AutoMapper.3.2.1\AutoMapper.dll" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 

이 작업은 서버가 재부팅 될 때까지 올바르게 작동합니다. 우리는 기계가 시작된 후 이벤트 로그에서 볼 :

Activation context generation failed for "Service.exe". 
Error in manifest or policy file "Service.exe.Config" on line 71. 
The element assemblyBinding appears as a child of element configuration which is not supported by this version of Windows. 

그래서 내가 (이 blog에 따라)을 sxstrace.exe 도구를 실행하고이 출력을 얻을 : 나는 linkedConfiguration에서 제거하면

================= 
Begin Activation Context Generation. 
Input Parameter: 
    Flags = 0 
    ProcessorArchitecture = AMD64 
    CultureFallBacks = en-US;en 
    ManifestPath = E:\my-service\Service.exe 
    AssemblyDirectory = E:\my-service\ 
    Application Config File = E:\my-service\Service.exe.Config 
----------------- 
INFO: Parsing Application Config File E:\my-service\Service.exe.Config. 
    ERROR: Line 71: The element assemblyBinding appears as a child of element configuration which is not supported by this version of Windows. 
ERROR: Activation Context generation failed. 
End Activation Context Generation. 

을 서비스가 시작되는 주 app.config (다른 오류가 있음에도 불구하고). 그런 다음 다시 추가 할 수 있으며 서비스를 시작하고 다시 시작할 때까지 중지 할 수 있습니다.

왜 이런 일이 일어날 지 알고 있습니까? 그리고 이것이 linkedConfiguration의 올바른 사용입니까?

UPDATE

는 후와 Microsoft 지원 길고 생산적인 대화, 내가 포함 된 매니페스트와 linkedConfiguration를 사용하여 (see MSDN doc)는 지원되지 않습니다 것을 발견했다.

그러나 외부 파일에서 구성을로드하는 중에 버그가있는 것으로 보입니다. 나는 이것을 bug on connect으로 제기했다.

답변

1

마이크로 소프트 지원 업데이트 및 @cmckeegan의 제안에 이어 우리는 바인딩 리디렉션을위한 외부 설정 파일에서 코드로 옮겼습니다. 이제 composition root에서 BindingRedirects.Register()이라고 부릅니다.

BindingRedirects 클래스는 다음과 같습니다

public static class BindingRedirects 
{ 
    static readonly Dictionary<string, string> Redirects = new Dictionary<string, string> 
    { 
     { "AutoMapper, Version=3.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005", @"AutoMapper.3.2.1\AutoMapper.dll"}  
    }; 

    public static void Register() 
    { 
     AppDomain.CurrentDomain.AssemblyResolve += (o, args) => 
     { 
      if (Redirects.ContainsKey(args.Name)) 
      { 
       var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Redirects[args.Name]); 
       return Assembly.LoadFrom(path); 
      } 

      return null; 
     }; 
    } 
}