Bug 30044 - Resource.resx are generated with incorrect namespace
Summary: Resource.resx are generated with incorrect namespace
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Project Model ()
Version: 5.9
Hardware: PC Mac OS
: Normal normal
Target Milestone: (C7)
Assignee: Bugzilla
URL:
: 30170 ()
Depends on:
Blocks:
 
Reported: 2015-05-13 14:32 UTC by John Miller [MSFT]
Modified: 2015-06-27 07:36 UTC (History)
5 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description John Miller [MSFT] 2015-05-13 14:32:06 UTC
**Overview:**

   The generated ResourceManager code in the .Designer files is not using the correct namespaces after updating to XS 5.9. 

**Steps to Reproduce:**

   Can attempt creating resources per http://developer.xamarin.com/guides/cross-platform/xamarin-forms/localization/

**Actual Results:**

   For an example, see private comment below. 

**Expected Results:**

   The namespaces should match. 

**Build Date & Platform:**

   XS 5.9 (Cycle 5 update)
Comment 2 Matt Ward 2015-05-14 09:26:48 UTC
Looks like there was a change made for XS 5.9:

https://github.com/mono/monodevelop/commit/946ae56dd9261798f743807f4a7a99de6340f914

The change means that the resource namespace is the project's default namespace, not the tool namespace.

Xamarin Studio has different behaviour to Visual Studio when the resource file (.resx) is in a subdirectory. Visual Studio includes the subdirectory as part of the resource name name.

To repro:

1) Create a new project
2) Change project's default namespace to DefaultNamespace
3) Add new FooBar directory to project.
4) Add new resource file to the project called Resources.resx
5) Open the Resource.Designer.cs file.


