Fatal error. Internal CLR error. (0x80131506) when DataObject.GetData(EnhancedMetaFile)
See original GitHub issue- .NET Core Version: .NET Core SDK (reflecting any global.json): Version: 3.1.201 Commit: b1768b4ae7
Runtime Environment: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.201\
Host (useful for support): Version: 3.1.3 Commit: 4a9f85e9f8
.NET Core SDKs installed: 3.1.201 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
- Have you experienced this same bug with .NET Framework?: No
Problem description: I have a console app that prints out the clipboard contents using System.Windows.Forms.IDataObject. When I do IDataObject.GetData(“EnhancedMetafile”) (verified that the format is available), the program crashes with this error:
Fatal error. Internal CLR error. (0x80131506)
at System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(IntPtr)
at System.Windows.Forms.DataObject+OleConverter.GetDataFromOleIStream(System.String)
at System.Windows.Forms.DataObject+OleConverter.GetDataFromBoundOleDataObject(System.String, Boolean ByRef)
at System.Windows.Forms.DataObject+OleConverter.GetData(System.String, Boolean)
at System.Windows.Forms.DataObject.GetData(System.String, Boolean)
at System.Windows.Forms.DataObject.GetData(System.String)
Expected behavior: No crash, should be able to access the data in the EMF
Minimal repro:
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (7 by maintainers)

Top Related StackOverflow Question
For me this repros when copying an image inside an email in Outlook (desktop). It is possible this broke in Windows or Office. I’m trying to find other sources of EMF to validate whether this is an Office or Windows bug, stay tuned.
What application (or API if its your own) did you use to provide the metafile data? I can repro with copying a metafile from inside Word, but I’m wondering what the scope of the problem is.
On which version of Desktop Framework have you tested this? (Installed version, the target version against which the project is compiled is irrelevant.) For me this crashes on fully patched Desktop Framework 4.8 as well, so this is not a regression in .NET Core.
For what its worth the crash happens here. Contrary to the documentation we get a
TYMED_ENHMFeven though WinForms asked for aTYMED_ISTREAM. Unconditionally turning that pointer into a COM interface crashes because there is no COM interface stored in the struct.This looks like a regression in Windows and/or the application which provided the data as the doc says:
If an error code were returned then
innerData.GetDatashould have thrown and the method been exited early.If you want to make WinForms more robust you can check the medium by replacing this check to make sure the code is operating on what it assumed to operate on
Though technically now you created a memory leak because you are not properly releasing the pointed-to data. Before adding general release logic to work around what looks like a bug in Windows and/or Office I’d like to dig into this a bit more since it looks like a Windows API semantic is violated here.