diff --git a/Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs b/Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs index e9b84e45..f4ad758d 100644 --- a/Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs +++ b/Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs @@ -137,6 +137,13 @@ private void InitPre29AttributeGeneratorAnalysis(int rangeIndex) { ulong generatorPtr; if (AppContext.MetadataVersion < 27) + { + if (rangeIndex < 0) + { + RawIl2CppCustomAttributeData = Array.Empty(); + return; + } + try { generatorPtr = AppContext.Binary.GetCustomAttributeGenerator(rangeIndex); @@ -147,6 +154,7 @@ private void InitPre29AttributeGeneratorAnalysis(int rangeIndex) RawIl2CppCustomAttributeData = Array.Empty(); return; } + } else { var baseAddress = CustomAttributeAssembly.CodeGenModule!.customAttributeCacheGenerator; @@ -204,7 +212,7 @@ public void AnalyzeCustomAttributeData(bool allowAnalysis = true) //Basically, extract actions from the analysis, and compare with the type list we have to resolve parameters and populate the CustomAttributes list. - foreach (var il2CppType in AttributeTypes!) //Assert nonnull because we're pre-29 at this point + foreach (var il2CppType in AttributeTypes ?? []) //Can be null for injected objects { var typeDef = il2CppType.AsClass(); var attributeTypeContext = AppContext.ResolveContextForType(typeDef) ?? throw new("Unable to find type " + typeDef.FullName);