I've got a weird error here I don't quite understand. I have a very simple class with nothing but string properties and a couple of methods. One of those methods is a static function that returns a list of the object. When I attempt to instantiate an XmlSerializer with the type, though, I get an InvalidOperationException with a NullReferenceException inner exception . The declaration of properties and class looks like this:
[Serializable]
public class Config
{
public string Name { get; set; }
public string DatabaseInstanceName { get; set; }
public string InitialCatalog { get; set; }
public string PersistSecurityInfo { get; set; } = "true";
public string UserID { get; set; }
public string Password { internal get; set; }
public Config() { } //declared explicitly in case this was the pitfall, but didn't work
public void Save()....
public SqlConnection GetConn()...
public static IList<Config> LoadAllConfigurations...
The static function where the error occurs doesn't get far.
public static IList<Config> LoadAllConfigurations()
{
var t = typeof(Config);
var xml = new XmlSerializer(t); //error occurs here
I confirmed that t contains the Type Config, so what about my instantiation am I doing incorrectly? As you can see, I added a parameterless constructor explicitly to see if there as a failure here, but nothing changed. Update: I also tried removing the default value for PersistSecurityInfo. InvalidOperationException outer exception says there was a problem reflecting type Config.
internalmodifier onPasswordgetter that causes it.