Skip to content

.NET 6: $(AndroidEnablePreloadAssemblies)=False by default #5838

Closed
@jonpryor

Description

@jonpryor

Context: d13d0f9
Context: b90d3ab
Context: PR #5790
Context: PR #5811
Context? 9e6ce03

For .NET 6 we want $(AndroidEnablePreloadAssemblies)=False by default, so that all assemblies don't need to be loaded as part of process startup.

This was done in PR #5790 / d13d0f9 , after which point we found a problem (missed during PR review, alas):

  1. .NET 6 +
  2. "Debug" build +
  3. Fast Deployment +
  4. App launch

resulted in a crash (!) in DebuggingTest.ClassLibraryMainLauncherRuns():

android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
    at MyLibrary.MainActivity.OnCreate(Bundle bundle)
    at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState)
    at com.xamarin.classlibrarymainlauncherruns.MainActivity.n_onCreate(Native Method)
    at com.xamarin.classlibrarymainlauncherruns.MainActivity.onCreate(MainActivity.java:29)

The cause of the crash is that, because not all assemblies are loaded as part of process startup, ResourceIdManager.UpdateIdValues() isn't able to update all fields in all Resource types to have the values from the app Resource.designer.cs file. Consequently, the values may be invalid, thus the NullReferenceException.

In order to actually default $(AndroidEnablePreloadAssemblies)=False for .NET 6, we need to figure out how to make this work.

Perhaps we can enable $(AndroidLinkResources)=True (9e6ce03) for all .NET 6 builds? What would the build-time impacts be?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions