"Settings" are not available due to the level of protection

I have the following Utilities.CS file in my App_Code folder as โ€œhelperโ€ methods used throughout my entire MVC4 application (Build Action set to Compile)

There is a breakpoint in the code ...

The application compiles (Ctrl-Shift-B) without errors, but when I start the application, I get CS0122: 'Settings' is inaccessible due to its protection level in the following return after the breakpoint.

The AdminGroup parameter AdminGroup defined as public in the parameter constructor

The interrupt line never hits, possibly due to a compilation error at runtime ... but if I compiled it, why does it recompile at run time?

(Sorry, I'm new to MVC, so I don't know what is going on)

 namespace MyApplication { public class Utilities { public static string UserID { get { return Regex.Replace(WindowsIdentity.GetCurrent().Name, @".+\\", "").ToUpper(); } } public static bool IsAdmin { get { System.Diagnostics.Debug.WriteLine("Break point on this line"); return (HttpContext.Current.User.IsInRole(Properties.Settings.Default.AdminGroup)); } } } } 

UPDATE

 //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace MyApplication.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); public static Settings Default { get { return defaultInstance; } } // // Other Settings Removed // [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("MYDOMAIN\\ADMINGROUP")] public string AdminGroup { get { return ((string)(this["AdminGroup"])); } } } } 
+5
source share
1 answer

This error is related to the Settings class internal .

I assumed that you created and changed the settings from the properties section of the Visual Studio project properties. Right click on project > Properties > Settings. There is a drop-down menu called an access modifier that needs to be changed from internal to public.

enter image description here

Additional information about the internal keyword: The internal keyword is an access modifier for types and types. Internal types or elements are only available in files of the same assembly.

+16
source

Source: https://habr.com/ru/post/1238358/


All Articles