Xamarin Forms: Public C# Properties Missing on Android

While working on the mobile apps for McAllen Next (my new side project, stay tuned for more soon!), I discovered a very strange issue when running the app on Android; I kept getting repeated errors like this:

Binding: ‘IsLoading’ property not found on ‘RegionModel’, target property: ‘Xamarin.Forms.Label’

and as such, the UI would not bind and would render an empty label (or not at all, depending on the control).

At first I thought it was because the app wasn’t rebuilding properly, resulting in stale binaries as was suggested in a StackOverflow post I found while trying to find a fix.

Eventually I posted my own question about this issue and I swear before two minutes passed, I was provided the solution by a very helpful user Gusman.

Turns out I had the box checked in the Android properties for the project to link both SDK and User assemblies.


Apparently this optimizes the selected assemblies, removing references to properties that the linker detects are not in use.

I don’t remember much from my college days when we built a compiler, but although optimization sounds great, completely deleting references is strange to me, especially if they’re going to be bound at runtime to the XAML as they are when working with Xamarin Forms…

But hey I’m not a compiler builder, so I changed the option to only link SDK assemblies, and everything is back to normal!

As always, I hope this is helpful, and thanks for reading!

Quick Fix: Unwanted Rounding When String Formatting Number as Currency

Sometimes it’s the little things you forget the easiest and most often that throw you for a loop. Today I was attempting to show a value in an ASP.NET MVC View which is stored as type long, representing a monetary amount in cents.

I formatted it as currency:

@string.Format("{0:c}", Model.Subtotal / 100)

But when I saw the output it rounded the value of 1250 to $12.00. This was strange since it was rounding down instead of up, which would still be incorrect, but at least make sense.

In an attempt to fix, I added a decimal place to the formatting:

@string.Format("{0:c2}", Model.Subtotal / 100)

But apparently currency is already set to two decimals. I can add more decimals, but it will always be zero, since it’s rounding.

I then realized that the Subtotal is long, which is an integer, as is of course 100, so it’s doing integer division. I need to cast one of the values to ensure the result doesn’t round. I defined the 100 value as a decimal by adding M at the end:

@string.Format("{0:c}", Model.Subtotal / 100M)

which revealed the expected output of $12.50 and I can go about my day.

It’s all so obvious in retrospect, but it’s one of those things that is easily forgotten. hopefully this note will help me remember!

as always, hope this was helpful and thanks for reading!