3

I have been generating a StronglyTypedClass file using resgen.exe in my Windows Form application using C# and .NET 4.5

According to syntax I can make the StringResources class as public but the Constructor still remains internal.

resgen inputFilename [outputFilename] /str:language[,namespace,[classname[,filename]]] [/publicClass]

When I put this argument [/publicClass], it just makes the class as public but the constructor is still internal.

internal StringResources() {}

Please suggest, how to achieve this.

Indigo
  • 2,887
  • 11
  • 52
  • 83
  • How do you need the constructor to be public? – Luis Filipe Jan 24 '13 at 10:15
  • that is my question actually, By default this tool ResGen.exe can make the class public but the constructor remains internal. And one of my team mate has demamnded to make it public somehow. I tried MSDN help but doens't seems to be helping much. Basically, I wanted to do it while generting the cs file itself but if there is no way doing that, it might be done by reading the file again after it is generated and cahnge this internal to public. However, I believe that is not a good and proper solution. – Indigo Jan 24 '13 at 10:23

1 Answers1

2

Very likely your teammate wanted to have that constructor public because he wants to use the resources in xaml.

Just create a class in the same assembly, which inherits the resources file and exposes a public constructor, then use this class instead.

public class ResourcesProxy : Properties.Resources
{
    /// <summary>
    /// resolves the problem of internal constructor in resources.designer.cs
    /// in conjunction with xaml usage
    /// </summary>
    public ResourcesProxy() : base()
    {
    }
}
Mike Fuchs
  • 12,081
  • 6
  • 58
  • 71
  • This should be marked as answer. Solution is so simple yet I have been trying to remember to make the constructor public every time, but failed to do so when my memory refused to remember. Thanks for your solution. In my case I am accessing the resource class via XAML as a static resource and it fails to work when the constructor is internal. – johnildergleidisson Jun 05 '13 at 18:21
  • 1
    @adabyron - I tried that but although the base class properties do appear in the Create Data Binding dialog, I get binding path errors at runtime: http://stackoverflow.com/questions/20278545/binding-path-error-with-class-that-inherits-from-c-sharp-windows-phone-8-shared – Robert Oschler Nov 29 '13 at 13:18