Fix some new error/warnings from .NET 8

This commit is contained in:
Max Katz
2024-02-07 23:35:00 -08:00
parent 5551a6cc1b
commit 7cab284b89
10 changed files with 32 additions and 7 deletions
+2 -2
View File
@@ -8,7 +8,7 @@
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
<IsAotCompatible Condition="'$(IsAotCompatible)' == ''">true</IsAotCompatible>
</PropertyGroup>
<!-- Remove check for the AOT when we get rid of dependencies with reflection -->
@@ -17,7 +17,7 @@
<!-- Trim warnings -->
<WarningsAsErrors>$(WarningsAsErrors);IL2000;IL2001;IL2002;IL2003;IL2004;IL2005;IL2006;IL2007;IL2008;IL2009;IL2010;IL2011;IL2012;IL2013;IL2014;IL2015;IL2016;IL2017;IL2018;IL2019;IL2020;IL2021;IL2022;IL2023;IL2024;IL2025;IL2026;IL2027;IL2028;IL2029;IL2030;IL2031;IL2032;IL2033;IL2034;IL2035;IL2036;IL2037;IL2038;IL2039;IL2040;IL2041;IL2042;IL2043;IL2044;IL2045;IL2046;IL2047;IL2048;IL2049;IL2050;IL2051;IL2052;IL2053;IL2054;IL2055;IL2056;IL2057;IL2058;IL2059;IL2060;IL2061;IL2062;IL2063;IL2064;IL2065;IL2066;IL2067;IL2068;IL2069;IL2070;IL2071;IL2072;IL2073;IL2074;IL2075;IL2076;IL2077;IL2078;IL2079;IL2080;IL2081;IL2082;IL2083;IL2084;IL2085;IL2086;IL2087;IL2088;IL2089;IL2090;IL2091;IL2092;IL2093;IL2094;IL2095;IL2096;IL2097;IL2098;IL2099;IL2100;IL2101;IL2102;IL2103;IL2104;IL2105;IL2106;IL2107;IL2108;IL2109;IL2110;IL2111;IL2112;IL2113;IL2114;IL2115;IL2116;IL2117;IL2118;IL2119;IL2120;IL2121;IL2122;IL2123;IL2124;IL2125;IL2126;IL2127;IL2128;IL2129;IL2130;IL2131;IL2132;IL2133;IL2134;IL2135;IL2136;IL2137;IL2138;IL2139;IL2140;IL2141;IL2142;IL2143;IL2144;IL2145;IL2146;IL2147;IL2148;IL2149;IL2150;IL2151;IL2152;IL2153;IL2154;IL2155;IL2156;IL2157</WarningsAsErrors>
<!-- NativeAOT warnings -->
<WarningsAsErrors>$(WarningsAsErrors);IL3050;IL3051;IL3052;IL3053;IL3054;IL3055;IL3056</WarningsAsErrors>
<WarningsAsErrors Condition="'$(IsAotCompatible)' == 'true'">$(WarningsAsErrors);IL3050;IL3051;IL3052;IL3053;IL3054;IL3055;IL3056</WarningsAsErrors>
</PropertyGroup>
</Project>
@@ -15,7 +15,12 @@ namespace Avalonia.Controls.Primitives
private static readonly Dictionary<KnownColor, string> _cachedKnownColorNames = new Dictionary<KnownColor, string>();
private static readonly object _displayNameCacheMutex = new object();
private static readonly object _knownColorCacheMutex = new object();
private static readonly KnownColor[] _knownColors = (KnownColor[])Enum.GetValues(typeof(KnownColor));
private static readonly KnownColor[] _knownColors =
#if NET6_0_OR_GREATER
Enum.GetValues<KnownColor>();
#else
(KnownColor[])Enum.GetValues(typeof(KnownColor));
#endif
/// <summary>
/// Gets the relative (perceptual) luminance/brightness of the given color.
@@ -73,6 +73,7 @@ namespace Metsys.Bson
namespace Metsys.Bson
{
[RequiresUnreferencedCode("Bson uses reflection")]
[UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "Bson uses reflection")]
internal class Serializer
{
private static readonly IDictionary<Type, Types> _typeMap = new Dictionary<Type, Types>
@@ -615,6 +616,8 @@ namespace Metsys.Bson
namespace Metsys.Bson
{
[RequiresUnreferencedCode("Bson uses reflection")]
[UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "Bson uses reflection")]
internal class MagicProperty
{
private readonly PropertyInfo _property;
@@ -689,6 +692,7 @@ namespace Metsys.Bson
namespace Metsys.Bson
{
[RequiresUnreferencedCode("Bson uses reflection")]
[UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "Bson uses reflection")]
internal class TypeHelper
{
private static readonly IDictionary<Type, TypeHelper> _cachedTypeLookup = new Dictionary<Type, TypeHelper>();
@@ -791,6 +795,7 @@ namespace Metsys.Bson
namespace Metsys.Bson
{
[RequiresUnreferencedCode("Bson uses reflection")]
[UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "Bson uses reflection")]
internal class ListWrapper : BaseWrapper
{
private IList _list;
@@ -826,6 +831,7 @@ namespace Metsys.Bson
namespace Metsys.Bson
{
[RequiresUnreferencedCode("Bson uses reflection")]
[UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "Bson uses reflection")]
internal static class ListHelper
{
public static Type GetListItemType(Type enumerableType)
@@ -871,6 +877,7 @@ namespace Metsys.Bson
namespace Metsys.Bson
{
[RequiresUnreferencedCode("Bson uses reflection")]
[UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "Bson uses reflection")]
internal class CollectionWrapper<T> : BaseWrapper
{
private ICollection<T> _list;
@@ -899,6 +906,7 @@ namespace Metsys.Bson
namespace Metsys.Bson
{
[RequiresUnreferencedCode("Bson uses reflection")]
[UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "Bson uses reflection")]
internal abstract class BaseWrapper
{
public static BaseWrapper Create(Type type, Type itemType, object existingContainer)
@@ -956,6 +964,7 @@ namespace Metsys.Bson
namespace Metsys.Bson
{
[RequiresUnreferencedCode("Bson uses reflection")]
[UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "Bson uses reflection")]
internal class ArrayWrapper<T> : BaseWrapper
{
private readonly List<T> _list = new List<T>();
@@ -1008,6 +1017,7 @@ namespace Metsys.Bson
namespace Metsys.Bson
{
[RequiresUnreferencedCode("Bson uses reflection")]
[UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "Bson uses reflection")]
internal class Deserializer
{
internal class Options
@@ -20,7 +20,11 @@ namespace Avalonia.LinuxFramebuffer.Input.EvDev
Fd = fd;
_dev = dev;
Name = Marshal.PtrToStringAnsi(NativeUnsafeMethods.libevdev_get_name(_dev));
#if NET6_0_OR_GREATER
foreach (EvType type in Enum.GetValues<EvType>())
#else
foreach (EvType type in Enum.GetValues(typeof(EvType)))
#endif
{
if (NativeUnsafeMethods.libevdev_has_event_type(dev, type) != 0)
EventTypes.Add(type);
@@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<IsAotCompatible>false</IsAotCompatible>
<DefineConstants>$(DefineConstants);XAMLX_INTERNAL;XAML_RUNTIME_LOADER</DefineConstants>
</PropertyGroup>
<ItemGroup>
@@ -255,7 +255,8 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings
{
Method = MethodBase.GetMethodFromHandle(method) as MethodInfo
?? throw new ArgumentException("Invalid method handle", nameof(method));
DelegateType = Type.GetTypeFromHandle(delegateType);
DelegateType = Type.GetTypeFromHandle(delegateType)
?? throw new ArgumentException("Unexpected null returned from Type.GetTypeFromHandle in MethodAsDelegateElement");
}
public MethodInfo Method { get; }
@@ -2,6 +2,8 @@
<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- We still keep BinaryFormatter for WinForms compatibility. -->
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
+2 -1
View File
@@ -41,6 +41,7 @@ namespace Avalonia.Win32
}
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "We still use BinaryFormatter for WinForms dragndrop compatability")]
[UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "We still use BinaryFormatter for WinForms dragndrop compatability")]
private unsafe object? GetDataFromOleHGLOBAL(string format, DVASPECT aspect)
{
var formatEtc = new Interop.FORMATETC();
@@ -75,8 +76,8 @@ namespace Avalonia.Win32
using (var ms = new MemoryStream(data))
{
ms.Position = DataObject.SerializedObjectGUID.Length;
BinaryFormatter binaryFormatter = new BinaryFormatter();
#pragma warning disable SYSLIB0011 // Type or member is obsolete
BinaryFormatter binaryFormatter = new BinaryFormatter();
return binaryFormatter.Deserialize(ms);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
}
+2 -2
View File
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
@@ -536,7 +536,7 @@ namespace Avalonia.Win32
return PixelSize.Empty;
}
DwmGetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS, out var clientRect, Marshal.SizeOf(typeof(RECT)));
DwmGetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS, out var clientRect, Marshal.SizeOf<RECT>());
GetWindowRect(_hwnd, out var frameRect);
var borderWidth = GetSystemMetrics(SystemMetric.SM_CXBORDER);
@@ -3,6 +3,7 @@
<OutputType>Exe</OutputType>
<TargetFrameworks>net461;netstandard2.0;net6.0</TargetFrameworks>
<DefineConstants>$(DefineConstants);XAMLX_INTERNAL</DefineConstants>
<IsAotCompatible>false</IsAotCompatible>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Avalonia.DesignerSupport\Avalonia.DesignerSupport.csproj" />