Browse Source

Fix #1210: v4.x: System.InvalidCastException: Specified cast is not valid

pull/1213/head
Siegfried Pammer 7 years ago
parent
commit
dbe29596de
  1. 6
      ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs

6
ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs

@ -305,7 +305,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -305,7 +305,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
return false;
if (!(initialState == -2 || initialState == 0))
return false;
enumeratorCtor = (MethodDefinitionHandle)newObj.Method.MetadataToken;
var handle = newObj.Method.MetadataToken;
enumeratorCtor = handle.IsNil || handle.Kind != HandleKind.MethodDefinition ? default : (MethodDefinitionHandle)handle;
enumeratorType = enumeratorCtor.IsNil ? default : metadata.GetMethodDefinition(enumeratorCtor).GetDeclaringType();
return (enumeratorType.IsNil ? default : metadata.GetTypeDefinition(enumeratorType).GetDeclaringType()) == currentType
&& IsCompilerGeneratorEnumerator(enumeratorType, metadata);
@ -318,7 +319,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -318,7 +319,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
return false;
if (newObj.Arguments.Count != 0)
return false;
enumeratorCtor = (MethodDefinitionHandle)newObj.Method.MetadataToken;
var handle = newObj.Method.MetadataToken;
enumeratorCtor = handle.IsNil || handle.Kind != HandleKind.MethodDefinition ? default : (MethodDefinitionHandle)handle;
enumeratorType = enumeratorCtor.IsNil ? default : metadata.GetMethodDefinition(enumeratorCtor).GetDeclaringType();
return (enumeratorType.IsNil ? default : metadata.GetTypeDefinition(enumeratorType).GetDeclaringType()) == currentType
&& IsCompilerGeneratorEnumerator(enumeratorType, metadata);

Loading…
Cancel
Save