Xamarin and Resource.Designer.cs

I am doing a lot of development using Xamarin for Android and while most of the time it works really well, there are a few circumstances where it acts a little weirdly.

The first is when naming resources. The Xamarin documentation states the following in a resource on their website:

[blockquote source=”Xamarin”]Also, it’s important to note that while Android only supports lowercase filenames for resource items, Xamarin.Android is a bit more forgiving; it will support both uppercase and lowercase filenames.[/blockquote]

While this is true for most items it doesn’t work across the board. When naming drawable resources likes shapes or bitmaps and referring to them from a style I cannot use uppercase characters. I am from a C# background so I find it hard to let go of Pascal case for naming my files. If I name a file

TextRectangle.xml_ _I don’t seem to be able to reference it from a style like so:

[syntax type=”html php js css”]


If instead I rename the file to text_rectangle.xml I’m all good in the hood. This messes with my OCD a little as everything is Pascal case except for a handful of drawable resources sprinkled through the solution.

The next weird issue I have encountered is a situation that can occur with the Resource.Designer.cs file. This file is automatically generated to give static access to all of the layout elements available. This is described as the following:

**[blockquote source=”Xamarin”]Resource.designer.cs** – This file is automatically generated and maintained by Xamarin.Android and holds the unique ID’s assigned to each resource. This is very similar and identical in purpose to the R.java file that an Android application written in Java would have. It is automatically created by the Xamarin.Android tools and will be regenerated from time to time.[/blockquote]

If this ever doesn’t rebuild correctly I read that you can just delete it and it will be rebuilt on the next project compilation. This is true but when you add it back to the project after it is rebuilt, something strange will happen. The next compilation will fail with an obscure error in aapt.exe with the description, “Invalid resource directory name: “resource.designer.cs”. I found a few references to this error but couldn’t figure out exactly what had gone wrong. After an hour or two of tearing my hair out I compared the project file to a previous version and realised that the build action had been set to AndroidResource when I re-added it the file. This file’s build action should be set to Compile and when I specified this everything returned to normal.

droid error{.lightbox}

I understand that these are a couple of pretty specific issues but if they help someone else then it will have been time well spent writing this up…