question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
asklarcommented, Apr 1, 2020

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.

1reaction
weltkantecommented, Apr 2, 2020

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.

Have you experienced this same bug with .NET Framework?: No

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_ENHMF even though WinForms asked for a TYMED_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 the data object cannot comply with the information specified in the FORMATETC, the method should return DV_E_FORMATETC.

If an error code were returned then innerData.GetData should 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

- if (medium.unionmember != IntPtr.Zero)
+ if (formatetc.tymed == TYMED.TYMED_ISTREAM && medium.unionmember != IntPtr.Zero)

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the meaning of the runtime error - internal CLR ...
I got the error 'internal clr error 0x80131506' and the program being debugged crashed. It's .NET Core 3.1 running on Windows 10 x64....
Read more >
Fatal error. Internal CLR error. (0x80131506) : r/csharp
Fatal error. Internal CLR error. (0x80131506). Hi,. I started learning C# recently using the Microsoft Learn course and I have successfully ...
Read more >
c# Internal CLR error (0x80131506) caused by Regex. ...
Finaly I found the reason for the exception. It was a dll import of the WinScard. dll with a Unicode charset. Switching to...
Read more >
Fatal error. Internal CLR error. (0x80131506) during ...
Hi,. I'm debugging an asp.net 5 web application due to a strange issue. I have set my break point where I guess this...
Read more >
HTML5 Fatal error. Internal CLR error. (0x80131506)
Hey I'm trying to run my game in html and I keep getting this error: "Fatal error. Internal CLR error. (0x80131506)" There's no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found