简体   繁体   中英

"TypeInitializationException was unhandled" exception c#

I am initializing an object from the class TagNameHandler in another class.

This class has a constructor:

在此处输入图片说明

Every time I try to initialize the object in another class, I receive this message:

在此处输入图片说明

Both classes are public and none of them are static.

How can I solve this?

Thanks.

TypeInitializationException means that TagNameHandler threw an exception while initializing the type. By that, it means while assigning static variables and calling static constructors. The only static variable that is likely to throw an exception is the instance object, which calls the TagNameHandler constructor. You will have to view the InnerException of that exception to get anywhere, as so far there is minimal information. There should be a clickable "View Details" button to follow the stack trace.

Something quick would be if AppSettings doesn't contain one of those strings you're accessing. Perhaps debug print AppSettings first. Otherwise, it'll be in createTagDictionary(). The inner exception will tell you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM