You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[monodroid] ensure main app assembly is loaded (#4058)
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`.
0 commit comments