I’m trying to run this project DbMon.NET – A simple .NET OutputDebugString capturer in .NET Core (.NET 5.0).
It runs fine in .Net Framework 4.7.2, but when I switch to .NET 5, I keep getting the exception System.OverflowException: Arithmetic operation resulted in an overflow.
thrown by System.IntPtr.ToInt32()
.
Here is the details:
Step 1: Download DbMon.NET source code.
Step 2: Add the file DebugMonitor.cs
to my .NET 5.0 console project.
Step 3: I execute DebugMonitor in the file Program.cs
like this:
static void Main(string[] args)
{
DebugMonitor.OnOutputDebugString += new OnOutputDebugStringHandler(PrintDebugString);
DebugMonitor.Start();
Console.Read();
DebugMonitor.Stop();
}
private static void PrintDebugString(int id, string szMsg)
=> Console.WriteLine("{0} - {1}", id, szMsg);
Step 4: Run the project. The code always throw exception at m_SharedMem.ToInt32()
in the file DebugMonitor.cs
. the value of m_SharedMem
is m_SharedMem = MapViewOfFile(m_SharedFile, SECTION_MAP_READ, 0, 0, 512);
.
The exception is: System.OverflowException: Arithmetic operation resulted in an overflow.
.
In step 2, if I use .NET Framework 4.7.2 instead of .NET 5.0, I won’t get the exception. So I guess .NET 5.0 might require to setup some security rule or something, I have this this question (MemoryMappedFile low-integrity .Net 5) but haven’t figured out how to fix this DbMon.Net in .Net Core 5.0.