Reputation: 73
How can I fix this issue where the VS tells me that it might output null value of Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop").GetValue("TranscodedImageCache")
?
byte[] path = (byte[])Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop").GetValue("TranscodedImageCache");
String wallpaperFile = Encoding.Unicode.GetString(SliceMe(path, 24)).TrimEnd("\0".ToCharArray());
Upvotes: 0
Views: 261
Reputation: 4983
If using .NET 6, try the following:
using RegistryKey? subkey = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop");
byte[]? path = (byte[]?)subkey?.GetValue("TranscodedImageCache");
...
VS 2022:
In a .NET 6 project, the Nullable
setting can be found:
The following can also be seen in the .csproj
file: <Nullable>enable</Nullable>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
Resources:
Here's some additional resources that may be of interest:
Upvotes: 1