C# – Global Resources from class in App_Code

app-codeasp.netc

I've moved one of my classes to the App_Code folder (and namespace) and inside of this class I have a reference to a global resource:

using Res = myProjectName.App_GlobalResources.Validation;

Before I moved this class to the App_Code folder, everything worked alright. Now I get a runtime error stating that:

CS0122: 'myProjectName.App_GlobalResources.Validation' is inaccessible due to
its protection level

If I go into the designer code for the Validation.resx (Validation.designer.cs) and change the internal class Validation to be public (public class Validation) then it works fine.

How come I can't access this as normal from inside the App_Code folder?

Is it because the App_Code and App_GlobalResources content are dynamically compiled, and at runtime, App_Code is compiled first and my Validation Resx hasn't yet compiled?

Thanks for any answers.

Best Answer

You can also change Custom Tool in Properties of your resource file to "PublicResXFileCodeGenerator"

Related Topic