Bug 40214 - System.InvalidProgramException: Invalid IL code in OnCreateViewHolder
Summary: System.InvalidProgramException: Invalid IL code in OnCreateViewHolder
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 6.0.1 (C6SR1)
Hardware: PC Windows
: --- critical
Target Milestone: 6.1 (C7)
Assignee: Radek Doulik
URL:
Depends on:
Blocks:
 
Reported: 2016-04-07 18:14 UTC by Stadnik Piotr
Modified: 2016-04-14 20:02 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Stadnik Piotr 2016-04-07 18:14:22 UTC
# Steps to reproduce
I've created a dedicated repo with sample project to reproduce this bug here: 
https://github.com/lazybitch/xamarin-sample-recycler-view

Application starts w/o problems with v4.0.1.147 and thorws an error with v4.0.3.214

I'm using RecyclerView with custom RecyclerView.Adapter, and during run-time when I try to attach handler to my custom action an exception is thrown.

Custom adapter:
https://github.com/lazybitch/xamarin-sample-recycler-view/blob/master/Xamarin.Sample/AbstractRecyclerAdapter.cs

During runtime this in this line:
viewHolder.OnItemClick += HandleItemClick;

This exception is thrown:
System.InvalidProgramException: Invalid IL code in 

# Supplemental info (logs, images, videos)
04-07 17:48:09.515 D/OpenGLRenderer( 2146): Enabling debug mode 0
An unhandled exception occured.
04-07 17:48:12.591 D/Mono    ( 2146): DllImport attempting to load: '/system/lib/liblog.so'.
04-07 17:48:12.591 D/Mono    ( 2146): DllImport loaded library '/system/lib/liblog.so'.
04-07 17:48:12.591 D/Mono    ( 2146): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
04-07 17:48:12.591 D/Mono    ( 2146): Searching for '__android_log_print'.
04-07 17:48:12.591 D/Mono    ( 2146): Probing '__android_log_print'.
04-07 17:48:12.591 D/Mono    ( 2146): Found as '__android_log_print'.
04-07 17:48:12.591 I/MonoDroid( 2146): UNHANDLED EXCEPTION:
04-07 17:48:12.591 I/MonoDroid( 2146): System.InvalidProgramException: Invalid IL code in Xamarin.Sample.AbstractRecyclerAdapter`2<TKey_REF, TValue_REF>:OnCreateViewHolder (Android.Views.ViewGroup,int): IL_0040: stloc.2   
04-07 17:48:12.591 I/MonoDroid( 2146):   at Android.Support.V7.Widget.RecyclerView+Adapter.n_OnCreateViewHolder_Landroid_view_ViewGroup_I (IntPtr jnienv, IntPtr native__this, IntPtr native_parent, Int32 viewType) [0x00011] in <filename unknown>:0 
04-07 17:48:12.591 I/MonoDroid( 2146):   at (wrapper dynamic-method) System.Object:5c6e383e-022f-41cc-91ee-b783d994f5f4 (intptr,intptr,intptr,int)
04-07 17:48:12.595 I/dalvikvm( 2146): Could not find method java.lang.Throwable.<init>, referenced from method md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable.<init>
04-07 17:48:12.595 W/dalvikvm( 2146): VFY: unable to resolve direct method 19226: Ljava/lang/Throwable;.<init> (Ljava/lang/String;Ljava/lang/Throwable;ZZ)V
04-07 17:48:12.595 D/dalvikvm( 2146): VFY: replacing opcode 0x70 at 0x0000
An unhandled exception occured.

# Test environment (full version information)
Visual Studio Enterprise 2015 Version 14.0.24720.00 Update 1
Windows 10 Enterprise
Xamarin.VisualStudio 4.0.3.214
Comment 1 Rodrigo Kumpera 2016-04-11 22:55:34 UTC
Hey Radek,

Any news on this bug? Is it XA specific or a runtime/compiler issue?
Comment 2 Radek Doulik 2016-04-12 13:49:20 UTC
Piotr, could you please attach archive with content of the obj/ directory in your project?
Comment 3 Radek Doulik 2016-04-12 13:53:13 UTC
Rodrigo, looks like runtime/compiler issue to me. The XA linker adds only Newobj and Throw opcodes so far, so if the broken IL is the "IL_0040: stloc.2" then it might be compiler.

It will be clearer once we have the actual assembly.
Comment 4 Rodrigo Kumpera 2016-04-12 17:39:14 UTC
Ok, I'm CC'ing Marek on this one in case it's a mcs issue.
Comment 5 Marek Safar 2016-04-13 18:14:10 UTC
I cannot compile the project. Could you upload project with correct references or at least compiled bin/ folder output?
Comment 6 Stadnik Piotr 2016-04-13 18:31:23 UTC
Hi, I've just updated the hint path of references.
Comment 7 Marek Safar 2016-04-13 19:18:56 UTC
I cannot reproduce it using the latest alphas
Comment 8 Rustam Zaitov 2016-04-14 20:01:51 UTC
I verified this app with builds from C7 and I am not able to reproduce the issue.

Env info: https://gist.github.com/a5e233e2ab47e1348003007476f5163f