Bug 9395 - Resource LIbrary Id's
Summary: Resource LIbrary Id's
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.4.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2013-01-08 11:00 UTC by jonathan_chapman
Modified: 2013-01-09 11:22 UTC (History)
1 user (show)

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:

Description jonathan_chapman 2013-01-08 11:00:29 UTC
I have a library that contains resources.  When the class is called from the application the layout id's and widget id's are incorrect.

For example:

In the library I have an activity that calls SetContentView(Resource.Layout.login).  Instead of the correct layout being displayed the layout it is displaying is the layout that corresponds to the number defined in the application's Resource.Designer.cs (CustomerDetail).

In the Library I have: 
public static int login = 2130903059;

In the application I have: 
public const int CustomerDetail = 2130903059;
public const int login = 2130903110;

If I change the code to SetContentView(2130903110) then it works.

Clearly a disjoint in the compiler in determining what the value should be.

I don't see a work around and I need this ASAP as this proper library functionality is mandatory for the project that I'm in the middle of.

Comment 1 jonathan_chapman 2013-01-08 11:13:06 UTC
Of further note when debugging, SetContentView(Resource.Layout.login) is showing 2130903110 in quick watch because it is getting confused between Library.Resource.Layout and Application.Resource.Layout. i.e. quick watch is showing Application.Resource.Layout instead of Library.Resource.Layout.
Comment 2 jonathan_chapman 2013-01-08 11:31:24 UTC
I was able to figure it out.  I needed to call Resource.UpdateIdValues() in the constructor of my main activity.  Is there no way that this could be done automatically?
Comment 3 Atsushi Eno 2013-01-09 11:22:35 UTC
Oops! You're right, thanks for pointing it out. I totally forgot to add resource ID initializer code as in each resource designer's static constructor. It is fixed in our codebase and will be included in the next major release.

Until the fix arrives, please add call to Android.Runtime.ResourceIdManager.UpdateIdValues() somewhere around your app bootstrap (I added this method exactly for this purpose).