Reputation: 17348
I am building an ASP.NET MVC 4 website with C#. I am localizing all of my static strings in a Resource File (.resx
). I use the Visual Studio interface for creating and populating the resource file. In my index.cshtml
view, I try to use one of the strings from the resource file, like this:
@using Namespace.To.RESX.File
...
<h1>@EN_US.GLOBAL_NAME</h1>
<h2>“@EN_US.GLOBAL_SLOGAN”</h2>
...
I can compile the application, but I get a runtime error when I load the page, saying:
Compiler Error Message: CS0122: 'Namespace.To.RESX.File.EN_US' is inaccessible due to its protection level
Looking in the resx designer file, I can see the class and all of its members are marked as internal
. I completely understand what the C# access control modifiers do, how they work, etc... but I don't understand why Visual Studio would restrict access to the resource members like this.
Why would Visual Studio do this? Is there an (easy) way to change these access control modifiers, or am I missing the point of resource files completely?
Upvotes: 35
Views: 19505
Reputation: 395
I don't know if it's a bug in VS 2019 or what, but going by Oliver Spryn's answer, I could expand that Access Modifier dropdown box which was "Internal" by default, but clicking "Public" just closed the dropdown onMouseDown without selecting an option. So, if you click to dropdown the list, but then use your keyboard down arrow to select "Public" and hit enter, it will change the value.
Upvotes: 0
Reputation: 4436
For the Mac / visual studio 2017 guys , Open .Designer file and make your classes public :
Folder:
Change internal to public and save:
Update: It may Default back to internal. everytime you make changes which you want to make this change listed here
Right click on Resource file ( resource.resx
) => Properties.
Custom Tool => Change to PublicResXFileCodeGenerator
Upvotes: 14
Reputation: 17348
Yep... didn't see this. Open up the resource file in design mode and change the access modifier (at least, on VS 2013):
Upvotes: 83