Bug 9395 - Resource LIbrary Id's
Summary: Resource LIbrary Id's
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings (show other bugs)
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)

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


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).

Note You need to log in before you can comment on or make changes to this bug.