我有一个名为 Helpers 的静态类,其中包含大量简单的辅助方法,包括一些简单的“字符串”扩展方法等:
public static string AddSquareBrackets(this string str)
{
return "[" + str + "]";
}
我有一个测试类和方法如下:
[TestMethod()]
public void AddSquareBracketsTest()
{
Assert.AreEqual("[NAME]", "NAME".AddSquareBrackets());
}
使用默认(无编码)构造函数声明的静态类:
namespace Equinoxe.Utilities.Helpers
{
public static class HELPERS
{
对 AddSquareBrackets 的调用会引发以下内容:
System.TypeInitializationException was unhandled by user code
Message=The type initializer for 'XXX.Utilities.Helpers.HELPERS' threw an exception.
Source=XXX.Utilities
TypeName=XXX.Utilities.Helpers.HELPERS
StackTrace:
at XXX.Utilities.Helpers.HELPERS.AddSquareBrackets(String str)
at XXX.Utilities.Test.HELPERSTest.AddSquareBracketsTest() in C:\DEVELOPMENT\PROJECTS\XXX.NavEgate\XXX.Utilities.Test\HELPERSTest.cs:line 77
InnerException: System.NullReferenceException
Message=Object reference not set to an instance of an object.
Source=XXX.Utilities
StackTrace:
at XXX.Utilities.Helpers.HELPERS..cctor() in C:\DEVELOPMENT\PROJECTS\XXX.Utilities\XXX.Utilities\Helpers\HELPERS.cs:line 44
InnerException:{System.NullReferenceException: Object reference not set to an instance of an object.
at XXX.Utilities.Helpers.HELPERS..cctor() in C:\DEVELOPMENT\PROJECTS\XXX.Utilities\XXX.Utilities\Helpers\HELPERS.cs:line 44}
我也看过
我正在运行 VS2010