Parse with Windows Phone 8 Universal Apps - exception

I have a Windows 8.1 Universal app that I am using with Parse. I have downloaded the latest .NET libraries for Parse and included the Parse.dll and ParseWindows.dll in the Windows 8 project. The app works just fine with them.
I then include the Parse.dll and parsePhone.dll in the Windows Phone app. When the phone app runs, I get a FileNotFound exception when the ParseClient.initialize method is called. The method is in a static class within my Shared library, and is used by both projects. It works fine in the Windows 8 app, but throws the exception in the Windows Phone app.
This is the method that gets called, with the keys redacted.
public static class ParseCloudService
{
public static void InitializeParseCloudService()
{
try
{
ParseClient.Initialize("AppIdGoesHere", ".NETKey");
}
catch(ParseException)
{
throw;
}
}
}
Has anyone else ran in to this? Is there something that I'm supposed to be adding to the Windows Phone 8.1 app that the Parse library expects? Again, this is in a Universal app, and not a standard Windows Phone app project (previous posts I've made this gets confused).
Another interesting thing, is that even though I have this wrapped in a try/catch, the exception goes thrown within the Intialize() method, and never gets caught by my try/catch. If I set a break-point in my catch, the breakpoint never gets hit. It throws within Initialize(), then immediately breaks within app.g.i.cs file.
Could not load file or assembly 'System.Windows, Version=2.0.6.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.
and this is the stack trace:
at Parse.PlatformHooks.SettingsWrapper..ctor()
at Parse.PlatformHooks.SettingsWrapper.get_Wrapper()
at Parse.PlatformHooks.get_ApplicationSettings()
at Parse.ParseClient.get_ApplicationSettings()
at Parse.ParseClient.get_InstallationId()
at Parse.ParseClient.Initialize(String applicationId, String dotnetKey)
at Actions.Services.ParseCloud.ParseCloudService.InitializeParseCloudService()
at Actions.Services.ParseCloud.ParseCloudUserService..ctor()
at lambda_method(Closure , IBuilderContext )
at Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
Thanks in advance!

The Parse .NET SDK will not be updated to support Windows Phone 8.1.
Source: https://developers.facebook.com/bugs/327073484113608/

Related

Windows phone 8.1 app crashing while using libphonenumber-csharp

I am trying to use libphonenumber-csharp library for my windows phone project for validating international phone numbers. I have installed the library using the following command on nuget package manager console:
Install-Package libphonenumber-csharp
I am using the following click event handler to test the functionality of the library:
private void buttonCall_Click(object sender, RoutedEventArgs e)
{
String bdNumberStr = "0123456789";
PhoneNumbers.PhoneNumberUtil phoneUtil = PhoneNumbers.PhoneNumberUtil.GetInstance();
try
{
PhoneNumbers.PhoneNumber numberProto = phoneUtil.Parse(bdNumberStr, "BD");
}
catch (PhoneNumbers.NumberParseException exc)
{
Debug.WriteLine("NumberParseException was thrown: " + exc.Message);
}
}
The program is crashing after clicking the button. The event handler function is not getting hit and an exception is thrown. In output window it says something like the following:-
Loaded 'C:\Data\Programs{60688B3F-2E3D-46EE-B0DE-C1F3E22F0912}\Install\PhoneNumbers.DLL'. Cannot find or open the PDB file.
Does anyone have an idea whats going wrong here?
You can't use this package, this library built for desktops, not for Windows Phone or Store apps.
You need to port it by yourself or find another solution.

Portable Class Library - Windows Store App: "Could not load file or assembly Microsoft.Threading.Task"

I have an MVVM Light infrastructure which is all contained within a Portable Class Library targeting .Net 4, SL5, Win 8, WP 8.1, WPSL 8, Xamarin.Android and Xamarin.iOS. This works perfectly with a WPF client, however, when I try and use it in a Windows Store App/Win 8 environment I am coming up against some resistance. The first issue is found in App.xaml:
<Application
x:Class="Win8Client.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:INPS.Vision.Appointments.Shared.ViewModels"
xmlns:local="using:Win8Client">
<Application.Resources>
<vm:ViewModelLocator x:Key="Locator" />
</Application.Resources>
</Application>
At design time I get "Could not load file or assembly 'Microsoft.Threading.Tasks', version=1.0.12.0 ..." which is referring to my ViewModelLocator. This compiles and appears to run ok but I don't get any design time data. The design time data works fine in the WPF client.
Once running I see my first view but once this line gets called:
Slots = await _appointmentsDataProvider.GetAppointments(SelectedDate);
I get the following exception in the setter of my slots property which takes advantage of MVVM Lights Set method of ViewModelBase. The Slots property is NOT bound to any UI yet.
Exception:
"The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))"
Slots Property:
public List<Slot> Slots
{
get { return _slots; }
set
{
Set(SlotsPropertyName, ref _slots, value); // <-- Exception thrown here
}
}
Realised I haven't actually asked a question. Simply, I would like to know, what is the best approach for using MVVM Light with a Windows Store App?
Thanks in advance for any help or advice!
The first issue "Could not load file or assembly 'Microsoft.Threading.Tasks', version=1.0.12.0 ..." I haven't worked out yet but from time to time I do see the design data. Seems very temperamental...
The second issue - The reason this through me a bit was because is "just worked" in WPF and I assumed it would just work in a Windows Store App. Wrong. It looks like Windows Store Apps handle async/await threading differently - that's my guess.
Fix: Created an IDispatcherHelper interface in PCL with a single method declaration:
void RunOnUIThread(Action action);
Then created a single concrete DispatcherHelper class in each platform specific project (WPF/Windows 8.1) which implement IDispatcherHelper. Each implementation simply calls MVVM Lights:
DispatcherHelper.CheckBeginInvokeOnUI(action);
In App.xaml.cs in the WPF and Windows 8.1 I simply registered the concrete implementations with MVVM Lights SimpleIoc with the IDispatcherHelper as the handle. Within the view model I then use the platform specific implementations through the interface:
var slots = await _appointmentsDataProvider.GetAppointments(SelectedDate);
IDispatcherHelper dispatcherHelper = SimpleIoc.Default.GetInstance<IDispatcherHelper>();
dispatcherHelper.RunOnUIThread(() =>
{
Slots = slots;
});
Got to love abstraction!

