"Pipe closes" when using Geolocator WinRT

When I use Geolocator WinRT, I sporadically get an error:

{"The pipe is being closed. (Exception from HRESULT: 0x800700E8)"} 

Again, this is sporadic. Any suggestions?

 Windows.Devices.Geolocation.Geoposition _Postion = null; try { var _Locator = new Windows.Devices.Geolocation.Geolocator(); _Postion = await _Locator.GetGeopositionAsync(); } catch { /* continue, null okay */ } if (_Postion == null) { /* use alternate */ } else { /* use location */ } 

This is in the simulator, but also when running on the local machine. Usually this error will NOT cause a break. It just ends the application all of a sudden. When will this lead to a break. This is the resulting error.

+6
source share
3 answers

I realized that this happened when your localization is set to “simulated”, if you use your application using a device simulator, you can disable it by clicking the world icon (between the display and camera settings), then uncheck the “Use simulated location” box

+1
source

I think the reason for this problem is that GeoLocator uses the Location API.

The error you get is HRESULT_FROM_WIN32 (ERROR_NO_DATA), which seems to correspond to the friendly (but useless, in this case) line "Pipe closes." This is an expected error when the platform does not see your sensor providing a valid report.

0
source

I also came across a similar sporadic exception in my project. Take a look at the screenshot I attached. enter image description here

Here is a solution that worked for me, but I'm not sure if it will work for others.

This has been my code before:

 Geolocator loc = new Geolocator(); try { loc.DesiredAccuracy = PositionAccuracy.High; Geoposition pos = await loc.GetGeopositionAsync(); var lat = pos.Coordinate.Point.Position.Latitude; var lang = pos.Coordinate.Point.Position.Longitude; Status = loc.LocationStatus; return GetGpsInfoObject(pos); } catch (System.UnauthorizedAccessException) { return null; } 

I changed the code to:

 Geolocator loc = new Geolocator(); try { loc.DesiredAccuracy = PositionAccuracy.High; Geoposition pos = await loc.GetGeopositionAsync(); var lat = pos.Coordinate.Point.Position.Latitude; var lang = pos.Coordinate.Point.Position.Longitude; Status = loc.LocationStatus; return GetGpsInfoObject(pos); } catch (Exception) { return null; } 
0
source

Source: https://habr.com/ru/post/919173/


All Articles