C# ';System.IO.FileNotFoundException';
MyApp.DLL中出现“System.IO.FileNotFoundException” C#代码如下。错误指针在LockScreen.SetImageUri(uri)上指示“这是将要执行的下一条语句”C# ';System.IO.FileNotFoundException';,c#,windows-phone-8,C#,Windows Phone 8,MyApp.DLL中出现“System.IO.FileNotFoundException” C#代码如下。错误指针在LockScreen.SetImageUri(uri)上指示“这是将要执行的下一条语句” 请确保图像存在于指定位置,并且其生成操作属性设置为内容: 请确保图像存在于指定位置,并且其生成操作属性设置为内容: 将图像保存到独立存储,而不是项目文件夹。然后在需要时从独立存储中检索图像 var lockimageuri = new Uri("ms-appdata:///Local/"
请确保图像存在于指定位置,并且其
生成操作
属性设置为内容
:
请确保图像存在于指定位置,并且其
生成操作
属性设置为内容
:
将图像保存到独立存储,而不是项目文件夹。然后在需要时从独立存储中检索图像
var lockimageuri = new Uri("ms-appdata:///Local/" + "lockimage0.jpg", UriKind.Absolute);
LockScreen.SetImageUri(lockimageuri);
这里locimage0.jpg是存在于隔离存储器中的映像
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
string filePath = "lockimage0.jpg";
if (store.FileExists(filePath))
{
store.DeleteFile(filePath);
}
IsolatedStorageFileStream fileStream = store.CreateFile(filePath);
wbm.SaveJpeg(fileStream, wbm.PixelWidth, wbm.PixelHeight, 0, 100);
fileStream.Close();
}
下面是将图像保存到独立存储中的代码
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
string filePath = "lockimage0.jpg";
if (store.FileExists(filePath))
{
store.DeleteFile(filePath);
}
IsolatedStorageFileStream fileStream = store.CreateFile(filePath);
wbm.SaveJpeg(fileStream, wbm.PixelWidth, wbm.PixelHeight, 0, 100);
fileStream.Close();
}
也可以使用此方法从项目文件夹中读取本地图像
private WriteableBitmap ReadLocalImage(string Uri)
{
StreamResourceInfo sri = null;
Uri uri = new Uri(Uri, UriKind.Relative);
sri = Application.GetResourceStream(uri);
BitmapImage bitmap = new BitmapImage();
bitmap.CreateOptions = BitmapCreateOptions.None;
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
return wb;
}
这就是我在应用程序中实现自定义锁屏的方式
还要确保更新了清单文件
<Extensions>
<Extension ExtensionName="LockScreen_Background" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />
</Extensions>
将图像保存到独立存储,而不是项目文件夹。然后在需要时从独立存储中检索图像
var lockimageuri = new Uri("ms-appdata:///Local/" + "lockimage0.jpg", UriKind.Absolute);
LockScreen.SetImageUri(lockimageuri);
这里locimage0.jpg是存在于隔离存储器中的映像
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
string filePath = "lockimage0.jpg";
if (store.FileExists(filePath))
{
store.DeleteFile(filePath);
}
IsolatedStorageFileStream fileStream = store.CreateFile(filePath);
wbm.SaveJpeg(fileStream, wbm.PixelWidth, wbm.PixelHeight, 0, 100);
fileStream.Close();
}
下面是将图像保存到独立存储中的代码
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
string filePath = "lockimage0.jpg";
if (store.FileExists(filePath))
{
store.DeleteFile(filePath);
}
IsolatedStorageFileStream fileStream = store.CreateFile(filePath);
wbm.SaveJpeg(fileStream, wbm.PixelWidth, wbm.PixelHeight, 0, 100);
fileStream.Close();
}
也可以使用此方法从项目文件夹中读取本地图像
private WriteableBitmap ReadLocalImage(string Uri)
{
StreamResourceInfo sri = null;
Uri uri = new Uri(Uri, UriKind.Relative);
sri = Application.GetResourceStream(uri);
BitmapImage bitmap = new BitmapImage();
bitmap.CreateOptions = BitmapCreateOptions.None;
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
return wb;
}
这就是我在应用程序中实现自定义锁屏的方式
还要确保更新了清单文件
<Extensions>
<Extension ExtensionName="LockScreen_Background" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />
</Extensions>
似乎
ms-appx:///Assets/1.jpg
不存在。是否确实可以访问此文件?请确保路径正确。是否已将映像的BuildAction属性设置为Content?更改路径时发生System.Windows.ApplicationUnhandledException。请告诉我这条路是怎么走的。我记得我在最近的一次应用程序更新中遇到过类似的情况。我知道这听起来很疯狂,但如果您使用尝试
/捕获
忽略异常,锁屏图像是否仍然正确设置(即,可能找不到的不是您的文件)?似乎ms-appx:///Assets/1.jpg
不存在。是否确实可以访问此文件?请确保路径正确。是否已将映像的BuildAction属性设置为Content?更改路径时发生System.Windows.ApplicationUnhandledException。请告诉我这条路是怎么走的。我记得我在最近的一次应用程序更新中遇到过类似的情况。我知道这听起来很疯狂,但如果您使用try
/catch
忽略异常,锁屏图像是否仍然正确设置(即,可能找不到的不是您的文件)?我已检查图像是否存在于指定位置,并且其构建操作属性设置为内容。我复制并粘贴了您的代码,这种配置对我很有效。所以错误不是由代码引起的,那么为什么会显示异常?我不知道。如果您试图在新项目中重现错误,是否也会发生错误?我已创建了三次项目,但所有这些都有相同的异常。我已检查图像是否存在于指定位置,并且其“生成操作”属性设置为“内容”。我复制并粘贴了您的代码,这种配置对我很有效。所以错误不是由代码引起的,那么为什么会显示异常?我不知道。如果你试图在一个新项目中重现错误,它也会发生吗?我已经创建了三次我的项目,但所有这些都有相同的例外。