Visual Studio will create code that uses the default namespace and the folder name:

  namespace DefaultNamespace.FooBar {

  new global::System.Resources.ResourceManager("DefaultNamespace.FooBar.Resource", typeof(Resource).Assembly);

Xamarin Studio just uses the project's default namespace:


  namespace DefaultNamespace {

  new global::System.Resources.ResourceManager("DefaultNamespace.Resource"


So the only workaround currently would be to change the default namespace of the project.
Comment 3 Matt Ward 2015-05-20 07:16:30 UTC
Xamarin Studio 6.0.0.683 (master) should now allow the .NET naming policy to be applied to the resource name.

Fixed in commit:

https://github.com/mono/monodevelop/commit/6ecaa7c462e117fbdca9d3ebf63f546c9d598978

Another workaround for Xamarin Studio 5.9 without this fix would be to change the Resource ID on the .resx file so it matches the name used in the generated code.
Comment 4 Mikayla Hutchinson [MSFT] 2015-05-20 20:42:24 UTC
This'll only work correctly if the project's policy has the VS namespace and resource name behaviour.

I made a PR that fixes this - https://github.com/mono/monodevelop/pull/912/commits
Comment 5 Matt Ward 2015-05-21 04:10:04 UTC
*** Bug 30170 has been marked as a duplicate of this bug. ***
Comment 6 Matt Ward 2015-05-21 13:14:10 UTC
mhutch's pull request has been merged and should be available in Xamarin Studio 6.0.0.2307
Comment 7 Alessandro 2015-06-24 19:26:59 UTC
Sorry.
I have had this problem  and (in XS) I have change manually this line in AppResources.Designer.cs

                   System.Resources.ResourceManager temp = new System.Resources.ResourceManager("IWapp.AppResources", typeof(AppResources).GetTypeInfo().Assembly);
 

to

                   System.Resources.ResourceManager temp = new System.Resources.ResourceManager("IWapp.Resx.AppResources", typeof(AppResources).GetTypeInfo().Assembly);
 

Today, I have this exception:

[MonoDroid] System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "IWapp.Resx.AppResources.resources" was correctly embedded or linked into assembly "RilevazionePresenze" at compile time, or that all the satellite assemblies required are loadable and fully signed.
[MonoDroid] at System.Resources.ResourceManager.AssemblyResourceMissing (string) <IL 0x00053, 0x00147>
[MonoDroid] at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo,bool,bool) <IL 0x00140, 0x0054b>
[MonoDroid] at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo,bool,bool) <IL 0x00213, 0x00920>
[MonoDroid] at System.Resources.ResourceManager.GetString (string,System.Globalization.CultureInfo) <IL 0x00032, 0x00137>
[MonoDroid] at IWapp.Resx.AppResources.get_StringAttendi () [0x00010] in /Users/alessandrocaliaro/Projects/Soluzione1/IWapp/IWapp/Resx/AppResources.Designer.cs:370
[MonoDroid] at IWapp.App/<VisualizzaMenuPrincipale>c__async0.<>m__0 () [0x00005] in /Users/alessandrocaliaro/Projects/Soluzione1/IWapp/IWapp/IWApp.cs:112
[MonoDroid] at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
[MonoDroid] at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.IRunnable.cs:71
[MonoDroid] at (wrapper dynamic-method) object.0c66d232-c022-46cb-a9d9-c317d1972415 (intptr,intptr) <IL 0x00011, 0x0001f>


But IWapp.Resx.AppResources is correct in Resources.Designer.cs
Comment 8 Alessandro 2015-06-24 19:28:29 UTC
How can I do this?

Another workaround for Xamarin Studio 5.9 without this fix would be to change
the Resource ID on the .resx file so it matches the name used in the generated
code.
Comment 9 Matt Ward 2015-06-25 06:19:28 UTC
The name of the resource can be changed if right click the .resx file in the Solution window, select Properties, then specify the name in the Resource ID text box.

So if you have the string "IWapp.Resx.AppResources" in your designer.cs file then the Resource ID should be "IWapp.Resx.AppResources.resources".

Changing the designer.cs code by hand you will need to be aware that if you change the .resx file and save it the designer.cs code will be modified and you may lose your changes.
Comment 10 Alessandro 2015-06-26 16:00:44 UTC
Matt, I've take a look at your suggestion.

In resx "property", text box "Resource ID", I have IWapp.Resx.AppResources.resources
In Designer.cs, I have                     System.Resources.ResourceManager temp = new System.Resources.ResourceManager("IWapp.Resx.AppResources", typeof(AppResources).GetTypeInfo().Assembly);

The Exception is

MonoDroid] System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "IWapp.Resx.AppResources.resources" was correctly embedded or linked into assembly "RilevazionePresenze" at compile time, or that all the satellite assemblies required are loadable and fully signed.


What do I have to change to solve?
Thanks for your help
Alessandro
Comment 11 Matt Ward 2015-06-27 05:06:11 UTC
Without seeing your project it is difficult to know. To repro your scenario I did the following:

1. Create a new Android project
2. Created a Resx directory in the root of the project
3. Add a resource file AppResources.resx inside the Resx directory.
4. Add a simple resource string to the .resx file.
5. Referenced the AppResources class in the MainActivity.
6. Running the app here fails since the resource is being embedded with the name MyProject.Resx.AppResources.resources but the designer.cs file is not using that name.
7. Edit the .designer.cs file to use "MyProject.Resx.AppResources" instead of "MyProject.AppResources"
8. Build and run the app again.
9. The resource is found and the app runs without any errors.

My .csproj file has:

<EmbeddedResource Include="Resx\AppResources.resx">
  <Generator>ResXFileCodeGenerator</Generator>
  <LastGenOutput>AppResources.Designer.cs</LastGenOutput>
</EmbeddedResource>

If you modify the Resource ID in properties then you can also see a LogicalName element inside the EmbeddedResource. In my case this would need to <LogicalName>MyProject.Resx.AppResources.resources</LogicalName>. However you may not need this element, in my test case I did not have this element in my project file.

So my only guess would be that the build action for the .resx file is not set to be embedded resource.
Comment 12 Alessandro 2015-06-27 07:36:00 UTC
I don't know.
By now, to solve the situation, I've renamed .resx and now it's ok
Thanks
Alessandro