gpt4 book ai didi

c# - UWP 发布版本崩溃但不在 Visual Studio 中

转载 作者:行者123 更新时间:2023-11-30 23:28:37 24 4
gpt4 key购买 nike

当我从 VS 2015 (Windows 10) 部署该应用程序时,该应用程序运行良好但是,当我从“Store > Create App Packages...”创建构建,然后从 powershell 脚本的应用程序安装应用程序时,情况就大不相同了。

我已将问题隔离到为锁定屏幕设置图像的部分。每当我在消息对话框中单击"is"以更改锁定屏幕时,我都会崩溃,我已经附加了调试器,但只收到以下异常:

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.

重现错误的代码基于以下文章:

https://msdn.microsoft.com/en-us/windows.system.userprofile.userprofilepersonalizationsettings.trysetlockscreenimageasync

    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;


}

我不知道发生了什么,我认为这是应用程序的功能。但是我已经启用了用户帐户信息和图片库,但仍然没有成功:(

最佳答案

看起来您正在使用一个已经打开的文件:SplashScreen* 并且来自该文件夹,您可能无法设置墙纸。

注意:“您的应用无法从任何文件夹设置壁纸。将文件复制到 ApplicationData.Current.LocalFolder 并从那里设置壁纸”

所以我对代码做了一点改动,我也把注意力放在了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.

在这段代码中,我将一个文件添加到 Visual Studio 项目中名为 img 的文件夹中,并将图像属性设置为“如果更新则复制”。然后我从这样的位置加载图像。

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;
}

此代码在 Windows Mobile 10 中完美运行,并且因为这是一个通用应用程序,您应该期望它在 Windows 10 应用程序中以相同的方式运行......是的。

让我知道这对你来说是否足够。

关于c# - UWP 发布版本崩溃但不在 Visual Studio 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35931399/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com