다음을 통해 공유


ZipEngine 역할이 다시 시작 상태와 사용 중 상태 사이에 중단됨

이 문서에서는 ZipEngine 역할이 다시 시작 상태와 사용 중 상태 사이에 중단되는 문제 해결과 파일 또는 어셈블리 'WorkerAssembly를 로드할 수 없음 - 잘못된 형식으로 프로그램을 로드하려고 했습니다.'라는 예외를 throw하는 문제를 해결하는 방법에 대한 정보를 제공합니다.

원래 제품 버전: API Management 서비스
원래 KB 번호: 4464909

참고 항목

랩의 첫 번째 시나리오인 Azure Cloud Service 문제 해결 시리즈에 대한 문서를 참조하세요. 이에 따라 압축기 애플리케이션에 대한 랩 설정 지침을 따라 문제를 다시 만들어야 합니다.

증상

압축기 애플리케이션의 ZipEngine 역할 인스턴스는 Azure Portal 블레이드에서 아래 처리되지 않은 예외를 throw하는 다시 시작 상태와 사용 중 상태 간에 지속적으로 반복됩니다.

Unhandled Exception: Could not load file or assembly 'WorkerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. at ZipEngine.WorkerRole.OnStart() at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum) at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge. <InitializeRole> b__0() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()'[2018-08-12T11:28:39Z] Last exit time: [2018/08/12, 11:28:39.434].

문제 해결 단계

사용자의 역할이 시작되지 않거나 초기화, 사용 중 및 중지 상태 사이에서 재활용되는 경우, 코드는 역할이 다시 시작될때마다 수명 주기 이벤트 중 하나에서 처리되지 않은 예외를 발생시킬 수 있습니다. 따라서 위의 호출 스택을 주의 깊게 살펴보면 처리되지 않은 예외가 작업자 역할의 OnStart() 메서드를 통해 수행되고 있음을 알 수 있습니다. 이러한 종류의 시나리오에 대한 문제 해결을 시작하는 가장 좋은 방법은 역할 시작/중지, 시작 작업, OnStart 시작 및 중지, OnRun 시작, 크래시, 재활용 등과 같은 정보를 포함하여 Microsoft Azure 런타임의 주요 진단 출력이 포함된 Microsoft Azure 이벤트 로그를 확인하는 것입니다.

System.BadImageFormatException

Process ID: 5132
Process Name: WaWorkerHost
Thread ID: 4
AppDomain Unhandled Exception for role ZipEngine_IN_0
Exception: Could not load file or assembly 'WorkerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
at ZipEngine.WorkerRole.OnStart()
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum)
at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.
<InitializeRole>
b__0()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

이제 System.BadImageFormatException으로 인해 작업자 역할을 호스팅하는 프로세스가 어셈블리 'WorkerAssembly'를 로드할 수 없다는 Microsoft Azure 이벤트 로그의 예외대해 좀 더 자세히 알아봅니다. 일반적으로 프로세스가 어셈블리를 로드할 수 없는 경우 Fusion 로그를 캡처하는 것이 좋습니다. Fusion 로깅을 사용하도록 설정하려면 경로 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion 아래에서 다음 레지스트리 키를 변경합니다. 모든 사용자에게 - Fusion 로그 경로 폴더에 대한 모든 권한을 부여합니다C:\FusionLogs.

스크린샷은 Fusion의 레지스트리 키를 보여줍니다.

'WorkerAssembly'에 대한 Fusion 로그를 확인하면 추가 문제 해결을 위한 자세한 정보를 얻을 수 있습니다.

*** Assembly Binder Log Entry  (8/12/2018 @ 12:51:00 PM) ***
The operation failed.
Bind result: hr = 0x8007000b. An attempt was made to load a program with an incorrect format.
Assembly manager loaded from:  D:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  E:\base\x64\WaWorkerHost.exe
--- A detailed error log follows. 
=== Pre-bind state information ===
LOG: DisplayName = WorkerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///E:/approot
LOG: Initial PrivatePath = E:\approot
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = RoleManager
Calling assembly : ZipEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: E:\approot\ZipEngine.dll.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from D:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///E:/approot/WorkerAssembly.DLL.
LOG: Assembly download was successful. Attempting setup of file: E:\approot\WorkerAssembly.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: WorkerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
ERR: Invalid assembly platform or ContentType in file (hr = 0x8007000b).
ERR: Run-from-source setup phase failed with hr = 0x8007000b.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

퓨전 로그에서 위에서 강조 표시된 오류 메시지는 어셈블리의 비트에 문제가 있음을 나타냅니다. 이 BadImageFormatException 문서를 살펴보면 이 오류의 가장 가능성이 큰 원인은 다음과 관련이 있습니다.

"DLL 또는 실행 파일은 64비트 어셈블리로 로드되지만 32비트 기능 또는 리소스를 포함합니다. 예를 들어 COM interop에 의존하거나 32비트 동적 링크 라이브러리에서 메서드를 호출합니다. 이 예외를 해결하려면 프로젝트의 플랫폼 대상 속성을 x64 또는 AnyCPU 대신 x86으로 설정하고 다시 컴파일합니다."

어셈블리의 비트를 확인하기 위해 원하는 .NET 디컴필러를 실행할 수 있습니다. ILSpy를 사용하여 'WorkerAssembly'를 디컴파일한 후 다음 어셈블리를 찾을 수 있습니다.

32비트 어셈블리(x86)입니다.

// C:\WorkerAssembly.dll
// WorkerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// Global type:
<Module>
// Architecture: x86
// Runtime: .NET 4.0

Azure는 64비트 환경입니다. 따라서 32비트 대상에 컴파일된 .NET 어셈블리는 Azure에서 작동하지 않습니다. 이 예외를 해결하려면 'WorkerAssembly' 프로젝트의 플랫폼 대상 속성을 x64(x86 또는 AnyCPU 대신)로 설정하고 다시 컴파일합니다.

ZipEngine 역할에 대한 WorkerRole.cs 코드를 검토하면 실제로 어셈블리 'WorkerAssembly'를 로드하고 일부 함수를 수행하는 두 줄의 코드가 아래에 표시됩니다. 32비트 어셈블리 이므로 WaWorkerHost.exe 해당 어셈블리를 로드할 수 없습니다.

WorkerAssembly.WorkerAssembly workerAssembly = new WorkerAssembly.WorkerAssembly();
workerAssembly.DoWork();

도움을 요청하십시오.

질문이 있거나 도움이 필요한 경우 지원 요청을 생성하거나Azure 커뮤니티 지원에 문의하세요. Azure 피드백 커뮤니티에 제품 피드백을 제출할 수도 있습니다.