Skip to content

Commit

Permalink
Warning fixes: spring wave (#15747)
Browse files Browse the repository at this point in the history
* Fix duplicated trimming attributes warning in Markup.Xaml.Loader

* Fix nullability warnings

* Update ImageSharp to 2.1.8

* Removed obsolete attributes on ValueStore

* Ignore CA1815 on private API RenderTargetProperties

* Fix switch expression warnings

* Fix warnings in Vulkan project

* Only include PThread for WasmEnableThreads

* Rename pollfd to PollFd to fix CS8981

* Fix incompatible packages being used in ControlCatalog.Desktop

---------

Co-authored-by: Max Katz <maxkatz6@outlook.com>
  • Loading branch information
MrJul and maxkatz6 committed May 21, 2024
1 parent 1b27bf7 commit b30894c
Show file tree
Hide file tree
Showing 39 changed files with 111 additions and 103 deletions.
3 changes: 0 additions & 3 deletions build/Base.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- '!NET6_0_OR_GREATER' equivalent -->
<ItemGroup Condition="!('$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')))">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.6.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/ImageSharp.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.7" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.8" />
</ItemGroup>
</Project>
13 changes: 11 additions & 2 deletions build/SampleApp.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup Condition="'$(TargetFramework)'=='net461'" >
<OutputType>WinExe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)..\src\Avalonia.Desktop\Avalonia.Desktop.csproj" />

<ItemGroup Condition="'$(TargetFramework)'!='net461'">
<ProjectReference Include="$(MSBuildThisFileDirectory)../src/Avalonia.Desktop/Avalonia.Desktop.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net461'">
<ProjectReference Include="$(MSBuildThisFileDirectory)../src/Windows/Avalonia.Win32/Avalonia.Win32.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)../src/Skia/Avalonia.Skia/Avalonia.Skia.csproj" />
</ItemGroup>

<Target Name="GatherReferences" AfterTargets="CoreCompile">
<WriteLinesToFile File="$(TargetPath).refs"
Lines="@(ReferencePathWithRefAssemblies)"
Overwrite="true" />
</Target>

</Project>
5 changes: 2 additions & 3 deletions samples/ControlCatalog.Desktop/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Platform;
using ControlCatalog.NetCore;
using ControlCatalog.Pages;
Expand Down Expand Up @@ -29,7 +27,8 @@ public static AppBuilder BuildAvaloniaApp()
EmbedSample.Implementation = new EmbedSampleWin();
})
.UsePlatformDetect();
.UseWin32()
.UseSkia();

private static void ConfigureAssetAssembly(AppBuilder builder)
{
Expand Down
4 changes: 2 additions & 2 deletions samples/ControlCatalog/Pages/OpenGl/OpenGlContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private static void CheckError(GlInterface gl)
Console.WriteLine(err);
}

public string Info { get; private set; }
public string Info { get; private set; } = string.Empty;

public unsafe void Init(GlInterface GL, GlVersion version)
{
Expand Down Expand Up @@ -308,4 +308,4 @@ public void Deinit(GlInterface GL)

CheckError(GL);
}
}
}
8 changes: 4 additions & 4 deletions samples/ControlCatalog/Pages/OpenGl/OpenGlLeasePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public OpenGlLeasePage()
_knobs.PropertyChanged += KnobsPropertyChanged;
}

private void KnobsPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs change)
private void KnobsPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs change)
{
if (change.Property == GlPageKnobs.YawProperty
|| change.Property == GlPageKnobs.RollProperty
Expand All @@ -183,7 +183,7 @@ Parameters GetParameters() => new()
Yaw = _knobs!.Yaw, Pitch = _knobs.Pitch, Roll = _knobs.Roll, Disco = _knobs.Disco
};

private void ViewportAttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e)
private void ViewportAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
{
var visual = ElementComposition.GetElementVisual(_viewport!);
if(visual == null)
Expand All @@ -206,11 +206,11 @@ protected override Size ArrangeOverride(Size finalSize)
return size;
}

private void ViewportDetachedFromVisualTree(object sender, VisualTreeAttachmentEventArgs e)
private void ViewportDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
{
_visual?.SendHandlerMessage(new DisposeMessage());
_visual = null;
ElementComposition.SetElementChildVisual(_viewport, null);
base.OnDetachedFromVisualTree(e);
}
}
}
2 changes: 1 addition & 1 deletion samples/ControlCatalog/Pages/OpenGlPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Init(GlPageKnobs knobs)
_knobs.PropertyChanged += KnobsPropertyChanged;
}

