locked
CrossDeviceInfo.Current not working for me in UWP RRS feed

  • Question

  • User234750 posted

    Hi, I have been using CrossDeviceInfo.Current.Platform and CrossDeviceInfo.Current.Idiom successfully with Droid and iOS. Now I have added an UWP project and they are throwing an exception. While stepping through in debug mode, when I set a watch on CrossDeviceInfo.Current.Platform it tells me CrossDeviceInfo.Current.Idiom error CS0103: The name 'CrossDeviceInfo' does not exist in the current context

    and the exception it throws starts with:

    Exception: Element not found. (Exception from HRESULT: 0x80070490)
    -> System.Exception: Element not found. (Exception from HRESULT: 0x80070490) at SharedLibrary!<BaseAddress>+0x80587d

    Any ideas on how to fix this are appreciated!

    Wednesday, November 29, 2017 12:30 AM

Answers

  • User89714 posted

    @"Will.Itrax" - I didn't mention it before, but I don't see any point in using the DeviceInfo plugin to get Platform or Idiom (perhaps I'm missing something...)

    For Platform, you could use Xamarin.Forms.Device.RuntimePlatform . Or, what I do (as a result of previously supporting multiple Windows variations - WinPhone 8.0 SL, WinRT 8.1, WinPhone RT 8.1, UWP) is to set a globally accessible enum from each of my platform-specific projects.

    For Idiom, you could use Xamarin.Forms.Device.Idiom . Or, what I do, is to check whether functionality I need is available on the device, or to check the available screen dimensions. I figure it's safer if I explicitly check for what my app needs, or check screen dimensions before deciding whether to display one page, or more than one side-by-side, etc.

    The only place I actually use Xam.Plugin.DeviceInfo is on a page where I experiment with stuff, so not a page that will make it to production code.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, December 1, 2017 5:58 PM

All replies

  • User196454 posted

    It supports Windows 10 UWP with version 10+. Can you please check your version.

    Wednesday, November 29, 2017 7:53 AM
  • User234750 posted

    @MahaLakshmiGunti Hi. I am using Win 10 Pro Version 1709 for Compiling the UWP app with a Target of Windows 10 Build 16299 and a Min of 16299 using Visual Studio 2017 Pro v15.4.5. Other components: Xamarin Forms 2.5.0.91635 Microsoft.NETCore.UniversalWindowsPlatform v 6.0.2 NetStandard Library v 1.6.1 XAM.Plugin.DeviceInfo v3.0.2 Xamarin v4.7.10.38 Regards, Will

    Wednesday, November 29, 2017 6:35 PM
  • User234750 posted

    Update: On UWP, the rest of CrossDeviceInfo.Current seems to work fine. I get the Version and Model from there. I can even inspect the contents of CrossDeviceInfo.Current when I am getting the Model and meanwhile, inspect the CrossDeviceInfo.Current object, it will display Windows for Platform. But when I go to extract (assign to a variable) the Platform (or Idiom) it gives an exception. Regards, Will

    Thursday, November 30, 2017 11:52 PM
  • User89714 posted

    @Will.Itrax - Can you post your code?

    I'm using a much older version of Xam.Plugin.DeviceInfo (version 2.1.2). I'll update it in a week or so, but both Platform and Idiom are working fine calling from PCL, using 2.1.2 on UWP.

    Friday, December 1, 2017 11:11 AM
  • User234750 posted

    @JohnHardman Thanks for your comments. Because of your experience, I reverted to several older versions. Either they behaved the same or the older ones were incompatible with my code. As for a copy of code, it is not possible to post it. I expect the issue stems from some weird disturbance cause by some version interaction. For now, I won't use Platform and Idiom for UWP - it is not central to the app.

    Friday, December 1, 2017 5:44 PM
  • User89714 posted

    @"Will.Itrax" - I didn't mention it before, but I don't see any point in using the DeviceInfo plugin to get Platform or Idiom (perhaps I'm missing something...)

    For Platform, you could use Xamarin.Forms.Device.RuntimePlatform . Or, what I do (as a result of previously supporting multiple Windows variations - WinPhone 8.0 SL, WinRT 8.1, WinPhone RT 8.1, UWP) is to set a globally accessible enum from each of my platform-specific projects.

    For Idiom, you could use Xamarin.Forms.Device.Idiom . Or, what I do, is to check whether functionality I need is available on the device, or to check the available screen dimensions. I figure it's safer if I explicitly check for what my app needs, or check screen dimensions before deciding whether to display one page, or more than one side-by-side, etc.

    The only place I actually use Xam.Plugin.DeviceInfo is on a page where I experiment with stuff, so not a page that will make it to production code.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, December 1, 2017 5:58 PM
  • User234750 posted

    @JohnHardman Thanks! Those are great alternatives.

    Friday, December 1, 2017 6:19 PM
  • User234750 posted

    Update: Other things in the app were acting weird, too - illogical - so I rolled back to a previous version of Xam.Plugin.DeviceInfo and Xamarin.Forms (2.4.0.280) and everything else, too. Now most things seem to be behaving properly for me. Edit: I thought Xam.Plugin.DeviceInfo was working as well, but only in Droid and iOS. Still broken for me in UWP. I'll try to find time to create a repro.

    Monday, December 4, 2017 6:15 PM
  • User368965 posted

    Can anyone explain what is DeviceID in CrossDeviceInfo? Is it device SR No? or Is it Device Mac Address?

    Tuesday, June 26, 2018 2:00 PM