Skip to content

Fix NRT annotations in Xamarin.Android.Build.Tasks/Utilities directory and resolve runtime KeyNotFoundException #10371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a958adf
Initial plan
Copilot Aug 4, 2025
60a2bfd
Fix NRT annotations in MarshalMethodsClassifier.cs
Copilot Aug 4, 2025
7006395
Fix NRT annotations in ManifestDocument.cs
Copilot Aug 4, 2025
b122355
Fix NRT annotations in ManifestDocumentElement.cs
Copilot Aug 4, 2025
48e3a45
Fix NRT annotations in TypeMapGenerator.cs (basic setup)
Copilot Aug 4, 2025
c7b472e
Fix NRT annotations in several LlvmIrGenerator files
Copilot Aug 4, 2025
d2e7354
Fix NRT annotations in remaining LlvmIrGenerator files
Copilot Aug 4, 2025
869cd6b
Make TypeDefinition parameter non-nullable in FindMethod and FindField
Copilot Aug 4, 2025
7410086
Fix core NRT issues in MarshalMethodsClassifier, ManifestDocument, an…
Copilot Aug 4, 2025
3110aa0
Fix additional NRT issues in TypeMap, StructureInstance, and LlvmIr f…
Copilot Aug 4, 2025
03e969c
Remove redundant null assignments in MarshalMethodEntry constructor
Copilot Aug 4, 2025
0d18d31
Fix primary NRT errors in LlvmIrGenerator files mentioned in feedback
Copilot Aug 5, 2025
e1e2c21
Continue fixing NRT errors in LLVM files mentioned in feedback
Copilot Aug 5, 2025
189da69
Changes before error encountered
Copilot Aug 5, 2025
3f41160
Apply code style improvements suggested in review feedback
Copilot Aug 6, 2025
04ba175
Fix remaining null reference errors in ManifestDocument.cs methods
Copilot Aug 6, 2025
abe06e5
Fix KeyNotFoundException for System.Object in ValueConverters dictionary
Copilot Aug 6, 2025
ae81d7a
Address code review feedback on ManifestDocumentElement.cs
Copilot Aug 7, 2025
e7c50f1
Implement all code review feedback on ManifestDocumentElement.cs
Copilot Aug 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static ActivityAttribute FromTypeDefinition (TypeDefinition type, TypeDef

internal XElement ToElement (IAssemblyResolver resolver, string packageName, TypeDefinitionCache cache, int targetSdkVersion)
{
return mapping.ToElement (this, specified, packageName, cache, type, resolver, targetSdkVersion);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache, type, resolver, targetSdkVersion);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static ApplicationAttribute FromCustomAttributeProvider (ICustomAttribute

internal XElement ToElement (IAssemblyResolver resolver, string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache, provider, resolver);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache, provider, resolver);
}

