xamarin forms error Droid.Resource does not contain a definition for string
Asked Answered
H

3

7

This is where the problem is - red lines under "String".

I´m developing a xamarin forms application, and i'm using the PCL Storage plugin.. I think this is whats causing the problem somehow, and i don't know how to fix it. The problem occurs in my Android solution.

public static void UpdateIdValues()
{
    global::PCLStorage.Resource.String.ApplicationName = global::XamarinClients.Droid.Resource.String.ApplicationName;
    global::PCLStorage.Resource.String.Hello = global::XamarinClients.Droid.Resource.String.Hello;
}

I get this error :

Error 6 'XamarinClients.Droid.Resource' does not contain a definition for 'String' pathtomyapplication\Resources\Resource.Designer.cs

Anyone had this problem?

Hanzelin answered 2/12, 2015 at 12:24 Comment(2)
This is most likely an error while generating the Resource file. Are you using Xamarin Studio or Visual Studio? I've had big headaches with Xamarin Studio for MacKernite
I'm using visual studio. I commented the lines out, but id really like to know what was the cause of the error..Hanzelin
E
14

If you look in the android documentation for localization it mentions storing application resource string in an xml file. Apparently there are some hard coded values in the android Xamarin.Forms Resource.Designer.cs. To fix it in the resources folder under values add an XML file named String.xml and in it put:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="ApplicationName">ApplicationName</string>
  <string name="Hello">Hello</string>
</resources>
Eldoraeldorado answered 27/1, 2016 at 2:52 Comment(1)
Also, set Build Action of strings.xml to AndroidResourceDynode
G
1

I know this is an old post, but I still get this error in VS2019. It usually happens when I am lazy and Ctrl-D one string definition in strings.xml and then retype the string name and content to the new string.

The program builds fine but I still get the doesn't-contain-definition error even after applying any of the suggestions above.

My solution is to copy and delete the line that I just created, then paste it somewhere else in strings.xml. Then the error goes away instantly.

This can also happen if I add a menu item to menu_main.xml. The project builds fine but I still get the wiggly red line under the menu item id in the code that refers to it. Go back to menu_main.xml, copy the item, delete it, paste it back again. Red line goes away.

Gleet answered 29/3, 2021 at 7:17 Comment(0)
V
0

Often, this can be resolved by simply Cleaning the project and then choosing Rebuild.

Volcanism answered 15/8, 2016 at 13:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.