Is there a way I can initialize a class which contains a static constructor (that throws an exception), without executing the static constructor?
I've tried these so far:
Activator.CreateInstance(typeof(Foo));
FormatterServices.GetUninitializedObject(typeof(Foo));
var s = new XmlSerializer(typeof(Foo));
Foo f = (Foo)s.Deserialize(new StringReader("<Foo></Foo>"));
Aside from using a CRL Profiler api with something like MS Fakes or TypeMock, can this be done using any API in the baseclass library, or perhaps something unmanaged.
Example class that I want to use.
public class Foo
{
static Foo()
{
throw new Exception("Populate Bar from the database, which isn't available.");
}
public int Bar { get; set; }
}