Troubleshooting .NET 6 migration


During the .NET 6 migration, there are also general items that need to be addressed independently of Next Design.
Here, we share the issues and solutions encountered by the Next Design development team as reference information.

For details, please refer to the official Microsoft documentation.

The System.Windows.Forms namespace cannot be used, resulting in an error.

Symptom

In .NET 6, if the UseWindowsForms property is not set to true in the project file, the System.Windows.Forms namespace cannot be used, resulting in an error.

Code example using the System.Windows.Forms namespace:

using System.Windows.Forms; namespace MyExt { /// <summary> /// エクステンションのエントリポイントです /// </summary> public class MyExtEntryPoint : ExtensionBase { /// <summary> /// アクティベート時の処理です。 /// </summary> protected override void OnActivate() { var form = new Form(); } } }

Solution

Set the UseWindowsForms property to true in the project file that references the System.Windows.Forms namespace. Edit the project file (project_name.csproj) using Visual Studio or a text editor.

Example of a project file before the fix:

<!--csprojの設定--> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net6.0-windows</TargetFramework> </PropertyGroup> </Project>

Example of a project file after the fix:

<!--csprojの設定--> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net6.0-windows</TargetFramework> <UseWindowsForms>true</UseWindowsForms> </PropertyGroup> </Project>

An error occurs because the Reactive Extensions interface does not exist.

Symptom

When migrating to .NET 6, certain interfaces in Reactive Extensions (hereinafter referred to as Rx) have been changed, which may cause previously used interfaces to become unavailable and result in an error.

Code example:

m_TargetEventSubscription = targetObservable.Throttle(EventThrottleSpan, DispatcherScheduler.Current) .ObserveOnDispatcher(DispatcherPriority) .SubscribeSafely(m_Handler, HandleEvent);

Solution

This can be resolved by restoring the interface referring to the official Rx program below.

Images are not displayed.

Symptom

In .NET 6, if the SDK setting in the project file is Microsoft.NET.Sdk , and the UseWPF property is not set to true, icons included in that project will not be displayed even if they are referenced from other projects.
In projects that do not implement views using WPF, this property may not be set to true.

Example of project settings:

<!--csprojの設定--> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net6.0-windows</TargetFramework> </PropertyGroup> </Project>

Solution

Set the UseWPF property to true in the project file. Edit the project file (project_name.csproj) using Visual Studio or a text editor.

Example of project settings:

<!--csprojの設定--> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net6.0-windows</TargetFramework> <UseWPF> </PropertyGroup> </Project>

A warning is displayed when comparing System.Windows.GridLength with null.

Symptom

In .NET 6, System.Windows.GridLength no longer allows null.
As a result, GridLength warnings will appear if you have an implementation that compares objects of type GridLength with null.

Code example:

var length = new GridLength(); if(length == null) { // ... }

Warning message:

The value of type 'GridLength' can never be equal to 'null' of type 'GridLength?', so the expression will always evaluate to 'false'

Solution

GridLength Since it will never be null, we will remove the redundant implementation comparing it to null.

Code example:

var length = new GridLength(); // ...