From 8e5f9aa940627b008cabbbeffc9b726ad0f6a832 Mon Sep 17 00:00:00 2001 From: mjgertsen <166763931+mjgertsen@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:10:56 +0200 Subject: [PATCH 1/2] type.assembly will never be the same as sourceassembly in case sourceassembly is an assemblybuilder --- src/Metadata/AssemblyMetadata.Types.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Metadata/AssemblyMetadata.Types.cs b/src/Metadata/AssemblyMetadata.Types.cs index 0b63551..72b023c 100644 --- a/src/Metadata/AssemblyMetadata.Types.cs +++ b/src/Metadata/AssemblyMetadata.Types.cs @@ -24,7 +24,7 @@ public bool IsReferencedType(Type type) // todo, also maybe in Module, ModuleRef, AssemblyRef and TypeRef // ECMA-335 page 273-274 - return type.Assembly != SourceAssembly; + return !SourceAssembly.FullName.Equals(type.Assembly.FullName); } private EntityHandle ResolveTypeReference(Type type) @@ -141,4 +141,4 @@ private StringHandle GetNamespaceForType(Type type) return type.IsNested ? default : GetOrAddString(type.Namespace); } } -} \ No newline at end of file +} From 7baca12841bc74b7a54adf92b7af2c9ab40fd0da Mon Sep 17 00:00:00 2001 From: mjgertsen <166763931+mjgertsen@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:15:24 +0200 Subject: [PATCH 2/2] Value provided for type parameters on customattributes which are not part of the assembly itself were not working. The GetCustomAttribute would fail because it is unable to resolve the reference for the provided type. Using the AssemblyQualifiedname will make sure the reference can be resolved. Example: [AnAttribute(typeof(TypeFromOtherAssembly))] public class test { } Trying to get the custom attribute will result in an unable to resolve "TypeFromOtherAssembly" exception --- src/AssemblyGenerator.Attributes.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AssemblyGenerator.Attributes.cs b/src/AssemblyGenerator.Attributes.cs index 20187b7..2dcc2a5 100644 --- a/src/AssemblyGenerator.Attributes.cs +++ b/src/AssemblyGenerator.Attributes.cs @@ -55,7 +55,7 @@ static void EncodeLiteral(LiteralEncoder litEnc, CustomAttributeTypedArgument ar if (arg.Value is Type type) { // Type reference - litEnc.Scalar().SystemType(type.FullName); + litEnc.Scalar().SystemType(type.AssemblyQualifiedName); } else if (arg.Value is ReadOnlyCollection array) { @@ -162,4 +162,4 @@ static PrimitiveSerializationTypeCode PrimitiveTypeCodeFromSystemTypeCode(Type t throw new NotImplementedException($"Unsupported primitive type: {type}"); } } -} \ No newline at end of file +}