Applies ToWindows Vista Service Pack 2 Windows 7 Service Pack 1 Windows Server 2008 Service Pack 2 Windows Server 2008 R2 Service Pack 1 Windows 8 Windows Server 2012 Datacenter Windows Server 2012 Datacenter Windows Server 2012 Essentials Windows Server 2012 Foundation Windows Server 2012 Foundation Windows Server 2012 Standard Windows Server 2012 Standard Windows Server 2012 R2 Datacenter Windows Server 2012 R2 Essentials Windows Server 2012 R2 Foundation Windows Server 2012 R2 Standard Windows 8.1

증상

코드는 Microsoft.NET Framework 4.5.1 또는 Microsoft.NET Framework, 4.5.2 코드와 동적으로 바인딩할 때 컨텍스트에서만 메서드나 System.Runtime.InteropServices.Marshal.PtrToStructure 메서드를 호출 하는 메서드 (예: Windows PowerShell, IronPython, IronRuby 또는 다른 동적 언어의 스크립트를 사용 하 여), 다음과 같은 문제가 발생할 수 있습니다.참고: 이미 관리 되는 실행 파일에 컴파일되는 코드에는 코드에서 C# dynamic 키워드를 사용 하지 않는 경우이 문제를 발생 하지 않습니다.

문제 1

다음 MethodInvocationException 예외를 throw 하는 컨텍스트에서만 호출:

관리 되지 않는 구조로 ' <형식 이름>' 형식 마샬링 설명자 수 없습니다. 의미 없는 크기나 오프셋을 계산할 수 있습니다.

문제 2

다음 MethodInvocationException 예외를 throw 하는 System.Runtime.InteropServices.Marshal.PtrToStructure 를 호출 합니다.

지정된 된 구조 blittable 이거나 레이아웃 정보를 가져야 합니다.

문제 3

다음 RuntimeBinderException 예외를 throw 하는 System.Runtime.InteropServices.Marshal.PtrToStructure 를 호출 합니다.

'Object'에 ' void' 형식을 암시적으로 변환할 수 있습니다.

원인

스크립팅 엔진 때문에이 문제가 발생 하 고 동적 언어는.NET Framework 도입 된 새 오버 로드를 바인딩할 수 있습니다. 특히 이전 Marshal.SizeOf(Type) 를 사용 하는 호출 Marshal.SizeOf < T > (T)호출할 수 및 Marshal.PtrToStructure (IntPtr, 형식)를 사용 하는 호출 호출할 수 있습니다 Marshal.PtrToStructure < T >(IntPtr, T). 이 변경으로 인해 메서드나 런타임 바인더에서 예외를 throw 합니다.

해결 방법

이 문제를 해결 하려면 코드를 해당 언어를 사용 하면이 작업을 수행 하는 경우 올바른 오버 로드를 사용 하도록 변경 합니다. 특정 메서드 오버 로드를 지정할 수 없습니다 구성 된 새 없이 제대로 대신 코드를 변경 합니다.

C# 동적 호출에 대 한

System.Type 을 SizeOf 메서드나 PtrToStructure메서드 호출 내에서 캐스트를 추가 합니다. 예를 들어:

object obj = System.Runtime.InteropServices.Marshal.PtrToStructure(ptr, (System.Type)type);int size = System.Runtime.InteropServices.Marshal.SizeOf((System.Type)type);

참고: 이것은 메서드에 대 한 인수 중 하나는 동적 경우에 필요입니다.

Windows PowerShell 스크립트에 대 한

System.Type 을 SizeOf 메서드나 PtrToStructure메서드 호출 내에서 캐스트를 추가 합니다. 예를 들어:

$size = [System.Runtime.InteropServices.Marshal]::SizeOf([System.Type] $type)$obj = [System.Runtime.InteropServices.Marshal]::PtrToStructure($ptr, [System.Type] $type)

IronPython 스크립트에 대 한

형식, 새 형식 인스턴스를 만들고 새 메서드 오버 로드를 사용 합니다. 예를 들어:

typeInstance = type()size = System.Runtime.InteropServices.Marshal.SizeOf(typeInstance)obj = System.Runtime.InteropServices.Marshal.PtrToStructure(ptr, typeInstance)

상태

Microsoft는 이 문제가 '적용 대상' 섹션에 나열된 Microsoft 제품의 문제임을 확인했습니다.

참조

도움이 더 필요하세요?

더 많은 옵션을 원하세요?

구독 혜택을 살펴보고, 교육 과정을 찾아보고, 디바이스를 보호하는 방법 등을 알아봅니다.