Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding String resource to .resx in PCL causes compilation error

I have a resources file in my portable class library which is currently holding around 30 strings. They are accessible from my Windows Phone 8 app and the strings that are already in the file work fine.

However, now when I try to add a new string as I did before it causes a compilation error:

'System.Type' does not contain a definition for 'Assembly' and no extension method 'Assembly' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)

Looking in the .designer.cs file it's clear that this is the problem. When a new string is added two changes occur:

  • using System.Reflection; disappears
  • `global::System.Resources.ResourceManager("ViewModels.Resources.StringResources", typeof(StringResources).Assembly); appears in place of:

    new global::System.Resources.ResourceManager("ViewModels.Resources.StringResources", typeof(StringResources).GetTypeInfo().Assembly);

The .GetTypeInfo() and disappearing using statement are the problem but I can't put them back because the file is generated by visual studio and changes back. Any ideas?

The only significant change I can think of is the new Visual Studio 2012 update 2?

Also worth noting: If I add another resx anywhere else in the project (the wp8 app or another pcl) then this exhibits the exact same behaviour when adding a string.

like image 264
James Mundy Avatar asked Nov 12 '22 07:11

James Mundy


1 Answers

It seems that for the time being this is a bug in Visual Studio after Update 2. Please see here for more details:

https://connect.microsoft.com/VisualStudio/feedback/details/783211/resx-file-unable-to-be-edited-correctly-causes-compilation-error-in-generated-designer-file-after-vs2012-update-2#tabs

like image 183
James Mundy Avatar answered Nov 14 '22 21:11

James Mundy