how to handle system.nullreferenceexception in c# windows service as I already written my code in try catch block.
I'm using S7 control & plc.cs for capturing data & inserting into database.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manas MohapatraRank #182 · 13.2K reputationPosted Jun 5, 2017, 9:38 PM EDT
Rajkiran SwainRank #165 · 14.4K reputationPosted Jun 7, 2017, 2:57 AM EDT
NullRefException is one of the basic programming error you should learn and avoid. How did you set collectionDB? Or if it's not collectionDB was null, just share exception stacktrace here so i will see and help you point out the cause of this.
Besides, never catch the top-level Exception like this. Catching exception without logging is a bad practice in all cases.