private void KnobsPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs change)
private void KnobsPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs change)
{
if (change.Property == GlPageKnobs.YawProperty
|| change.Property == GlPageKnobs.RollProperty
Expand Down
3 changes: 2 additions & 1 deletion samples/GpuInterop/VulkanDemo/VulkanImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public unsafe class VulkanImage : IDisposable
ImportMemoryWin32HandleInfoKHR handleImport = default;
if (handleType == ExternalMemoryHandleTypeFlags.D3D11TextureBit && exportable)
{
_d3dTexture2D = D3DMemoryHelper.CreateMemoryHandle(vk.D3DDevice, size, Format);
var d3dDevice = vk.D3DDevice ?? throw new NotSupportedException("Vulkan D3DDevice wasn't created");
_d3dTexture2D = D3DMemoryHelper.CreateMemoryHandle(d3dDevice, size, Format);
using var dxgi = _d3dTexture2D.QueryInterface<SharpDX.DXGI.Resource1>();

handleImport = new ImportMemoryWin32HandleInfoKHR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ public AssemblyLoadContextH(string pluginPath, string name) : base(isCollectible
Unloading += (sender) =>
{
AvaloniaPropertyRegistry.Instance.UnregisterByModule(sender.Assemblies.First().DefinedTypes);
Application.Current.Styles.Remove(MainWindow.Style);
AssetLoader.InvalidateAssemblyCache(sender.Assemblies.First().GetName().Name);
MainWindow.Style= null;
if (MainWindow.Style is { } style)
Application.Current?.Styles.Remove(style);
AssetLoader.InvalidateAssemblyCache(sender.Assemblies.First().GetName().Name!);
MainWindow.Style = null;
};
}

protected override Assembly Load(AssemblyName assemblyName)
protected override Assembly? Load(AssemblyName assemblyName)
{
var assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
if (assemblyPath != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Threading;
Expand Down Expand Up @@ -33,11 +34,11 @@ private void InitializeComponent()
this.AttachDevTools();
}
}
private PlugTool _plugTool;
private PlugTool? _plugTool;
protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
test();
Test();
//Content = _plugTool.FindControl("UnloadableAssemblyLoadContextPlug.TestControl");


Expand Down Expand Up @@ -75,7 +76,7 @@ protected override void OnClosed(EventArgs e)


Thread.CurrentThread.IsBackground = false;
var weakReference = _plugTool.Unload();
var weakReference = _plugTool!.Unload();
while (weakReference.IsAlive)
{
GC.Collect();
Expand All @@ -88,16 +89,16 @@ protected override void OnClosed(EventArgs e)

}

public static IStyle Style;
public void test(){
public static IStyle? Style;

public void Test() {

//Notice : 你可以删除UnloadableAssemblyLoadContextPlug.dll所在文件夹中有关Avalonia的所有Dll,但这不是必须的
//Notice : You can delete all Dlls about Avalonia in the folder where UnloadableAssemblyLoadContextPlug.dll is located, but this is not necessary
FileInfo fileInfo = new FileInfo("..\\..\\..\\..\\UnloadableAssemblyLoadContextPlug\\bin\\Debug\\net7.0\\UnloadableAssemblyLoadContextPlug.dll");
var AssemblyLoadContextH = new AssemblyLoadContextH(fileInfo.FullName,"test");

var assembly = AssemblyLoadContextH.LoadFromAssemblyPath(fileInfo.FullName);
var assemblyDescriptorResolver =
_plugTool=new PlugTool();
_plugTool.AssemblyLoadContextH = AssemblyLoadContextH;

Expand All @@ -106,13 +107,13 @@ protected override void OnClosed(EventArgs e)
styleInclude.Source=new Uri("ControlStyle.axaml", UriKind.Relative);
styles.Add(styleInclude);
Style = styles;
Application.Current.Styles.Add(styles);
Application.Current!.Styles.Add(styles);
foreach (var type in assembly.GetTypes())
{
if (type.FullName=="AvaloniaPlug.Window1")
{
//创建type实例
Window instance = (Window)type.GetConstructor( new Type[0]).Invoke(null);
Window? instance = (Window)type.GetConstructor([])!.Invoke(null);

Dispatcher.UIThread.InvokeAsync(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ namespace UnloadableAssemblyLoadContext;

public class PlugTool
{
public AssemblyLoadContextH AssemblyLoadContextH;
public AssemblyLoadContextH? AssemblyLoadContextH;
public WeakReference Unload()
{
var weakReference = new WeakReference(AssemblyLoadContextH);
AssemblyLoadContextH.Unload();
AssemblyLoadContextH?.Unload();
AssemblyLoadContextH = null;
return weakReference;
}

public Control? FindControl(string type)
{
var type1 = AssemblyLoadContextH.Assemblies.
var type1 = AssemblyLoadContextH!.Assemblies.
FirstOrDefault(x => x.GetName().Name == "UnloadableAssemblyLoadContextPlug")?.
GetType(type);
if (type1.IsSubclassOf(typeof(Control)))
if (type1 is not null && type1.IsSubclassOf(typeof(Control)))
{
var constructorInfo = type1.GetConstructor( Type.EmptyTypes).Invoke(null) as Control;
var constructorInfo = type1.GetConstructor([])!.Invoke(null) as Control;
return constructorInfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,10 @@
</PropertyGroup>

<ItemGroup>
<Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
<AvaloniaResource Include="**\*.xaml">
<SubType>Designer</SubType>
</AvaloniaResource>
<AvaloniaResource Include="Assets\*" />
<AvaloniaResource Include="Assets\Fonts\*" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\"/>
<AvaloniaResource Include="Assets\**"/>
<Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />
<AvaloniaResource Include="**\*.xaml" />
</ItemGroup>

<ImportGroup>
<Import Project="..\..\..\build\BuildTargets.targets" Condition="Exists('..\..\..\build\BuildTargets.targets')" />
<Import Project="..\..\..\build\SourceGenerators.props" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:avaloniaPlug="clr-namespace:AvaloniaPlug"
xmlns:unloadableAssemblyLoadContextPlug="clr-namespace:UnloadableAssemblyLoadContextPlug"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="UnloadableAssemblyLoadContextPlug.Window1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System.Diagnostics;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using AvaloniaPlug;

namespace UnloadableAssemblyLoadContextPlug;

Expand Down
4 changes: 3 additions & 1 deletion src/Avalonia.Base/Compatibility/TrimmingAttributes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma warning disable MA0048 // File name must match type name
#nullable enable

#pragma warning disable MA0048 // File name must match type name
// https://github.com/dotnet/runtime/tree/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis

// Licensed to the .NET Foundation under one or more agreements.
Expand Down
5 changes: 4 additions & 1 deletion src/Avalonia.Base/Platform/RenderTargetProperties.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Diagnostics.CodeAnalysis;
using Avalonia.Metadata;

namespace Avalonia.Platform;

[PrivateApi]
[SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Private API, not meant to be compared")]
public struct RenderTargetProperties
{
/// <summary>
Expand All @@ -21,10 +23,11 @@ public struct RenderTargetProperties
}

[PrivateApi]
[SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Private API, not meant to be compared")]
public struct RenderTargetDrawingContextProperties
{
/// <summary>
/// Indicates that the drawing context targets a surface that preserved its contents since the previous frame
/// </summary>
public bool PreviousFrameIsRetained { get; init; }
}
}
2 changes: 0 additions & 2 deletions src/Avalonia.Base/PropertyStore/ValueStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ public void SetInheritanceParent(AvaloniaObject? newParent)
/// </summary>
/// <param name="entry">The binding entry.</param>
/// <param name="priority">The priority of binding which produced a new value.</param>
[Obsolete("TODO: Remove?")]
public void OnBindingValueChanged(
IValueEntry entry,
BindingPriority priority)
Expand Down Expand Up @@ -592,7 +591,6 @@ public void OnInheritedEffectiveValueDisposed<T>(StyledProperty<T> property, T o
/// </summary>
/// <param name="property">The previously bound property.</param>
/// <param name="observer">The observer.</param>
[Obsolete("TODO: Remove?")]
public void OnLocalValueBindingCompleted(AvaloniaProperty property, IDisposable observer)
{
if (_localValueBindings is not null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

namespace Avalonia.Rendering.Composition.Server;

/// <summary>

/// </summary>
internal partial class CompositorDrawingContextProxy : IDrawingContextImpl,
IDrawingContextWithAcrylicLikeSupport, IDrawingContextImplWithEffects
{
Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class DBusTrayIconImpl : ITrayIconImpl
private readonly OrgFreedesktopDBus? _dBus;

private IDisposable? _serviceWatchDisposable;
private StatusNotifierItemDbusObj? _statusNotifierItemDbusObj;
private readonly StatusNotifierItemDbusObj? _statusNotifierItemDbusObj;
private OrgKdeStatusNotifierWatcher? _statusNotifierWatcher;
private (int, int, byte[]) _icon;

Expand Down Expand Up @@ -115,7 +115,7 @@ private async void CreateTrayIcon()
await _dBus!.RequestNameAsync(_sysTrayServiceName, 0);
await _statusNotifierWatcher.RegisterStatusNotifierItemAsync(_sysTrayServiceName);

_statusNotifierItemDbusObj.SetTitleAndTooltip(_tooltipText);
_statusNotifierItemDbusObj!.SetTitleAndTooltip(_tooltipText);
_statusNotifierItemDbusObj.SetIcon(_icon);
_statusNotifierItemDbusObj.ActivationDelegate += OnClicked;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Avalonia.Vulkan/Avalonia.Vulkan.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
<Import Project="..\..\build\SourceGenerators.props" />
<Import Project="..\..\build\TrimmingEnable.props" />
<Import Project="..\..\build\NullableEnable.props" />

<ItemGroup>
<Compile Remove="..\Shared\SourceGeneratorAttributes.cs" />
</ItemGroup>

</Project>

0 comments on commit b30894c

Please sign in to comment.