I want to add this class as setting's type:
using System.Collections.Generic;
using System.Configuration;
namespace MY_PROJECT.SUB_PROJECT
{
[SettingsSerializeAs(SettingsSerializeAs.Xml)]
public class Configs: List<ConfigData>
{
Configs(int capacity): base(capacity) { }
public string GroupName { get; set; }
}
}
So what I did:
- Select Browse... in the type dropbox:
- I cannot see the
MY_PROJECT
namespace anywhere: - So I typed the full type manually:
The result is an error:
Type 'MY_PROJECT.SUB_PROJECT.Configs' is not defined.
I also tried SUB_PROJECT.Configs
and Configs
alone. Nothing helped. Why does my class not show in the browser?
I had this problem as well. I was doing exactly the same: creating a custom class to use in Application Settings. In my case, I followed the steps outlined in this very informative article: http://www.blackwasp.co.uk/CustomAppSettings.aspx
I should note the article is written for C#, and I painstakingly converted it to VB until it worked. I had to solve the
Type...is not defined
error the hard way: relentlessly experimenting until I got it to work.I will describe my first solution, one which was not mentioned in the article, probably because it's for C# instead of VB, and that is: put the custom class or classes each in their own
.vb
files. For instance:Employee.vb
andRoom.vb
. This is the only way I could make it work perfectly with no errors. After doing this and rebuilding the solution, I was then able to add my custom class as an Application Setting, but of course only by manually typing the full nameTestProject.Employee
in theSelect a Type
dialog.However, following the article I linked above, if I put all the class definitions in the
Module1.vb
file withSub Main()
, theSelect a Type
dialog cannot find them, and I receive theType...is not defined
error.And the cause of this error seems to be shortcomings in the code & design of the Applications Settings system and Settings page of the Project Properties dialog. I say this because of the solution I found: I hacked my classes into the settings the hard way.
What I mean by that is I initially created the setting with the name
DefaultEmployee
and type ofString
. Then I used theFind In Files
dialog to find all instances ofDefaultEmployee
and replaced the appropriate instances ofString
withTestProject.Employee
.The files I made replacements in are:
App.config
,Settings.Designer.vb
, andSettings.settings
.And it worked..! Sort of. I should say the code ran fine and it did what was expected. But...the Application Settings dialog didn't like it. After I made the changes, there are various errors from the Project Properties/Settings system every time I opened it. But as I said, it still works.
Thus...my only conclusion is the coding of the Settings system is not designed to handle this situation, and if you wish to have the most reliable & error-free experience, it's best to put each of the custom classes in their own
.vb
class file.On the other hand, if you wish to become very adventurous, you could create your own Applications Settings system, as the author of this article did. I have not read all of this yet, but scanning through it seems very interesting: https://weblog.west-wind.com/posts/2012/dec/28/building-a-better-net-application-configuration-class-revisited