koszeggy / KGySoft.Drawing.Tools

Debugger visualizers and image editor apps built on KGy SOFT Drawing Libraries
https://kgysoft.net/drawing
Other
19 stars 4 forks source link

Graphics causes an exception on .NET 5 #6

Closed ChrisBertrandIndus closed 2 years ago

ChrisBertrandIndus commented 3 years ago

When I try to visualize a Graphics, an exception occurs:

exception visualizing Graphics

No problem when visualizing the Bitmap.

My code :

        using (Bitmap b = new(@"c:\temp\Image 01_C - 24 bits.png"))
        {
            using (Graphics g = Graphics.FromImage(b))
            {
                g.DrawEllipse(Pens.Green, 10, 20, 100, 200);
                g.DrawString("hello", SystemFonts.DefaultFont, Brushes.Red, default(PointF));
            }
        }

The breakpoint is juste after g.Drawing so Graphics is not disposed.

VS : Version 16.11.4

Application : Windows Forms on .NET 5, 32 and 64 bits, Debug. dotnet --version : 5.0.401

Windows Update : up-to-date

No problem with a Windows Forms application on .NET Framework 4.8, 32 and 64 bits, Debug.

The stack:

     at KGySoft.Throw.InvalidOperationException(String message)
     at KGySoft.Reflection.Accessors.GetPropertyValue(Object instance, String propertyName)
     at KGySoft.Reflection.Accessors.IsSzArray(Type type)
     at KGySoft.CoreLibraries.TypeExtensions.IsZeroBasedArray(Type type)
     at KGySoft.Serialization.Binary.BinarySerializationFormatter.SerializationManager.WriteTypeNamesAndRanks(BinaryWriter bw, Type type, DataTypesEnumerator enumerator, Boolean allowOpenTypes)
     at KGySoft.Serialization.Binary.BinarySerializationFormatter.SerializationManager.WriteRootCollection(BinaryWriter bw, Object data, DataTypes dataType)
     at KGySoft.Serialization.Binary.BinarySerializationFormatter.SerializationManager.WriteRoot(BinaryWriter bw, Object obj)
     at KGySoft.Serialization.Binary.BinarySerializationFormatter.SerializeByWriter(BinaryWriter writer, Object data)
       at KGySoft.Serialization.Binary.BinarySerializer.SerializeByWriter(BinaryWriter writer, Object data, BinarySerializationOptions options)
       at KGySoft.Drawing.DebuggerVisualizers.Serialization.GraphicsSerializationInfo.Write(BinaryWriter bw)
       at KGySoft.Drawing.DebuggerVisualizers.Serialization.SerializationHelper.SerializeGraphicsInfo(Graphics g, Stream outgoingData)
     at KGySoft.Drawing.DebuggerVisualizers.Serialization.GraphicsSerializer.GetData(Object target, Stream outgoingData)
     at Microsoft.VisualStudio.DebuggerVisualizers.DebuggeeSide.Impl.ClrCustomVisualizerDebuggeeHost.GetData(Object visualizedObject)

The image: Image 01_C - 24 bits

koszeggy commented 3 years ago

Thank you for the report.

koszeggy commented 3 years ago

I fixed the root cause in the dependent library.

As it's targeting also .NET 6 and contains also a sort of .NET 6-relevant changes an actual release can be expected after the release date of .NET 6.0.

ChrisBertrandIndus commented 3 years ago

Thank you.

koszeggy commented 2 years ago

Fixed by v2.6.0