Skip to content

Maui .NET 8 => .NET 9 linker issue #1347

@jdlegan

Description

@jdlegan

Description

I ported a Maui .NET 8 application to .NET 9 yesterday due to the impending Android API 35 edict, While the migration went ok and required little in the way of changes and iOS is building/publishing correctly, I have hit an issue with the compilation/linking which I cannot find any guidance online regarding. Issue is reproducible in both Windows and Mac build environments. Initially the error was vague and indicated an AOT issue, even with MONO_LOG_LEVEL set to debug. Either switching to a debug build or disabling AOT in a release build provides a much more concrete error, but its root causal is still unclear. Does anyone have any insight into what might be causing it?

C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.78\tools\Xamarin.Android.Common.targets(1503,3): error XAGJS7000:
      System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
       ---> System.NullReferenceException: Object reference not set to an instance of an object.
         at Java.Interop.Tools.Cecil.CustomAttributeProviderRocks.GetCustomAttributes(ICustomAttributeProvider item, String attribute_fullname)+MoveNe
      xt() in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/CustomAttributeProvid
      erRocks.cs:line 30
         at System.Linq.Enumerable.IEnumerableSelectIterator`2.MoveNext()
         at System.Linq.Enumerable.IEnumerableWhereSelectIterator`2.MoveNext()
         at Java.Interop.Tools.JavaCallableWrappers.Utilities.CecilExtensions.GetTypeRegistrationAttributes(ICustomAttributeProvider p)+MoveNext() in
      /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers
      /CecilExtensions.cs:line 159
         at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
         at Java.Interop.Tools.JavaCallableWrappers.Adapters.CecilImporter.CreateType(TypeDefinition type, IMetadataResolver resolver, CallableWrapper
      ReaderOptions options, String outerType) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.JavaCallableWrap
      pers/Java.Interop.Tools.JavaCallableWrappers.Adapters/CecilImporter.cs:line 67
         at Java.Interop.Tools.JavaCallableWrappers.Adapters.CecilImporter.CreateType(TypeDefinition type, IMetadataResolver resolver, CallableWrapper
      ReaderOptions options) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.
      Tools.JavaCallableWrappers.Adapters/CecilImporter.cs:line 19
         at Xamarin.Android.Tasks.JCWGenerator.CreateGenerator(TypeDefinition type, MarshalMethodsClassifier classifier, String monoInit, Boolean hasE
      xportReference, String applicationJavaClass) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs
      :line 183
         at Xamarin.Android.Tasks.JCWGenerator.ProcessTypes(Boolean generateCode, String androidSdkPlatform, MarshalMethodsClassifier classifier, Stri
      ng outputPath, String applicationJavaClass) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs:
      line 110
         at Xamarin.Android.Tasks.JCWGenerator.GenerateAndClassify(String androidSdkPlatform, String outputPath, String applicationJavaClass) in /User
      s/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs:line 83
         at Xamarin.Android.Tasks.GenerateJavaStubs.GenerateJavaSourcesAndMaybeClassifyMarshalMethods(AndroidTargetArch arch, Dictionary`2 assemblies,
       Dictionary`2 userAssemblies, Boolean useMarshalMethods, Boolean generateJavaCode) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android
      .Build.Tasks/Tasks/GenerateJavaStubs.cs:line 386
         at Xamarin.Android.Tasks.GenerateJavaStubs.<>c__DisplayClass146_0.<Run>b__0(KeyValuePair`2 kvp) in /Users/runner/work/1/s/xamarin-android/src
      /Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs:line 202
         at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean
      & replicationDelegateYieldedBeforeCompletion)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean
      & replicationDelegateYieldedBeforeCompletion)
         at System.Threading.Tasks.TaskReplicator.Replica.Execute()
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
         at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 s
      impleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Ac
      tion`1 localFinally)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 s
      impleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Ac
      tion`1 localFinally)
         at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action
      `2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinal
      ly)
         at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Action`1 body)
         at Xamarin.Android.Tasks.GenerateJavaStubs.Run(Boolean useMarshalMethods) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build
      .Tasks/Tasks/GenerateJavaStubs.cs:line 194
         at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/Generate
      JavaStubs.cs:line 102
         at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft
      .Android.Build.BaseTasks/AndroidTask.cs:line 25

Reproduction Steps

Cannot reproduce the issue with a new project currently, may be configuration related but have eliminated as many differences as possible.

Expected behavior

Compilation and linking works as it did with .NET 8 and Android 34

Actual behavior

Unable to compile.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions