2017-05-15 9 views
1

의 생성자를 해결하려고 할 때 :System.BadImageFormatException 나는 다음과 같은 코드에 문제가 System.Collections.Generic.GenericComparer`1

var type1 = typeof(object); 
var type2 = type1.Module.GetType("System.Collections.Generic.GenericComparer`1"); 
var constr = type2.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); 
var byteArray = constr.GetMethodBody().GetILAsByteArray(); 
var result = type2.Module.ResolveMethod(BitConverter.ToInt32(byteArray, 2)); 

매번 나는 그것이 나에게 다음과 같은 오류를 제공하여 실행 :

An exception of type 'System.BadImageFormatException' occurred in mscorlib.dll and wasn't handled before a managed/native boundary 
Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) 

그러나

var type2 = type1.Module.GetType("System.Collections.Generic.GenericComparer`1"); 

의 insteaf 나는 기본 클래스를 사용하는 경우

var type2 = type1.Module.GetType("System.Collections.Generic.Comparer`1"); 

"ResolveMethod"가 OK를 반환합니다.

누구나 그 클래스를 "해결"할 수없는 이유를 알고 있습니까?

감사합니다.

+0

, 둘 다 오류를 제공합니다. 나는 그 일과 관련이 없다고 생각합니다. – Florin

+0

아마도'GenericComparer'가 내부적일까요? –

+0

그렇게 생각하지 마십시오 .. System.Collections.StructuralComparer도 내부적으로 시도했는데 작동합니다 .. – Florin

답변

0

일반 문맥이 부족하기 때문일 수 있습니다. 기본 클래스의 차이점은 System.Collections.Generic.GenericComparer`1이 파생 된 유형을 보면 기본 클래스에서 파생 된 유형이 아니므로 적어도 검사 할 때 말했기 때문입니다. FullName조차 없다. 또한 GenericTypeArgument [1]을 가지고 있지만 t1은 아래 예제에서 볼 수 없습니다. 나는 일부 개체를 복제하는 DeepCloner을 사용하고 있기 때문에 이것에 대한 해결책이 있는지

 var t1 = Type.GetType("System.Collections.Generic.Comparer`1"); 
     var t2 = Type.GetType("System.Collections.Generic.GenericComparer`1").BaseType; 
     bool assignable = t1.IsAssignableFrom(t2); 
+0

재미 있습니다 .. dotPeek 및 GenericComparer'1에서 한 번 보았습니다. Compare1에서 상속 받았습니다 ' 내부 클래스 GenericComparer : Comparer 여기서 T : IComparable ' – Florin

0

내가 부탁 해요, 그리고 그들 중 일부는 IEnumerable을있는 특성을 가지고 있으며 그 가치는 또는 주문을 포함하는 표현이다 DB에 질의를합니다.

그런 종류의 복제를 시도 할 때 DeepCloner는 System.Collections.Generic.GenericComparer'1의 생성자를 해결하려고 시도하거나 DB를 쿼리하는 데 필요한 다른 방법을 해결하려고 할 때 예외를 제공합니다.

는 vb.net의 예입니다 : 내가 32 비트 및 64 비트 모두에서 응용 프로그램을 구축하기 위해 노력했다

Public Class cls1 
     Public Property prop2 As Integer 
    End Class 


    Public Class cls0 
     Public Property prop1 As IEnumerable(Of cls1) 
    End Class 

    Private Sub doClone() 
     Dim ob1 = New cls0() 
     Dim source = New List(Of cls1) 
     For i = 0 To 10 - 1 
      source.Add(New cls1() With {.prop2 = i}) 
     Next 
     ob1.prop1 = (From a In source Where a.prop2 < 5 Order By a.prop2 Select a) 
     ob1.DeepClone() 
    End Sub