how to lock the screen programmatically in windows phone 8?

We can prevent the screen to lock using the below code
PhoneApplicationService.Current.ApplicationIdleMode = IdleDetectionMode.Disabled
and
PhoneApplicationService.Current.UserIdleDetectionMode= IdleDetectionMode.Disabled
but how to lock the screen from my app. Like the below app
http://www.windowsphone.com/en-us/store/app/one-touch-lockscreen/a3b1220b-1f9a-4bf0-93bc-21ed02792279
Thanks in advance
It's pretty hacky. It's not in the official API, so it could stop working at any time, just like the volume control API. Anyway, it you want to do it, you need to use this external method:
[System.Runtime.InteropServices.DllImport("ShellChromeAPI.dll")]
private extern static void Shell_TurnScreenOn(bool value);
For WP8.0 app this needs to be in a Windows Runtime Component (you should reference its output, as the project cannot be referenced).
From what I understand, though, this won't work on WP8.1 devices, so you'll need a separate WP8.1 app and I think it needs to be a XAML (Windows Store) app.
What #yasen wrote is correct.
[DllImport("ShellChromeAPI.dll")]
private extern static void Shell_TurnScreenOn(bool value);
I've tried the following cases:
Runtime 8.1 C# (Passed store certification)
Runtime 8.1 C++ with Runtime Component 8.1 C# (Haven't tried to publish this in store)
Silverlight/DirectX 8.0 C++ (Passed store certification)
Here's the link to my app that's using the last solution mentioned above.
http://www.windowsphone.com/s?appid=38bf5918-025e-4f23-b515-2cac451a84ab
And I've heard about cases in store using Silverlight that supports 8.0 and 8.1.
You can get Screen is locked or not by Windows.Phone.System.SystemProtection.ScreenLocked
but Unfortunately There is no way to lock the screen via code in Windows Phone 7.x or 8.

stackoverflow exception on calling asmx service from scheduletaskagent in wp8

I have a wp8 project that references a wp8 class library. The class library has a service reference. I also have a wp8 task agent project that references the class library to update the live tiles. When calling the service methods from the phone project everything works great but when I call a service method from the task agent I start getting a stack overflow exception or out of memory exception.
protected override void OnInvoke(ScheduledTask task)
{
string userName = GetUserName(); //from isolated storage
MyServiceClient client = new MyServiceClient ();
client.GetDataCompleted += client_GetData;
client.GetDataAsync(username);
}
The error occurs on GetDataAsync. However when I use the same code in the phone app(not the task agent) everything is working fine.
Has anyone noticed something similar?
Thanks,
Kunal

What is the MvvmCross version of DeviceNetworkInformation.IsNetworkAvailable

I'm re-writing a Windows Phone app to make it cross platform using the excellent MvvmCross framework.
On Windows Phone I usually test DeviceNetworkInformation.IsNetworkAvailable to ensure I have a network connection before calling a REST service.
Is there a way of doing this in a cross-platform way using MvvmCross?
There is a cross-platform plugin Cirrious.MvvmCross.Plugins.Network specifically for Network functionality and this was originally built specifically to provide Reachability
However, sadly the WindowsPhone part of this isn't yet implemented! See https://github.com/MvvmCross/MvvmCross/blob/v3.1/Plugins/Cirrious/Network/Cirrious.MvvmCross.Plugins.Network.Phone/Plugin.cs
If you need Reachability within a cross-platform app including WindowsPhone, I'd probably opt for adding this Network plugin, and then also modifying your WindowsPhone Setup to register something like:
public class MyReachability : IMvxReachability
{
public bool IsHostReachable(string host)
return // something using DeviceNetworkInformation.IsNetworkAvailable
}
}
// registered in Setup using:
protected override void InitializeLastChance() {
base.InitializeLastChance();
Mvx.RegisterType<IMvxReachability, MyReachability>();
}
Longer term, I'd be happy to see a decent implementation pushed back into the MvvmCross repository.
Also linking this question to: MvvmCross Reachability on Windows Phone and Network state with mvvmcross?