Skip to content

Conversation

@jonathanpeppers
Copy link
Member

Fixes: https://developercommunity.visualstudio.com/content/problem/788217/xamarin-android-resource-ids-mismatch-1.html

In a project where:

  • The MainLauncher activity is in a class library
  • This activity uses a value from Resource.designer.cs

You get a crash such as:

UNHANDLED EXCEPTION:
Android.Content.Res.Resources+NotFoundException: Resource ID #0x7f09001c
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0
at Android.App.Activity.SetContentView (System.Int32 layoutResID) [0x00022] in <82e50ec67af648c3b9f43b3d70e21b96>:0
at ClassLibrary1.SharedActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00011] in <aff3f2d8f15f4b618f6674d9c306f099>:0
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <82e50ec67af648c3b9f43b3d70e21b96>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.4(intptr,intptr,intptr)
--- End of managed Android.Content.Res.Resources+NotFoundException stack trace ---
android.content.res.Resources$NotFoundException: Resource ID #0x7f09001c
    at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237)
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2281)
    at android.content.res.Resources.getLayout(Resources.java:1175)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
    at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at crc64fd99288c2cd04dcf.SharedActivity.n_onCreate(Native Method)
    at crc64fd99288c2cd04dcf.SharedActivity.onCreate(SharedActivity.java:30)
    at android.app.Activity.performCreate(Activity.java:7802)
    at android.app.Activity.performCreate(Activity.java:7791)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

In this example App1.dll is the main app assembly, but
ClassLibrary1.SharedActivity is the MainLauncher.

What was strange is that when I looked at the list of assemblies in
AppDomain.CurrentDomain.GetAssemblies () before the failure,
App1.dll was not in the list!

So I enabled a bunch of logging:

adb shell setprop debug.mono.log default,assembly,timing

The log messages like this did not mention App1.dll:

12-19 09:11:44.425 22695 22695 I monodroid-assembly: open_from_update_dir: loaded assembly: 0x7723bca880
12-19 09:11:44.425 22695 22695 I monodroid-timing: Assembly load: ClassLibrary1.dll preloaded; elapsed: 0s:1::252032

Which lead me to this code:

/* skip element 0, as that's loaded in create_domain() */
for (size_t i = 1; i < assemblies.get_length (); ++i) {

I don't actually see anything in create_domain that would load
App1.dll? Looking through the commit history I don't understand how
this project would have ever worked?

Changing i = 1 to i = 0 solves the crash in the project. However,
there might be a better fix here.

@jonpryor
Copy link
Contributor

Unit test? :-D

This should add a Documentation/release-notes/4058.md file which lists the bug fix.

@jonathanpeppers
Copy link
Member Author

Unit test? :-D

I'll look into this after the holiday. I sent this as a start, because I was not sure about it. @grendello might know more then, too.

Fixes: https://developercommunity.visualstudio.com/content/problem/788217/xamarin-android-resource-ids-mismatch-1.html

In a project where:

* The `MainLauncher` activity is in a class library
* This activity uses a value from `Resource.designer.cs`

You get a crash such as:

    UNHANDLED EXCEPTION:
    Android.Content.Res.Resources+NotFoundException: Resource ID #0x7f09001c
    at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0
    at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0
    at Android.App.Activity.SetContentView (System.Int32 layoutResID) [0x00022] in <82e50ec67af648c3b9f43b3d70e21b96>:0
    at ClassLibrary1.SharedActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00011] in <aff3f2d8f15f4b618f6674d9c306f099>:0
    at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <82e50ec67af648c3b9f43b3d70e21b96>:0
    at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.4(intptr,intptr,intptr)
    --- End of managed Android.Content.Res.Resources+NotFoundException stack trace ---
    android.content.res.Resources$NotFoundException: Resource ID #0x7f09001c
        at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237)
        at android.content.res.Resources.loadXmlResourceParser(Resources.java:2281)
        at android.content.res.Resources.getLayout(Resources.java:1175)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at crc64fd99288c2cd04dcf.SharedActivity.n_onCreate(Native Method)
        at crc64fd99288c2cd04dcf.SharedActivity.onCreate(SharedActivity.java:30)
        at android.app.Activity.performCreate(Activity.java:7802)
        at android.app.Activity.performCreate(Activity.java:7791)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

In this example `App1.dll` is the main app assembly, but
`ClassLibrary1.SharedActivity` is the `MainLauncher`.

What was strange is that when I looked at the list of assemblies in
`AppDomain.CurrentDomain.GetAssemblies ()` before the failure,
`App1.dll` was not in the list!

So I enabled a bunch of logging:

    adb shell setprop debug.mono.log default,assembly,timing

