Weird exception being thrown when initializing static variable

Viewed 475

I recently had a very weird System.ArgumentException.

The following code was at my MainWindow constructor on my WPF Application

CodeDefinitions.DEFAULT_AVALIABLE = (() => { return true; });

But every time a run the app, this is what I get: System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

So obviusly there where something wrong, so I put the line inside a try/catch block, like this:

try
{
    CodeDefinitions.DEFAULT_AVALIABLE = (() => { return true; });        
}
catch()
{

}

And put an breakpoint at catch's '{', and this is what I got as $exception:

[System.TypeInitializationException] {"The type initializer for 'ComunicadorSerial.Classes.Utils.CodeDefinitions' threw an exception."}

That tells me nothing, so I took a look at _innerException:

_innerException {"An item with the same key has already been added."}   System.Exception {System.ArgumentException}

As far as I know, this excepton is throw when using a Dictionary, but the most curious thing is that DEFAULT_AVALIABLE is a Func<bool>:

internal static Func<bool> DEFAULT_AVALIABLE;

Does anyone knows anything about this? It seems so dumb, but I just can't figure it out.

Thanks in advance!

1 Answers
Related