locked
SOS: Windows Mobile 6 SDK GPS C# sample code can not work on Windows Mobile 6.5 RRS feed

  • Question

  • Dear Experts,

    I am trying to utilize the Windows Mobile 6 SDK GPS C# sample code to build and then install it on my smart device (Windows Mobile 6.5), but got the error message after clicking "Start GPS", the detailed info as follows:

    GpsSample.exe
    NullReferenceException

    位于GpsTest.Form1.UpdateData(Object sender, EventArgs args)
    位于System.Windows.Forms.Control.TASK.Invoke()
    位于System.Windows.Forms.Control._InvokeAll()
    位于System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 IParam)
    位于System.Windows.Forms.ContainerControl.WnProc(WM wm, Int32 wParam, Int32 IParam)
    位于System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 IParam)
    位于System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 IParam)
    位于Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
    位于System.Windows.Forms.Application.Run(Form fm)
    位于GpsTest.Form1.Main()

    Please note that my smart device should already installed .Net CF, cause when I tried to install .Net CF 3.5  through MS ActiveSync, it showed that .Net CF higher version was installed already. And I was using VS 2008 to generate the smart device CAB installation file, which includes two files (GpsSample.exe and Microsoft.WindowsMobile.Samples.Location.dll, derived automatically by "add -> Project Output ..." ); after insalling the generated Cab file on my smart device and starting to use it, I got the above mentioned error.

    One more thing: the third party GPS application works fine on my smart device.

     Appreciate your great assistance!

    Millions of thanks if you can send your solution to my email box - billsen.xu@gmail.com, so I can read it at the first time.

    Best Regards,

    Billsen

    Tuesday, April 5, 2011 7:55 AM

Answers

  •  

    Hi Billsen,

     

    I guess it maybe multithread conflict on your real device deals to this problem. In the Emulator the function gps_LocationChanged() get the GPS datas no need to wait the IO completed, but In the real device, we sometimes need to wait the IO completed. If IO is not completed, the data may be null.

     

    I suggest you add a Sleep() function before position = args.Position. You also need to check the if(args!=null) before this line, to make sure it is not null.

     

    I hope my suggestions can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Monday, April 18, 2011 6:02 AM
    Tuesday, April 12, 2011 7:23 AM

All replies

  • Hi Billsen,

    I would suggest you, first of all you have to run "Gps Sample" project directly on the device then try it.

    If it is not throwing any NullReferenceException, while running application from the IDE 2008. It mean there is no error in the source code.

    Run your GPS Sample application through the VS 2008 (set as Device Target in) and connect with your mobile device.

    let me know is working for you?

     


    - Pavan [MCTS - Windows Mobile 5.0] If you find my post is helpful for you then mark as a answer and vote it.
    Tuesday, April 5, 2011 8:32 AM
  •  

    Hi Billsen,

     

    I believe you can debug your project in Visual Studio 2008 and get more error information.

     

    You can also test the GPS CPP project and see if this error still exist.

    \Windows Mobile 6 SDK\Samples\Common\CPP\Win32\gps

     

    I hope my suggestions can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 7, 2011 9:33 AM
  • Actually from what I remember original sample had a trivial bug in it which would do it. Should be easy to fix.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, April 7, 2011 4:01 PM
  • Dear Experts,

    Per your suggestions, kindly please find my troubleshooting as follows:

    1) When I use FakeGPS (come with WM 6 SDK) and debug the C# Gps sample code in WM 6 Professional Emulator, the sample code works fine; But when starting to debug in the mobile device directly, an error window shows "NullReferenceException was unhandled", the debugging stop at "Invoke(updateDataHandler)", the code block is:

    protected void gps_LocationChanged(object sender, LocationChangedEventArgs args)
            {
                position = args.Position;

                // call the UpdateData method via the updateDataHandler so that we
                // update the UI on the UI thread
                Invoke(updateDataHandler); 

            }

    2). When I test the GPS CPP project, that sample code works fine with the mobile device.

    Cause I am a beginner of VS 2008 development, a more detailed guidance/explanation will be a great assistance.

    Thanks a lot.

    Sunday, April 10, 2011 6:41 AM
  • Hi,

    You have to debug your code with device properly, and try to find which line you are getting "NullReferenceException" exception.

     

     


    - Pavan [MCTS - Windows Mobile 5.0] If you find my post is helpful for you then mark as a answer and vote it.
    Sunday, April 10, 2011 6:54 AM
  •  

    Hi Billsen,

     

    I guess it maybe multithread conflict on your real device deals to this problem. In the Emulator the function gps_LocationChanged() get the GPS datas no need to wait the IO completed, but In the real device, we sometimes need to wait the IO completed. If IO is not completed, the data may be null.

     

    I suggest you add a Sleep() function before position = args.Position. You also need to check the if(args!=null) before this line, to make sure it is not null.

     

    I hope my suggestions can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Monday, April 18, 2011 6:02 AM
    Tuesday, April 12, 2011 7:23 AM
  • Jesse Jiangs reply worked.

    I re-wrote it like this.

            protected void gps_LocationChanged(object sender, LocationChangedEventArgs args)
            {
                System.Threading.Thread.Sleep(20);
                if (args == null)
                    return;

                position = args.Position;

                // call the UpdateData method via the updateDataHandler so that we
                // update the UI on the UI thread
                Invoke(updateDataHandler);

            }
    Thanks Jesse. Finally a helpfull reply from one of you experts. Most only give you links and don't answer the question. So hats of for you.

    Tuesday, May 22, 2012 5:24 AM
  • My solutions;

    I added code for NullReferenceException to UpdateData method ; 

    if (position.SatellitesInSolutionValid &&
                            position.SatellitesInViewValid &&
                            position.SatelliteCountValid)
                        {
                            // I wrote this codes and NullReferenceException problem is solved
                            if (position.GetSatellitesInSolution() != null && position.GetSatellitesInView() != null)
                            {
                                str += "Satellite Count:\n   " + position.GetSatellitesInSolution().Length + "/" +
                                    position.GetSatellitesInView().Length + " (" +
                                    position.SatelliteCount + ")\n";
                            }
                        }


    Friday, September 18, 2015 8:45 AM