You must Sign In to post a response.
  • Category: .NET

    Object reference is not set to instance .

    I got above error when my program runs. It gives error at SendKeys.SendWait method.
    It gets proper input but didn't work. Actually in my scenario I want to send received data to activated window (i.e word , excel , notepad , or any application text box which is activated at that instance).
    Help me please, Thanks

    here is code,

    Hide Copy Code
    if (res.StartsWith("*"))

    In above code "res" is string received from socket and i want to send this string to activated window i.e text editor opened at runtime.
  • #761026

    Object reference is not set to instance
    error Mostly your object is nothing instance there
    so you first find object is correct or not then values coming or not then check them

    Name : Dotnet Developer-2015
    Email Id

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761028
    I checked value is coming in "res" variable. but it doesnt send data to file

  • #761029
    Hello Priyanka,

    By providing this much code we can not help you at the end. you should provide us that much of code where we can help you at least.

    The stack trace is just a string showing the full path of exception propagation from the throw statement to the handler.
    catch(Exception ex)

    Mostly this error occurs due to your object doesn't have instance. I suggest you to put a breakpoint in your code and try to debug it and check whether object has an instance or not.

    You can visit the MSDN Library for NullReferenceException on below link :

    Hope this will help you.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761031
    void sendkeytest(string input)
    //static extern int SetForegroundWindow(IntPtr point);
    Process p = Process.GetCurrentProcess();
    IntPtr h = p.MainWindowHandle;

    if (p.Responding)
    foreach (char c in input)

    if (res.StartsWith("*"))

  • #761185

    Check the null case before assign value like below.

    if (res !=string.Empty && res.StartsWith("*"))

    hope this will helpful to you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

Sign In to post your comments