I have DLL that run on server and I can't debug it for many reasons, I log its exceptions.
sometimes I have "Object reference not set to an instance of an object"
in a method call that have about 20 parameter that take from me long time to know where's the object that cause the exception.
Is there any way to log the exception in case of "Object reference not set to an instance of an object"
with the name of the object that cause the exception ?
If you want to log the exact argument that was null (it sounds like debugging is out of the question) you will need to test each parameter individually for null and throw an ArgumentNullException
for that parameter if it is null with the name of the parameter passed as a string to the exception's constructor.
This is one reason (among many) that a method accepting 20 parameters can lead to tough maintenance issues. It indicates that a method may have too many responsibilities and may be trying to do more than it should. While you are in the code you might want to consider breaking this method up into smaller pieces.