When AutoCAD 2027 was first released with .NET 10 support, many developers encountered a critical regression: drag-and-drop operations from custom palettes to the drawing area would crash with an InvalidCastException.
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject'
to interface type 'System.Windows.Forms.IDataObject'.
QueryInterface call failed with E_NOINTERFACE (0x80004002).
What Caused It?
This was a compatibility issue introduced by breaking changes in .NET 9 (which carried over into .NET 10):
- PR dotnet/winforms#10759 changed how
Control.DoDragDrop()wraps data objects. System.Windows.Forms.IDataObjectlost its COM visibility in .NET 5 (PR #3388).- AutoCAD’s internal drag-and-drop handler was no longer able to cast the COM object.
Affected Versions
- AutoCAD 2024–2026 (.NET Framework 4.8 / .NET 8) — Worked fine
- AutoCAD 2027 RTM (.NET 10) — Broken
Reproducing the Issue
The following minimal palette/command reproduces the crash. Starting a drag from the list box and dropping it onto the drawing area throws the InvalidCastException shown above on AutoCAD 2027 RTM:
public class ExtensionApplication : IExtensionApplication
{
public void Initialize()
{
// Initialization code if needed
}
public void Terminate()
{
// Cleanup code if needed
}
}
public class DragDropTestCommand
{
static PaletteSet s_paletteSet;
[CommandMethod("DRAGDROPTEST")]
public void ShowDragDropPalette()
{
if (s_paletteSet == null)
{
s_paletteSet = new PaletteSet("DragDrop PoC",
new Guid("A1B2C3D4-E5F6-7890-ABCD-EF1234567890"))
{
Style = PaletteSetStyles.ShowCloseButton
| PaletteSetStyles.ShowAutoHideButton,
MinimumSize = new System.Drawing.Size(200, 150)
};
var host = TestDragPalette.CreateControl();
s_paletteSet.Add("Drag Items", host);
}
s_paletteSet.Visible = true;
}
}
public sealed class TestDropTarget : DropTarget
{
public override void OnDrop(DragEventArgs e)
{
var doc = AcadApp.DocumentManager.MdiActiveDocument;
doc?.Editor.WriteMessage("\nTestDropTarget.OnDrop reached — drop succeeded.\n");
}
}
public static class TestDragPalette
{
static Point _dragStart;
const double DragThreshold = 5.0;
public static System.Windows.Forms.Control CreateControl()
{
var listBox = new ListBox { SelectionMode = SelectionMode.Single };
listBox.Items.Add("Asset A");
listBox.Items.Add("Asset B");
listBox.Items.Add("Asset C");
listBox.PreviewMouseLeftButtonDown += (s, e) =>
{
_dragStart = e.GetPosition(listBox);
};
listBox.PreviewMouseMove += (s, e) =>
{
if (e.LeftButton != MouseButtonState.Pressed)
return;
var pos = e.GetPosition(listBox);
if (System.Math.Abs(pos.X - _dragStart.X) < DragThreshold &&
System.Math.Abs(pos.Y - _dragStart.Y) < DragThreshold)
return;
if (listBox.SelectedItem == null)
return;
// This call reproduces the crash.
// AutoCAD internally casts the OLE IDataObject to
// System.Windows.Forms.IDataObject, which fails on .NET 8+
// because that interface is no longer COM-visible.
using (var button = new System.Windows.Forms.Button())
{
Autodesk.AutoCAD.ApplicationServices.Application.DoDragDrop(
button,
listBox.SelectedItem,
System.Windows.Forms.DragDropEffects.All,
new TestDropTarget());
}
};
var host = new ElementHost { Child = listBox, Dock = System.Windows.Forms.DockStyle.Fill };
return host;
}
}
The Fix
Autodesk resolved the InvalidCastException reproduced above in AutoCAD 2027 Update 1 — the drag-and-drop path in the example works again after installing the update.
Custom-Type Drag Payloads and BinaryFormatter
Reader Norman Yuan flagged that Update 1 doesn’t cover every drag-and-drop scenario: code that passes a custom object through IDataObject.SetData(Type, object) still fails on 2027.1 — not with an exception this time, but silently. e.Data.GetFormats() correctly lists the custom type’s format, yet e.Data.GetData(typeof(T)) comes back null.
This is a separate issue from the one this post covers, and it’s out of scope for AutoCAD to fix directly. SetData/GetData for non-native types relied on BinaryFormatter to marshal the payload across the OLE/COM boundary, and BinaryFormatter is removed by default starting .NET 9/10 — a deliberate Microsoft security decision, not an AutoCAD regression. Update 1’s fix was intentionally scoped to the exception reproduced above; it was never going to restore BinaryFormatter-based marshaling.
See Microsoft’s guidance on migrating off BinaryFormatter: BinaryFormatter migration guide.
The fix is straightforward: don’t hand a custom object to SetData at all — serialize it yourself and pass a string instead. Strings marshal natively across the OLE boundary and never touch the broken path:
// Before — relies on BinaryFormatter, silently returns null on 2027.1
IDataObject dataObject = new DataObject();
dataObject.SetData(typeof(CircleInfo), circle);
...
var data = e.Data.GetData(typeof(CircleInfo)); // always null
// After — JSON round-trip, confirmed working on AutoCAD 2027 Update 1
string json = JsonSerializer.Serialize(payload);
dataObject.SetData(typeof(string), json);
...
var json = e.Data.GetData(typeof(string)) as string;
var payload = JsonSerializer.Deserialize<TPayload>(json);
The same approach is behind Norman’s own published workaround. If you’d rather use the built-in .NET 10 equivalent instead of rolling your own JSON step, see Clipboard.SetDataAsJson<T>() / Clipboard.TryGetData<T>().
Download the Fix
You can download the update directly from the Autodesk Portal:
Download AutoCAD 2027 Update 1
After the Fix
The repro command above, running on AutoCAD 2027 Update 1:

Leave a Reply