locked
Getting Object reference not set to an instance of an object. RRS feed

  • Question

  • Hi, 

    I was trying to automate a windows app from scratch and not using the recording feature. I used the calculator application from window.

    Was getting the below error

    Test method SampleTest.CalculatorTest.launchCalculator threw exception: 
    System.NullReferenceException: Object reference not set to an instance of an object.

    PFB my code below

    namespace SampleTest
    {
        [CodedUITest]
        public class CalculatorTest
        {

            [TestMethod]
            public void launchCalculator()
            {

                ApplicationUnderTest.Launch("C:\\Windows\\System32\\calc.exe");
                WinWindow UICalcWindow = new WinWindow();
                UICalcWindow.SearchProperties[WinWindow.PropertyNames.Name] = "Calculator";
                UICalcWindow.SearchProperties[WinWindow.PropertyNames.ClassName] = "CalcFrame";
                UICalcWindow.WindowTitles.Add("Calculator");
                Console.WriteLine(UICalcWindow.Name.ToString());

            }


        }


    Monday, August 13, 2012 11:06 AM

Answers

All replies

  • Can you put some wait after launching the application; On my machine same code is working without any issue.

    Thanks


    Aditya Kumar Agrawal (MSFT)

    Tuesday, August 14, 2012 3:56 AM
  • I put a sleep time of 5000 ms after the launch of the application. Still getting the same error

    if possible could you upload load your sln file, so that i can see if i am missing some references

    Tuesday, August 14, 2012 4:37 AM
  • Or could it be problem of the framework i have chosen while creating the project

    I chose .net 4

    Tuesday, August 14, 2012 4:49 AM
  • CodedUITest works with .NET v4.0;

    Can you call UICalcWindow.DrawHighlight() to check which window it is highlighting ?


    Aditya Kumar Agrawal (MSFT)

    Tuesday, August 14, 2012 5:43 AM
  • i cannot use any of the methods of  UICalcWindow, all of it gives me the null reference exception
    Tuesday, August 14, 2012 5:50 AM
  • Thanks for Aditya’s friendly assistance.

    Hi Nikhil,

    Thank you for posting in the MSDN forum.

    1. We would make sure that the steps are correct when we create a coded UI test, for detailed information, see Mathew’s blog about “Hand-coding a Coded UI Test”.
    2. Like Vinoth’s suggestion, make sure all the related assemblies added as reference with Copy Local property as False. See “Object Exists but get a null reference trying to interact with it.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Nikhil Rajan Tuesday, August 14, 2012 9:57 AM
    Tuesday, August 14, 2012 9:09 AM
    Moderator
  • Thanks Jack and Aditya. Solved my issue . Appreciate the concern shown.

    Tuesday, August 14, 2012 9:58 AM
  • i had to set the Copy Local property as False, as it was True by default.
    Tuesday, August 14, 2012 10:10 AM