How to avoid a NullReferenceException
问题 if (alMethSign[z].ToString().Contains(aClass.Namespace)) Here, I load an exe or dll and check its namespace. In some dlls, there is no namespace, so aclass.namespace is not present and it's throwing a NullReferenceException . I have to just avoid it and it should continue with rest of the code. If I use try-catch, it executes the catch part; I want it to continue with the rest of the code. 回答1: Is aClass a Type instance? If so - just check it for null: if (aClass != null && alMethSign[z]