开发者

Trouble in Visual Studio 2010, changing resources is setting the constructor to internal

I am experiencing some weird behavior of Visual Studio 2010 when developing Silverlight applicat开发者_开发百科ions and using project resources (.resx)

Everytime I change a resource it sets itself to internal instead of public in the code behind, altough I can see it in the design mode as set to public it is not.

Any idea how to fix this?

I don't know if this affects only Silverlight projects or generaly all C# projects.


This link might help.

http://blogs.msdn.com/b/silverlight_sdk/archive/2010/09/08/ach-du-lieber-a-tour-of-some-localization-gotchas-in-silverlight.aspx

It says:

Turns out there's a flaw in the VS build action logic here; unfortunately changing this tool action will NOT flip the access level of the class constructor from internal to public (at least not for a strongly typed language). A public constructor is another requirement of Silverlight XAML usage of a class. You will have to do this yourself manually in the designer.cs file.

Hope this helps

EDIT:-

Here's another one http://www.wintellect.com/CS/blogs/jprosise/archive/2010/06/21/dynamic-localization-in-silverlight.aspx that says

Finally, Visual Studio suffers from a long-standing bug that leaves the constructor of the ResourceManager wrapper class it generates marked internal when you change the class's access modifier to public. This means that whenever you modify the primary RESX file, forcing a code regen, you have to manually change internal to public on the constructor in the generated code. It beats me why this hasn't been fixed after all these years, but it hasn't.


My approach consists in configuring a pre-build event that replaces "internal" with "public" in your .Designer.cs file. I have a post on my blog about the whole process, from creating the localized string to binding them and configuring the pre-build event command line.

The hearth of the process is to get a text-file replace utility (say it's called REPLACE.EXE) and set a pre-build action like this:

c:\utility\replace\replace.exe "$(ProjectDir)\LocalizedStrings.Designer.cs" "internal" "public"

$(ProjectDir) is a VS built-in macro that returns the path to your project folder.

I also gave an example of such a simple replace utility source code on same post.


The best solution is to switch the tool used to generate the resource code behind .cs file to one the automatically outputs the constructor as public instead of internal. The best one I have found is from Guy Smith-Ferrier. Download and run the installer and then change the "Custom Tool" property of your .resx resource file to "PublicResourceCodeGenerator".


Workaround:

Inherit another class from the generated one

public class TextRes2 : TextRes
{
  public TextRes2() { }
}

and use that instead of the original

<ResourceDictionary>
  <!--res:TextRes x:Key="Strings" /-->
  <res:TextRes2 x:Key="Strings" />
</ResourceDictionary>


There's a problem with all of these solutions - at least in our case.

Our resource files are all modified by a 3rd party codegen tool which updates the resource files to match the changes made in the UIs. All it does is update the strings in the xml. we still have to go in to the VS and toggle the Access Modifier from Public to something else, and back to Public so VS will synchronize the code-behind to match the new string values. THEN we have to update the c# by changing internal to public.

So for us, we need both steps automated, rebuilding the code behind and the fixing internal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