Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I unable to select a custom Type for a setting from the same project/assembly as the settings file?

I am trying to set the type of an application setting property to a custom enum type I have defined in my assembly (call this Project A)

In the settings browser I click browse and am presented with the "Select a Type" dialog box.

And the Types defined in Project A are not seem to be available to me. Yet types are available from other projects that A has referenced.

It seems almost beyond comprehension to me that one would not be able to use Types defined in the base project, so I assume I am doing something wrong. I have tried building, cleaning, rebuilding, restarting without any luck, so what exactly am I missing?

edit: screenshot here http://tinypic.com/r/2ls8myb/7

like image 445
fostandy Avatar asked Oct 28 '10 10:10

fostandy


People also ask

How do I create a settings file in Visual Studio?

In Visual Studio, from the Project menu, choose Add New Item. The Add New Item dialog box opens. In the Add New Item dialog box, select Settings File, enter a name for the file, and click Add to add a new settings file to your solution. In Solution Explorer, drag the new Settings file into the Properties folder.

Where are .NET application settings stored?

Settings. settings is located in the My Project folder for Visual Basic projects and in the Properties folder for Visual C# projects. The Project Designer then searches for other settings files in the project's root folder. Therefore, you should put your custom settings file there.

How do I access Visual Studio settings?

To open the Settings editor, use the following VS Code menu command: On Windows/Linux - File > Preferences > Settings. On macOS - Code > Preferences > Settings.


3 Answers

I was trying to do exactly the same thing in VS 2010 (.net 3.5). It turns out that you can do this using the Settings designer. The UI is totally flawed, as stated, but if you manually enter the fully qualified name of the enum in the Browse window it'll work. This has the benefit of not modifying generated code (*.Designer.cs), which is always good to avoid because when you do there's no guarantee that you're changes won't be overwritten.

PS - This only seems to work if the enum is public.

Settings GUI:

enter image description here

Then manually type fully-qualified type name:

enter image description here

At one point I swear I saw a drop-down of the enum values in the Value column, but I haven't seen it since and you just have to type an appropriate value in.

like image 156
Sean Avatar answered Oct 16 '22 11:10

Sean


I could not browse to my custom type either. I was able to add my custom type by opening the Settings.settings file in a text editor and adding the setting to the Settings section like this:

<Setting Name="Options" Type="MyProject.MyOptions" Scope="User">
  <Value Profile="(Default)" />
</Setting>

The settings designer complains when I open it, but I just respond 'No' to that dialog, and I am able to use the custom setting in my project.

like image 6
George H. Avatar answered Oct 16 '22 10:10

George H.


Because your own type is not serializable. Make it serializable and you can define it in your settings.

like image 2
Aykut Çevik Avatar answered Oct 16 '22 11:10

Aykut Çevik