Skip to content

UWP Notification Listener: Object reference not set to an instance of an object when trying to save app logo #21

Description

I am trying to save the logo as a file

             RandomAccessStreamReference stream = app.AppInfo.DisplayInfo.GetLogo(new Size(64, 64));
             IAsyncOperation<IRandomAccessStreamWithContentType> streamOperation = stream.OpenReadAsync();

I get an error on the second line: Object reference not set to an instance of an object.

The full code

            string appPackageName = notif.AppInfo.Id;
            string appDisplayName = notif.AppInfo.DisplayInfo.DisplayName;
            string Path = (Directory.GetCurrentDirectory() + "\\assets").Replace("\\\\", "\\");
            string Filename = Path + "\\" + appPackageName + ".png";
            
            if(!Directory.Exists(Path)){
                Directory.CreateDirectory(Path);
            }
         if (!File.Exists(Filename)) {
                RandomAccessStreamReference stream = notif.AppInfo.DisplayInfo.GetLogo(new Size(128, 128));
                IAsyncOperation<IRandomAccessStreamWithContentType> streamOperation = stream.OpenReadAsync();
                Task<IRandomAccessStreamWithContentType> streamTask = streamOperation.AsTask();
                streamTask.Wait();
                IRandomAccessStreamWithContentType content = streamTask.Result;

                FileStream TheFile = File.Create(Filename);
                content.AsStream().Seek(0, SeekOrigin.Begin);
                content.AsStream().CopyTo(TheFile);
                TheFile.Dispose();
            }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions