When I try to visualize a Graphics, an exception occurs:
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)
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.
When I try to visualize a Graphics, an exception occurs:
No problem when visualizing the Bitmap.
My code :
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:
The image: