The app Works perfectly fine when I deploy it from VS 2015 (Windows 10) But the story is very different when I create the build from "Store > Create App Packages...", then install the app from the app from the powershell script.
I have isolated the problem to a section where I set an image for the lock screen. Whenever I click yes on the message dialog to change the lock screen I get a crash, I have attached the debugger and I only get the following exception:
Exception thrown at 0x00007FFA61091F08 (KernelBase.dll) in
ApplicationFrameHost.exe: 0x80010012:
The callee (server [not server application]) is not available
and disappeared; all connections are invalid. The call did not execute.
The code to reproduce the error is based on the following article:
public async Task<bool> ChangeLockScreenBackground()
{
bool success = false;
if (UserProfilePersonalizationSettings.IsSupported())
{
var uri = new Uri("ms-appx:///Assets/SplashScreen.scale-400.png");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);
UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
success = await profileSettings.TrySetLockScreenImageAsync(file);
}
return success;
}
I have no idea what is going on, I thought it was the capabilities of the app. But I have enabled User Account Information and Pictures Library and still no luck :(
Looks that you're using a file already opened: SplashScreen* and also from that folder may be you can't set the wallpaper.
Pay Attention: "Your app can't set wallpapers from any folder. Copy file in ApplicationData.Current.LocalFolder
and set wallpaper from there"
So I have changed the code a Little bit and also I put attention to documentation:
Remarks
Caution For the mobile device family, you can only set a lock screen image that is smaller than 2 megabytes (MB). Attempting to set a lock screen image that is larger fails, even though the async operation returns true.
Caution When you set an image more than once, the new image file must have a different name than the previously set image. If you set a new image using a file with the same name as the previous image, it will fail.
In this code I'm adding a file to Visual Studio Project in a folder called img, and setting the image properties to "Copy if newer". Then I load the image from such location.
async Task<bool> SetWallpaperAsync(string localAppDataFileName)
{
bool success = false;
var uri = new Uri($"ms-appx:///img/{localAppDataFileName}");
//generate new file name to avoid colitions
var newFileName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(localAppDataFileName)}";
if (UserProfilePersonalizationSettings.IsSupported())
{
var profileSettings = UserProfilePersonalizationSettings.Current;
var wfile = await StorageFile.GetFileFromApplicationUriAsync(uri);
//Copy the file to Current.LocalFolder because TrySetLockScreenImageAsync
//Will fail if the image isn't located there
using (Stream readStream = await wfile.OpenStreamForReadAsync(),
writestream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(newFileName,
CreationCollisionOption.GenerateUniqueName)
)
{ await readStream.CopyToAsync(writestream); }
StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(newFileName);
success = await profileSettings.TrySetLockScreenImageAsync(file);
}
Debug.WriteLine(success);
return success;
}
This code works perfectly in Windows Mobile 10, and because this is an Universal App you should expect it runs same way in Windows 10 Apps... and yes.
Letme know if this was enough for you.
User contributions licensed under CC BY-SA 3.0