As suggested most likely your code is calling a dll that is designed for the 4.8 runtime and will not work .net 6 as the runtimes are not compatible, thus the try/catch not working.
C# try/catch not work
I'm using WPF/C# .NET 6.0.9
I have a class class library DLL file that contain a method, I use the method with try/catch but it does not work, then application will crash and exit.
try
{
var result = PosAtmDevice.PosAtmPayment(Convert.ToDecimal(100000), posVendor, connectionType, selectedPos.IpAddress, selectedPos.PortNumber, selectedPos.PortName, int.Parse(selectedPos.PortBitrate), selectedPos.TimeOut, PosAtmDevice.RunTypes.Sync, selectedPos.PosId, selectedPos.TerminalId, selectedPos.AcceptorId, selectedPos.TextOnReceipt, deviceType);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Error is :
Symbol loading for optimized module System.IO.Ports.dll was skipped because Just My Code is enabled Disassembly 1ADB3EAF mov ecx,dword ptr [edx+4] System.NullReferenceException: 'Object reference not set to an instance of an object.'
After disable Enable Just my code and Show disassembly if source is not available in Option > Debugging , this error will happen
System.Io.Ports.pdb Not loaded System.IO.Ports.pdb contains the debug information required to find the source for the module System.IO.Ports.dll
Version : 7.00.22.51805 Location : D:\Proj c\StoreManager\StoreManager\bin\Debug\net6.0-windows\runtimes\win\lib\net6.0\System.IO.Ports.dll
but Catch does not work , and my app will crash.
Developer technologies | Windows Presentation Foundation
Developer technologies | .NET | Other
Developer technologies | C#
1 answer
Sort by: Most helpful
-
Bruce (SqlWork.com) 81,696 Reputation points Volunteer Moderator
2023-06-13T15:15:56.05+00:00