c#Stream.Seek给了我一个';NullReferenceException';

c#Stream.Seek给了我一个';NullReferenceException';,c#,windows-phone-7,C#,Windows Phone 7,我正为这件事发疯。有人能在我的代码中发现这个注释后面的错误吗?因为它在突出显示的点上给了我一个NullReferenceException错误。。。。提前感谢您的建议 //retreive the picture from isolated storage Stream file = PicturesLoader.LoadFileFromStorage(PhoneApplicationService.Current.State[PictureCrop.PictureStateKe

我正为这件事发疯。有人能在我的代码中发现这个注释后面的错误吗?因为它在突出显示的点上给了我一个NullReferenceException错误。。。。提前感谢您的建议

    //retreive the picture from isolated storage
    Stream file = PicturesLoader.LoadFileFromStorage(PhoneApplicationService.Current.State[PictureCrop.PictureStateKey_Url].ToString());
    BitmapImage bi = new BitmapImage();
    bi.SetSource(file);

    //load _pic
    Picture _pic = new Picture();

    _pic.Name = "TempFile";
    _pic.Url = PhoneApplicationService.Current.State[PictureCrop.PictureStateKey_Url].ToString();
    _pic.Height = bi.PixelHeight;
    _pic.Width = bi.PixelWidth;
    _pic.Bitmap = bi;

    //save the new cropped image for later use
    file.Seek(0, SeekOrigin.Begin);
    App._capturedImage.SetSource(file); <------  THROWS ERROR HERE, suggest file  = NullReferenceException ???????????????????

    //Get rid of the stream....
    file.Dispose();
//从独立存储中检索图片
流文件=PicturesLoader.LoadFileFromStorage(PhoneApplicationService.Current.State[PictureCrop.PictureStateKey_Url].ToString());
BitmapImage bi=新的BitmapImage();
bi.SetSource(文件);
//装载图
图片_pic=新图片();
_pic.Name=“TempFile”;
_pic.Url=PhoneApplicationService.Current.State[PictureCrop.PictureStateKey_Url].ToString();
_图片高度=双像素高度;
_图片宽度=双像素宽度;
_pic.Bitmap=bi;
//保存新裁剪的图像以供以后使用
Seek(0,SeekOrigin.Begin);

App._capturedImage.SetSource(文件) 要么_capturedImage是空引用,要么(假设App是一个字段或属性而不是类名)App返回空引用。

黑暗中的镜头:可能
\u capturedImage
空的。

你不能在那一行上放一个断点而不是猜测吗?App,_capturedImage也可以为null。在这个代码段中,App和_apturedImage都是从天而降的。优秀的NRE候选人。文件变量不可用。使用调试器。我建议这样做。也许还有一门C#的基础课。谢谢克劳斯,我喜欢聪明的a**帮忙。碰巧我在自学c#,当你可以编写大型机时,i5和VB又回到了我身边,甜心:-很高兴能帮上忙。这发生在我们所有人身上:有时我们只是瞎了眼,看不见发生了什么,即使它就在那里,尖叫着。。。