static string ToNameAttribute (ApplicationAttribute self, ICustomAttributeProvider provider, IAssemblyResolver resolver, TypeDefinitionCache cache)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static BroadcastReceiverAttribute FromTypeDefinition (TypeDefinition type

public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static ContentProviderAttribute FromTypeDefinition (TypeDefinition type,

public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static IEnumerable<GrantUriPermissionAttribute> FromTypeDefinition (TypeD

public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void SetTargetPackage (string package)

public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static LayoutAttribute FromTypeDefinition (TypeDefinition type, TypeDefin

internal XElement ToElement (IAssemblyResolver resolver, string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache, type, resolver);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache, type, resolver);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static IEnumerable<MetaDataAttribute> FromCustomAttributeProvider (ICusto

public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IEnumerable<PermissionAttribute> FromCustomAttributeProvider (ICus

internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}

internal class PermissionAttributeComparer : IEqualityComparer<PermissionAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IEnumerable<PermissionGroupAttribute> FromCustomAttributeProvider

internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}

internal class PermissionGroupAttributeComparer : IEqualityComparer<PermissionGroupAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IEnumerable<PermissionTreeAttribute> FromCustomAttributeProvider (

internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}

internal class PermissionTreeAttributeComparer : IEqualityComparer<PermissionTreeAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static IEnumerable<PropertyAttribute> FromCustomAttributeProvider (ICusto

public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static ServiceAttribute FromTypeDefinition (TypeDefinition type, TypeDefi

public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ partial class SupportsGLTextureAttribute

internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}

ICollection<string>? specified;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ partial class UsesConfigurationAttribute {

internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}

ICollection<string>? specified;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal string GLESVesionAsString ()

internal XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}

ICollection<string>? specified;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static IEnumerable<UsesLibraryAttribute> FromCustomAttributeProvider (ICu

public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ public static IEnumerable<UsesPermissionAttribute> FromCustomAttributeProvider (

self.specified = mapping.Load (self, attr, cache);

foreach (var e in extra)
foreach (var e in extra) {
self.specified ??= new HashSet<string> ();
self.specified.Add (e);
}

yield return self;
}
}

public XElement ToElement (string packageName, TypeDefinitionCache cache)
{
return mapping.ToElement (this, specified, packageName, cache);
return mapping.ToElement (this, specified ?? new HashSet<string> (), packageName, cache);
}

internal class UsesPermissionComparer : IEqualityComparer<UsesPermissionAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ IList<string> MergeManifest (NativeCodeGenState codeGenState, Dictionary<string,
} else if (!VersionCode.IsNullOrEmpty ()) {
manifest.VersionCode = VersionCode;
}
manifest.Assemblies.AddRange (userAssemblies.Values.Select (item => item.ItemSpec));
manifest.Assemblies?.AddRange (userAssemblies?.Values?.Where (item => item?.ItemSpec != null).Select (item => item.ItemSpec) ?? []);

if (!String.IsNullOrWhiteSpace (CheckedBuild)) {
// We don't validate CheckedBuild value here, this will be done in BuildApk. We just know that if it's
Expand All @@ -120,10 +120,10 @@ IList<string> MergeManifest (NativeCodeGenState codeGenState, Dictionary<string,
manifest.ForceExtractNativeLibs = true;
}

IList<string> additionalProviders = manifest.Merge (Log, codeGenState.TypeCache, codeGenState.AllJavaTypes, ApplicationJavaClass, EmbedAssemblies, BundledWearApplicationName, MergedManifestDocuments);
IList<string> additionalProviders = manifest.Merge (Log, codeGenState.TypeCache, codeGenState.AllJavaTypes, ApplicationJavaClass, EmbedAssemblies, BundledWearApplicationName, MergedManifestDocuments ?? []);

// Only write the new manifest if it actually changed
if (manifest.SaveIfChanged (Log, MergedAndroidManifestOutput)) {
if (!MergedAndroidManifestOutput.IsNullOrEmpty () && manifest.SaveIfChanged (Log, MergedAndroidManifestOutput)) {
Log.LogDebugMessage ($"Saving: {MergedAndroidManifestOutput}");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable disable
#nullable enable

using System;
using System.Collections.Generic;
Expand All @@ -24,7 +24,7 @@ abstract class LlvmIrFunctionBodyItem
public void Write (GeneratorWriteContext context, LlvmIrGenerator generator)
{
DoWrite (context, generator);
if (!String.IsNullOrEmpty (Comment)) {
if (!Comment.IsNullOrEmpty ()) {
context.Output.Write (' ');
generator.WriteComment (context, Comment);
}
Expand All @@ -44,14 +44,14 @@ abstract class LlvmIrFunctionLocalItem : LlvmIrFunctionBodyItem

public string Name {
get {
if (String.IsNullOrEmpty (name)) {
if (name.IsNullOrEmpty ()) {
throw new InvalidOperationException ("Internal error: name hasn't been set yet");
}
return name;
}

protected set {
if (String.IsNullOrEmpty (value)) {
if (value.IsNullOrEmpty ()) {
throw new InvalidOperationException ("Internal error: value must not be null or empty");
}
name = value;
Expand Down Expand Up @@ -84,7 +84,7 @@ protected void SetName (ulong num)
Name = num.ToString (CultureInfo.InvariantCulture);
}

protected bool NameIsSet () => !String.IsNullOrEmpty (name);
protected bool NameIsSet () => !name.IsNullOrEmpty ();
}

class LlvmIrFunctionLabelItem : LlvmIrFunctionLocalItem
Expand Down Expand Up @@ -192,11 +192,14 @@ public void Add (LlvmIrFunctionLabelItem label, string? comment = null)
previousLabel = label;

if (comment == null) {
var sb = new StringBuilder (" preds = %");
sb.Append (precedingBlock1.Name);
if (precedingBlock2 != null) {
sb.Append (", %");
sb.Append (precedingBlock2.Name);
var sb = new StringBuilder (" preds = ");
if (precedingBlock1 != null) {
sb.Append ('%');
sb.Append (precedingBlock1.Name);
if (precedingBlock2 != null) {
sb.Append (", %");
sb.Append (precedingBlock2.Name);
}
}
comment = sb.ToString ();
}
Expand Down
Loading
Loading