-3

I have a class named 'Utility' which contains several static members. On calling any of those static members, i get an exception 'The type initializer for Utility.cs threw an exception'. I can't figure out what is wrong. Please help!

Uzair Raza
  • 35
  • 3

1 Answers1

1

You have a static constructor (static Utility() {...this bit...}) or a static field initializer (static SomeType someField = {...this bit...};) that is failing inside Utility. Find out why. You could start by looking at the .InnerException of the exception that is being thrown.

Marc Gravell
  • 927,783
  • 236
  • 2,422
  • 2,784
  • Its not a static class, and I haven't defined any static constructor in the class scope. I am just calling the static members of the Utility class in other classes with the class name. – Uzair Raza Jan 23 '18 at 12:22
  • @UzairRaza I never said anything about it being a static class; and if you don't have a static constructor, then that leaves: static field initializers. So: check for static field initializers (values on the right of a `=` in a static field declaration), and : look at the `.InnerException` – Marc Gravell Jan 23 '18 at 12:34
  • Solved my problem. Thank you very much. – Uzair Raza Jan 25 '18 at 08:57