How to configure XLabs Resolver on Windows phone ?

BogdanUngureanuBogdanUngureanu USMember
edited December 2016 in Xamarin.Forms

Dear all,

Trying to launch a Windows Phone app built with forms, XLabs installed, the following error occurs in App.cs:

    An exception of type 'System.IO.FileNotFoundException' occurred in XLabs.Platform.WP8.DLL but was not handled in user code  Additional information: Could not load file or assembly 'Microsoft.Devices.Sensors'

The error is indicated at the following line:
resolverContainer.Register(t => WindowsPhoneDevice.CurrentDevice);
before the
Xamarin.Forms.Forms.Init(e);

Full code before Init:
rootFrame.CacheSize = 1;

            var resolverContainer = new SimpleContainer();

            resolverContainer.Register<IDevice>(t => WindowsPhoneDevice.CurrentDevice);
            Resolver.ResetResolver();
            Resolver.SetResolver(resolverContainer.GetResolver());
            Xamarin.Forms.Forms.Init(e);

            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                // TODO: Load state from previously suspended application
            }

Any idea why this is happening?

Thank you

Best Answer

Answers

  • Nobody? @JamesMontemagno @AdamP can you help out a fellow coder in a bit of distress?

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @BogdanUngureanu - Microsoft.Devices.Sensors was used in Windows Phone 8 and 8.1 Silverlight, both of which are deprecated in Xamarin Forms. Windows.Devices.Sensors is what is used from WinRT 8.1 onwards.

    Hence I am speculating that you have a Windows Phone 8.1 Runtime Application (as per the default XF template) and you are trying to run a 8.1 silverlight based component.

    Do you have the right XLabs packages installed? I'm not too familiar with XLabs so I am not sure on the specifics on what you should have.

  • BogdanUngureanuBogdanUngureanu USMember
    edited December 2016

    @AdamP

    Hello Adam, nice to hear from you again! Regarding XLabs, I have used it for the Droid project so far with no issues, however when trying to run the WP8.1 app, the above error comes up. The same XLabs version is installed in all the projects, when trying to Init() the app, that's when the error appears. It's searching for the namespace inside the XLabs assembly for some reason, although I am not using the specified library explicitly..

    The reason behind the use of XLabs was to get the Device height using it's device resolver.

  • @AdamP - from my understanding the Height and Width calculations from XF differ, I tried to read them on page initialization, then on the OnAppearing event, and each time they returned a value of 1. The documentation said that it still hasn't finished calculating.

    I will give your approach a try in the following hours, it seems the best suggestion to use DependencyService and get the platform specific values once loaded ( I hope they are loaded when I call them ).

    Thank you!

Sign In or Register to comment.