When Resource Ids Are Not Recognised In A CS File

I’m using Xamarin Android for one of my current projects and (especially after my recent short break) sometimes I forget important lessons that could leave me confused and annoyed for ages.

Here’s an example of one of them:

Sometimes you need to create a new component in your axml file. You add an id and the rest of the parameters. Then you want to create the event that this button will call once clicked. So you go to a CS file, create a new variable to hold the resource and proceed to create a new event. Then the compiler catches up and you see a little red squiggly line under your resource id name 😩

Why Does This Happen?

The Resource Library is searched for the id of the new component when the code is pre-complied. The Resource Library is a file in the Android project listing all id’s of your components declared within your axml files. If the id of the component mentioned in the CS file doesn’t exist in the Resource Library, then this is highlighted as an error.

Resource Id Resolution

Comment out the use of the resource in the CS file, then do a rebuild of the project. After that, uncomment the reference of the resource in the CS file. Voila!


The new resource needs to be added into the Resource Dictionary before it’s used in other files. By commenting out it’s usage in the CS file, when the compiler checks for the resources, it won’t find it anywhere and will continue to add it the Resource Dictionary correctly without freaking out.

Coding is part banging your head against your desk, part shouting at your computer, but mostly (hopefully) part fun. It’s the fun that expires me and keeps me going when I hit those coding walls of despair. But I keep hope alive because I know I can get over it…eventually! If you code something everyday, you’ll start to hit these walls less often.

Get Up And Code Something Everyday

Being able to code something everyday is a great way to improving your development skills. Just like Jennifer Dewalt who built 180 websites in 180 days, you will slowly notice your skills improving. Things that you may have struggled with to begin with becoming easier.

The journey to building great development skills doesn’t happen overnight. I have to always remind myself of this fact. It takes time, lots and lots of time! Doing something small and short everyday helps you keep up your momentum, moves you forward little by little and keeps you motivated.