<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/investigating-an-invalidprogramexception-from-a-memory-dump-part-1-of-3--ikpmkjtdn" -->

---
title: Investigating an InvalidProgramException from a memory...
description: A deep technical walkthrough of debugging an InvalidProgramException reported by a Datadog .NET profiler customer, using a memory dump captured on Linux. The...
canonical: https://daily.dev/posts/investigating-an-invalidprogramexception-from-a-memory-dump-part-1-of-3--ikpmkjtdn
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Investigating an InvalidProgramException from a memory dump (part 1 of 3) | daily.dev
og:description: A deep technical walkthrough of debugging an InvalidProgramException reported by a Datadog .NET profiler customer, using a memory dump captured on Linux. The...
og:url: https://daily.dev/posts/investigating-an-invalidprogramexception-from-a-memory-dump-part-1-of-3--ikpmkjtdn
og:image: https://api.daily.dev/og/posts/IKpmkjtdN.png
og:image:alt: Investigating an InvalidProgramException from a memory dump (part 1 of 3)
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Investigating an InvalidProgramException from a memory dump (part 1 of 3)

**[Kevin Gosse \(minidump.net\)](https://daily.dev/sources/minidump)** · 10 min read · 0 upvotes · 0 comments

## Summary

A deep technical walkthrough of debugging an InvalidProgramException reported by a Datadog .NET profiler customer, using a memory dump captured on Linux. The investigation uses dotnet-dump commands (clrthreads, dumpheap, pe, ip2md, dumpil) to trace the exception back through an AggregateException rethrow that destroyed the original stack trace, eventually narrowing the root cause down to Npgsql's LoadBackendTypes method, a candidate for IL rewriting by the profiler's instrumentation. The investigation continues in subsequent parts.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://minidump.net/investigating-an-invalidprogramexception-from-a-memory-dump-part-1-of-3-bce634460cc3>

## Questions this post answers

### How can I find an InvalidProgramException object in a .NET memory dump if it wasn't captured at the moment of the first-chance exception?

Use the dumpheap -stat -type InvalidProgramException command in dotnet-dump or WinDbg to locate surviving exception objects on the heap, since they remain there if no garbage collection occurred after the throw. Then use dumpheap -mt with the method table address to get object addresses, and printexception (pe) on each address to retrieve the stack trace.

_Developers tracking down memory-dump mysteries can follow deep debugging write-ups like this one on daily.dev._

### Why does rethrowing task.Exception.InnerExceptions[0] inside a ContinueWith callback hide the original stack trace?

Throwing an inner exception directly, instead of using ExceptionDispatchInfo to rethrow it, overwrites the exception's original callstack with the new throw location inside the ContinueWith lambda. This makes the reported stack trace point to the rethrow site rather than where the exception actually originated, making root-cause analysis far harder.

_Anyone debugging misleading .NET stack traces can find similar exception-handling pitfalls on daily.dev._

## Similar posts on daily.dev

- [Creating a memory dump in C\#](https://daily.dev/posts/creating-a-memory-dump-in-c--torykruun) · .NET Blog · 16 upvotes · 0 comments
- [Today I will… debug a production crash](https://daily.dev/posts/today-i-will-debug-a-production-crash-oix9ikedw) · Visual Studio Blog · 11 upvotes · 1 comments
- [Inside .NET Loader Analysis: From Malspam to In-Memory Loader](https://daily.dev/posts/inside-net-loader-analysis-from-malspam-to-in-memory-loader-tafajwltg) · Huntress Blog · 4 upvotes · 0 comments

---

Tags: [#.net](https://daily.dev/tags/.net)

[View this post on daily.dev](https://daily.dev/posts/investigating-an-invalidprogramexception-from-a-memory-dump-part-1-of-3--ikpmkjtdn)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Investigating an InvalidProgramException from a memory dump (part 1 of 3)","url":"https://daily.dev/posts/investigating-an-invalidprogramexception-from-a-memory-dump-part-1-of-3--ikpmkjtdn","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/investigating-an-invalidprogramexception-from-a-memory-dump-part-1-of-3--ikpmkjtdn"},"datePublished":"2026-10-04T13:06:25.606Z","dateModified":"2026-10-04T13:09:42.942Z","description":"A deep technical walkthrough of debugging an InvalidProgramException reported by a Datadog .NET profiler customer, using a memory dump captured on Linux. The...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/1056987b22c10d2dfbafaf2334787e56?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/1056987b22c10d2dfbafaf2334787e56?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Kevin Gosse (minidump.net)","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Kevin Gosse (minidump.net)","logo":"https://media.daily.dev/image/upload/s--8KHn1aFB--/f_auto,q_auto/v1791119046/logos/minidump?_a=BAMAMicg0","url":"https://daily.dev/sources/minidump"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/investigating-an-invalidprogramexception-from-a-memory-dump-part-1-of-3--ikpmkjtdn","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Kevin Gosse (minidump.net)","item":"https://daily.dev/sources/minidump"},{"@type":"ListItem","position":3,"name":"Investigating an InvalidProgramException from a memory dump (part 1 of 3)"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/investigating-an-invalidprogramexception-from-a-memory-dump-part-1-of-3--ikpmkjtdn#faq","mainEntity":[{"@type":"Question","name":"How can I find an InvalidProgramException object in a .NET memory dump if it wasn't captured at the moment of the first-chance exception?","acceptedAnswer":{"@type":"Answer","text":"Use the dumpheap -stat -type InvalidProgramException command in dotnet-dump or WinDbg to locate surviving exception objects on the heap, since they remain there if no garbage collection occurred after the throw. Then use dumpheap -mt with the method table address to get object addresses, and printexception (pe) on each address to retrieve the stack trace. Developers tracking down memory-dump mysteries can follow deep debugging write-ups like this one on daily.dev."}},{"@type":"Question","name":"Why does rethrowing task.Exception.InnerExceptions[0] inside a ContinueWith callback hide the original stack trace?","acceptedAnswer":{"@type":"Answer","text":"Throwing an inner exception directly, instead of using ExceptionDispatchInfo to rethrow it, overwrites the exception's original callstack with the new throw location inside the ContinueWith lambda. This makes the reported stack trace point to the rethrow site rather than where the exception actually originated, making root-cause analysis far harder. Anyone debugging misleading .NET stack traces can find similar exception-handling pitfalls on daily.dev."}}]}
```

