I am working on a unit testing for a function in a form call Tester.cs, below is the error:
Error 7/31/2012 10:43:11 PM One of the background threads threw exception:
System.TypeInitializationException: The type initializer for 'Tester.Tester' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: String
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s)
at Tester.Tester..cctor() in E:\Incubator\Tester\Tester\Tester.cs:line 35
--- End of inner exception stack trace ---
at Tester.Tester.Dispose(Boolean disposing)
at System.ComponentModel.Component.Finalize() MY-PC
On line 35 is a code, which basically retrieve value from configuration file and convert it to integer:
private static int _part = int.Parse(ConfigurationManager.AppSettings["Part"]);
What is the error? Thank you.
The likelyhood is that ConfigurationManager.AppSettings["Part"]
is returning null. Hense the parse exception.
Does your unit test project have the app setting defined in its configuration?
You should copy your app.config (or web.config) file into test project. Otherwise test project can't find it. Remember config is related to host process, not to the dll itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With