InvalidProgramException in D365 F&O

I run into two cases when F&O threw InvalidProgramException at runtime. This is the full message: System.InvalidProgramException: Common Language Runtime detected an invalid program. It happened because X++ compiler generated invalid IL that the JIT compiler wasn’t able to compile to native code. One scenario is assigning a struct to an interface-types variable. For example: …

Continue reading ‘InvalidProgramException in D365 F&O’ »

Process exceptions inside transactions

D365 F&O doesn’t allow you to catch (most) exceptions inside database transactions. But there is a way how you can work with exceptions there. For example, I have some logic using Message processor and I noticed that the processor ignores CLR (.NET) exceptions. It silently handles them and they appear neither in infolog nor any …

Continue reading ‘Process exceptions inside transactions’ »

Details of type initializer exception

My F&O development environment showed an error message when I tried to use Inventory > Transaction on a sales order line. This doesn’t say much about the actual cause. Attaching a debugger didn’t help – there was no unhandled exception and Info.add() wasn’t called either. I was still able to get more information; showing that …

Continue reading ‘Details of type initializer exception’ »

Exception handling in PU31

In 2018, I wrote the blog post Throwing managed exceptions from X++ in D365FO, where I pondered upon how throwing proper exceptions objects in X++ would be beneficial. This is still true. I also showed a proof of concept how it can be done despite the fact that X++ doesn’t directly support it. But this …

Continue reading ‘Exception handling in PU31’ »

Throwing managed exceptions from X++ in D365FO

Update! PU31 has added the ability to throw managed exceptions. Read more about it here. What I really miss in X++ is the ability to throw exception objects. If you throw an exception in X++, it’s just a number defining what kind of exception it is, which usually says just “Error” (Exception::Error). You also typically …

Continue reading ‘Throwing managed exceptions from X++ in D365FO’ »