TROUBLESHOOTING DURING .NET6 MIGRATION
NET6 migration, there are some general issues that need to be addressed independent of Next Design.
Here are some issues that the Next Design development team has encountered and how to resolve them for your reference.
For more information, please refer to the official Microsoft literature.
- Error due to unavailability of namespace in System.Windows.Forms.
- Reactive Extensions interface does not exist and an error occurs
- The image will not be displayed.
- Warning displayed for null comparison with System.Windows.GridLength
Error due to unavailability of namespace in System.Windows.Forms.
phenomenon
NET6, if the UseWindowsForms attribute is not set to true in the project file, the System.Windows.Forms namespace is not available and an error will occur.
Example code 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 attribute to true in the project file that references the System.Windows.Forms namespace. To set the setting, edit the project file (project name.csproj) using Visual Studio or a text editor.
Example of a project file before resolution:
<!--csprojの設定-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup>
</Project>
Example of a resolved project file:
<!--csprojの設定-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
Reactive Extensions interface does not exist and an error occurs
phenomenon
NET6, the following interfaces in Reactive Extensions (hereafter referred to as Rx) have changed, NET6, the following interfaces in Reactive Extensions (hereafter referred to as Rx) have been changed, which may result in errors.
IObservable<TEventArgs>.ObserveOnDispatcher()
- Error message: the name 'DispatcherScheduler' does not exist in the current context
DispatcherScheduler
- Error message: 'IObservable
' does not contain a definition of 'ObserveOnDispatcher' and the type 'IObservable ' Could not find an accessible extension method 'ObserveOnDispatcher' that accepts the first argument of using Make sure you are not missing any directives or assembly references
- Error message: 'IObservable
Code Example:
m_TargetEventSubscription =
Throttle(EventThrottleSpan, DispatcherScheduler.Current)
.ObserveOnDispatcher(DispatcherPriority)
.SubscribeSafely(m_Handler, HandleEvent);.
Solution
This can be resolved by restoring the interface with reference to the following official Rx program.
- https://github.com/dotnet/reactive/blob/9f2a8090cea4bf931d4ac3ad071f4df147f4df50/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/DispatcherScheduler.cs
- https://github.com/dotnet/reactive/blob/9f2a8090cea4bf931d4ac3ad071f4df147f4df50/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Linq/DispatcherObservable.cs
The image will not be displayed.
phenomenon
NET6, the Sdk setting in the project file is Microsoft.NET.Sdk
and the UseWPF attribute is not set to true
the icons contained in that project will not be displayed when referenced from other projects.
This attribute may not be true for projects that do not implement views using WPF, for example.
Example of project setup:
<!--csprojの設定-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup>
</Project>
Solution
Set the UseWPF attribute to true in the project file. To set, edit the project file (project name.csproj) in Visual Studio or a text editor.
Example of project setup:
<!--csprojの設定-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>
</PropertyGroup>
</Project>
Warning displayed for null comparison with System.Windows.GridLength
phenomenon
IN .NET6 GridLength
will no longer tolerate null.
Therefore, GridLength
A warning is issued if an implementation is comparing objects of type null.
Code Example:
var length = new GridLength();
if(length == null)
{
// ...
}
Warning message:
The value of type 'GridLength' is never equal to 'null' of type 'GridLength?
Solution
GridLength
will never be null, so remove unnecessary implementations that are being compared to null.
Code Example:
var length = new GridLength();.
// ...