In my last post I have introduced the GETLASTERROROBJECT function that returns you the instance of the System.Exception class, representing the actual exception that has happened.
To properly handle exceptions in an unambiguous way, you must use the exception type, not its name, so it is important to get the actual System.Type representing the exception type.
Sounds easy, but it’s not quite so.
Continue reading Getting the exception type from the GETLASTERROROBJECT
A friend asked my by e-mail today about a problem he encountered with DotNet interop: how to access a property of an object, if the property name matches a reserved word in NAV. A simplest example is from the Microsoft.Dynamics.Nav.SMTP.SmtpMessage class that comes bundled with NAV 2013.
Consider this piece of code:
Mail := Mail.SmtpMessage;
Mail.<span style="color: rgb(32, 96, 160);">To</span> := <span style="color: rgb(192, 48, 48);">'email@example.com'</span>;
If you try to compile this, it will fail. It’s simple: the To property name is invalid in the C/AL context, because it is a reserved word.
So, how do you fix it?
Continue reading DotNet Quick Tip: Accessing members with invalid names