{“The best overloaded method match for ‘string.IsNullOrEmpty(string)’ has some invalid arguments”}

{“The best overloaded method match for ‘string.IsNullOrEmpty(string)’ has some invalid arguments”}

If you come across above error it means you are trying to validate response with wrong type.

Check what exact type of response your variable is receiving and then put the validations to make sure bug free code. In this article I will guide you how to overcome such issues. Following code which returns an object and i am holding it into a var variable, next I am trying to validate it with string.IsNullOrEmpty method cause code broken:

 var userRange = Globals.ThisAddIn.Application.InputBox("Select range to insert formula:",
                "VBAOVERALL Range Selector", string.Empty, System.Reflection.Missing.Value,
                System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 8);

And the exception looks like as follow:

Let’s make a fix and try to run the code:

 var userRange = Globals.ThisAddIn.Application.InputBox("Select range to insert formula:",
                "VBAOVERALL Range Selector", string.Empty, System.Reflection.Missing.Value,
                System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 8);
            if (userRange!=null)

now try and you see compiler moves

Leave a Reply

Your email address will not be published.