diff --git a/MetadataProcessor.Shared/Tables/nanoSignaturesTable.cs b/MetadataProcessor.Shared/Tables/nanoSignaturesTable.cs index 49d5dfb..b75b20b 100644 --- a/MetadataProcessor.Shared/Tables/nanoSignaturesTable.cs +++ b/MetadataProcessor.Shared/Tables/nanoSignaturesTable.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // Original work from Oleg Rakhmatulin. @@ -477,7 +477,7 @@ public void WriteDataType( if (alsoWriteSubType) { GenericInstanceType genericType = (GenericInstanceType)typeDefinition; - WriteDataType(genericType.Resolve(), writer, true, expandEnumType, isTypeDefinition); + WriteDataType(genericType.ElementType, writer, true, expandEnumType, isTypeDefinition); // OK to use byte here as we won't support more than 0x7F arguments writer.WriteByte((byte)genericType.GenericArguments.Count); diff --git a/MetadataProcessor.Shared/Tables/nanoTablesContext.cs b/MetadataProcessor.Shared/Tables/nanoTablesContext.cs index ffe8bf8..6877427 100644 --- a/MetadataProcessor.Shared/Tables/nanoTablesContext.cs +++ b/MetadataProcessor.Shared/Tables/nanoTablesContext.cs @@ -269,8 +269,10 @@ public ushort GetMethodReferenceId( else if (memberReference is MethodReference && MethodReferencesTable.TryGetMethodReferenceId(memberReference as MethodReference, out referenceId)) { - // check if method is external - if (memberReference.DeclaringType.Scope.MetadataScopeType == MetadataScopeType.AssemblyNameReference) + // check if method is external, unless it's a closed generic instance + if (memberReference.DeclaringType.Scope.MetadataScopeType == MetadataScopeType.AssemblyNameReference + && !(memberReference.DeclaringType is GenericInstanceType genericInstanceType + && genericInstanceType.HasGenericArguments)) { // method reference is external } diff --git a/MetadataProcessor.Shared/nanoAssemblyBuilder.cs b/MetadataProcessor.Shared/nanoAssemblyBuilder.cs index 9dba700..5101db8 100644 --- a/MetadataProcessor.Shared/nanoAssemblyBuilder.cs +++ b/MetadataProcessor.Shared/nanoAssemblyBuilder.cs @@ -829,11 +829,6 @@ private HashSet BuildDependencyList(MetadataToken token) set.Add(v.VariableType.GetElementType().MetadataToken); } } - else if (v.VariableType.IsValueType - && !v.VariableType.IsPrimitive) - { - set.Add(v.VariableType.MetadataToken); - } else if (v.VariableType is GenericInstanceType) { // Cecil.Mono has a bug providing TypeSpecs Metadata tokens generic parameters variables, so we need to check against our internal table and build one from it @@ -852,6 +847,11 @@ private HashSet BuildDependencyList(MetadataToken token) Debug.Fail($"Couldn't find a TypeSpec entry for {v.VariableType}"); } } + else if (v.VariableType.IsValueType + && !v.VariableType.IsPrimitive) + { + set.Add(v.VariableType.MetadataToken); + } else if (v.VariableType.IsPointer) { string message = $"Pointer types in unsafe code aren't supported. Can't use {v.VariableType} variable in \"{md.FullName}\"."; @@ -1051,7 +1051,7 @@ private HashSet BuildDependencyList(MetadataToken token) { // add "fabricated" token for TypeSpec using the referenceId as RID set.Add(new MetadataToken(TokenType.TypeSpec, tsRid)); - set.Add(ts.GetElementType().MetadataToken); + set.Add(ts.MetadataToken); } else {