"The pipe is being closed" error when using GeoLocator in Windows Store App(Windows 8.1)?

3

I am working in Windows 8.1 app and I am finding the current location of the user using below mentioned code. Now when I run my app in Tablet using Cellular network the app crashes but it works fine on Wifi. Can someone suggest a solution for this?

            geolocator = new Geolocator();
            geolocator.DesiredAccuracy = PositionAccuracy.Default;
            geolocator.DesiredAccuracyInMeters = 1000;
            geolocator.MovementThreshold = 5;
            geolocator.ReportInterval = 500;
            try
            {
                Geoposition mygeoPosition = await geolocator.GetGeopositionAsync();
            }
            catch(UnauthorizedAccessException ex)
            {
                UserMessageUtil.ShowMessage("Location is disabled in Settings");
                await Launcher.LaunchUriAsync(new Uri("ms-settings-location:"));
            }
            geolocator.PositionChanged += geolocator_PositionChanged;

I always check in Laptop Machine so I didn't face this issue in past but now I have a tablet with both 3G and WIFI connectivity and when I run the app in tablet and try to get the current location, the error comes.

Update

I also sometimes get The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F) error on line

Geoposition mygeoPosition = await geolocator.GetGeopositionAsync();

I get both these error when I am connected on a Cellular network

c#
windows-8.1
bing-maps
asked on Stack Overflow Mar 4, 2016 by Kinjan Bhavsar • edited Mar 6, 2016 by Kinjan Bhavsar

2 Answers

1

Start off by using a larger movement threshold. Most GPS devices only have an accuracy of 15 meters. Setting the movement threshold to 5 could be too small and cause issue.

Also look at using one of the position accuracy enumerators:

geolocator.DesiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.high;

answered on Stack Overflow Mar 6, 2016 by rbrundritt
1

These are both very low-level Windows error codes. Whatever fails is either very far removed from your code, roughly the device driver level. Or it is an error code that was re-used by intermediary software layers, a very common crime in WinRT. You do have to keep in mind that lots and lots of things can go wrong in networking and you don't always get a fantastic diagnostic. Well, almost never.

"The pipe is being closed" is ERROR_NO_DATA. That error identifier is pretty likely to be more representative than the message.

"The group or resource is not in the correct state" is ERROR_INVALID_STATE. Again that identifier quacks more sensibly than the message.

My call: your cellular network connection is just flaky. Either because the radio is spotty or because there's crappy anti-malware in between. You can eliminate the latter easily enough. But the former is always going to happen on somebody's machine. So do write your code to be resilient to those kind of networking mishaps, do not just catch UnauthorizedAccessException. Write another catch for Exception and display a "We're sorry, service temporarily unavailable" style message. Maybe you can band-aid it by memorizing the previous location, as long as the user knows.

answered on Stack Overflow Mar 7, 2016 by Hans Passant

User contributions licensed under CC BY-SA 3.0