The log messages like this did not mention `App1.dll`:

    12-19 09:11:44.425 22695 22695 I monodroid-assembly: open_from_update_dir: loaded assembly: 0x7723bca880
    12-19 09:11:44.425 22695 22695 I monodroid-timing: Assembly load: ClassLibrary1.dll preloaded; elapsed: 0s:1::252032

Which lead me to this code:

    /* skip element 0, as that's loaded in create_domain() */
    for (size_t i = 1; i < assemblies.get_length (); ++i) {

I don't actually see anything in `create_domain` that would load
`App1.dll`? Looking through the commit history I don't understand how
this project would have ever worked?

Changing `i = 1` to `i = 0` solves the crash in the project. However,
there might be a better fix here.

I added a test that reproduces the issue. I also added a
`SetTargetFrameworkAndManifest` helper method to cleanup
`DebuggingTest.cs`.
@jonathanpeppers jonathanpeppers force-pushed the resourceidmanager-assembly-loading branch from eedcbfe to ad5cf6b Compare January 2, 2020 15:37
@jonathanpeppers
Copy link
Member Author

The MSBuild w/ emulator job is doing something weird:

OneTimeSetUp: System.TypeInitializationException : The type initializer for 'SetUp' threw an exception.

----> System.TypeLoadException : Could not load type of field 'Xamarin.ProjectTools.Builder:<Verbosity>k__BackingField' (7) due to: Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

I'm not sure how this PR would break this, but I'll try restarting.

@jonathanpeppers
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonathanpeppers
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonpryor jonpryor merged commit 807e665 into dotnet:master Jan 7, 2020
jonpryor pushed a commit that referenced this pull request Jan 7, 2020
Fixes: https://developercommunity.visualstudio.com/content/problem/788217/xamarin-android-resource-ids-mismatch-1.html

In a project where:

 1. The `MainLauncher` activity is in a class library
 2. This activity uses a value from `Resource.designer.cs`

You get a crash such as:

	UNHANDLED EXCEPTION:
	Android.Content.Res.Resources+NotFoundException: Resource ID #0x7f09001c
	at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0
	at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0
	at Android.App.Activity.SetContentView (System.Int32 layoutResID) [0x00022] in <82e50ec67af648c3b9f43b3d70e21b96>:0
	at ClassLibrary1.SharedActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00011] in <aff3f2d8f15f4b618f6674d9c306f099>:0
	at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <82e50ec67af648c3b9f43b3d70e21b96>:0
	at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.4(intptr,intptr,intptr)
	--- End of managed Android.Content.Res.Resources+NotFoundException stack trace ---
	android.content.res.Resources$NotFoundException: Resource ID #0x7f09001c
	    at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237)
	    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2281)
	    at android.content.res.Resources.getLayout(Resources.java:1175)
	    at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
	    at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
	    at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
	    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
	    at crc64fd99288c2cd04dcf.SharedActivity.n_onCreate(Native Method)
	    at crc64fd99288c2cd04dcf.SharedActivity.onCreate(SharedActivity.java:30)
	    at android.app.Activity.performCreate(Activity.java:7802)
	    at android.app.Activity.performCreate(Activity.java:7791)
	    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
	    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
	    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
	    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
	    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
	    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
	    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
	    at android.os.Handler.dispatchMessage(Handler.java:107)
	    at android.os.Looper.loop(Looper.java:214)
	    at android.app.ActivityThread.main(ActivityThread.java:7356)
	    at java.lang.reflect.Method.invoke(Native Method)
	    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
	    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

In this example `App1.dll` is the main app assembly, but
`ClassLibrary1.SharedActivity` is the `MainLauncher`.

What was strange is that when I looked at the list of assemblies in
`AppDomain.CurrentDomain.GetAssemblies ()` before the failure,
`App1.dll` was not in the list!

So I enabled a bunch of logging:

	adb shell setprop debug.mono.log default,assembly,timing

The log messages like this did not mention `App1.dll`:

	I monodroid-assembly: open_from_update_dir: loaded assembly: 0x7723bca880
	I monodroid-timing: Assembly load: ClassLibrary1.dll preloaded; elapsed: 0s:1::252032

Which lead me to this code:

	/* skip element 0, as that's loaded in create_domain() */
	for (size_t i = 1; i < assemblies.get_length (); ++i) {

I don't actually see anything in `create_domain()` that would load
`App1.dll`?  Looking through the commit history I don't understand
how this project would have ever worked?

Changing `i = 1` to `i = 0` solves the crash in the project.

I added a test that reproduces the issue.  I also added a
`DebuggingTest.SetTargetFrameworkAndManifest()` helper method to
cleanup `DebuggingTest.cs`.
@jonathanpeppers jonathanpeppers deleted the resourceidmanager-assembly-loading branch January 7, 2020 22:21
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants