From 03b586d8ab008807417565a2468b728406a37f58 Mon Sep 17 00:00:00 2001 From: ElektroKill Date: Wed, 6 Sep 2023 21:14:17 +0200 Subject: [PATCH] Fixed nullability warnings --- .../TreeView/Resources/SerializedImageUtilities.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/Resources/SerializedImageUtilities.cs b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/Resources/SerializedImageUtilities.cs index ef778c4e7f..a7ef3939c8 100644 --- a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/Resources/SerializedImageUtilities.cs +++ b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/Resources/SerializedImageUtilities.cs @@ -180,7 +180,10 @@ public static ResourceElement Serialize(ResourceElement resElem, SerializationFo } else if (format == SerializationFormat.TypeConverterByteArray) { var converter = TypeDescriptor.GetConverter(obj.GetType()); - serializedData = (byte[])converter.ConvertTo(obj, typeof(byte[])); + var byteArr = converter.ConvertTo(obj, typeof(byte[])); + if (byteArr is not byte[] d) + throw new InvalidOperationException("Failed to serialize image"); + serializedData = d; } else if (format == SerializationFormat.ActivatorStream) { using (var stream = new MemoryStream()) { @@ -192,7 +195,7 @@ public static ResourceElement Serialize(ResourceElement resElem, SerializationFo } } else - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(format)); return new ResourceElement { Name = resElem.Name,