title: Using UWP Geolocation-API with Win32-Application on Windows 10
body: <p>We're building a multi-platform (desktop- and tablet-computers) application targeting Windows 8.1 as well as 10. As we process spatial data, we offer the user the possibility to use his current location using the device's gps receiver. To allow easy adaption to the (hardware) environment, we placed the gps-logic (including the API-calls) into an external assembly that we load based on a configuration.</p>
  
  <p>Recently we discovered some problems with the gps-module using the Geolocator from Windows.Devices.Geolocation-API under windows 10 (but previously running without problem on Windows 8.1), not delivering any location. Further investigation and <a href="https://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.aspx" rel="nofollow">RTFM</a> showed up, that - under Windows 10 - we were obliged to call the RequestAccessAsync before calling for the location.</p>
  
  <p>As the RequestAcessAsync-method isn't available in Windows 8.1, we decided to create a new assembly, targeting Windows 10 (and then easily being bound/used through our configuration), what worked quite well:</p>
  
  <pre><code>public Win10GpsProvider()
  {
      RequestAccessAsync();
  }
  
  public async void RequestAccessAsnyc()
  {
      //next line causes exception:
      var request = await Geolocator.RequestAccessAsync();
      switch (request)
      {
          // we don't even get here... :(
      }
  }
  </code></pre>
  
  <p>Only up to running into an exception that gets thrown as soon as the RequestAccessAsync-method is being called (in UI-thread), stating that the call has to be made in the context of an app container.</p>
  
  <blockquote>
    <p>This operation is only valid in the context of an app container. (Exception from HRESULT: 0x8007109A)</p>
  </blockquote>
  
  <p>The exception occurs on both, desktop as well as tablet (verified through remoted debugging).</p>
  
  <p>Searching a bit more, adding the "location" as a required capability to the package.appxmanifest may help:</p>
  
  <pre><code>&lt;Capabilities&gt;
      &lt;Capability Name="location"/&gt;
  &lt;/Capabilities&gt;
  </code></pre>
  
  <p>That's where we're actually stuck at the moment:</p>
  
  <ul>
  <li>We don't have an UWP-application (and actually don't want/can change that, as we're targeting Win 8.1 as well and have a defined deployment workflow including setups)</li>
  <li>We can't get the assembly run without exception as there is no UWP app/context</li>
  </ul>
  
  <p>Is there a way to get a separate assembly that targets the Windows 10 version of the Windows.Devices.Geolocation-API and can be called/loaded by a Win32-application?</p>