OnAfter table event subscriber patterns and antipatterns

  • Post comments:18 Comments
  • Reading time:9 mins read

The purpose of events is to simplify business logic customization while not impeding upgradeability and general extensibility. However, there is one particular class of events that may cause troubles: OnAfter* table events. There are four of them: OnAfterInsert, OnAfterModify, OnAfterDelete, and OnAfterRename.

If you need them, you must be careful.

(more…)

Continue ReadingOnAfter table event subscriber patterns and antipatterns

Dynamically loading assemblies at runtime

  • Post comments:7 Comments
  • Reading time:7 mins read

When you spend more time in C# than C/AL, and you still tell yourself and the world around you that you are developing for NAV, then this post is for you.

I already wrote a three-article series about “DLL hell” and how to resolve it, and in my last post in the series (https://vjeko.com/sorting-out-the-dll-hell-part-3-the-code) I delivered some code that help you take control of your .NET assemblies.

This time, I am delivering an updated solution, one that solves all the problems others, and myself, have encountered in the meantime.

So, fasten the seatbelt, and let’s embark on another .NET interoperability black belt ride.

(more…)

Continue ReadingDynamically loading assemblies at runtime

How To Update a Class Or Assembly Reference in C/AL And Retain Event Trigger Code

  • Post comments:4 Comments
  • Reading time:5 mins read

When you reference a .NET class that exposes events, and you switch on the WithEvents property, C/SIDE creates the event triggers for you. If you later want to update the reference to the .NET class, for whatever reason (like, there is a newer version of the assembly), updating the reference will actually delete the event triggers with all the code in them.

To be fair to this non-feature, at least it warns you politely:

image

This is not something you experience once in a geologic era. When you are developing your own assemblies, this will happen fairly often – as often as you add or remove events to/from your classes, and you want to reflect that in the Development Environment. Or as often as you increase the version of your assembly.

Unfortunately, there is no way in the Development Environment to update the reference while actually retaining the event triggers or code in them.

But still, there is a way, and a fairly easy way at that.

(more…)

Continue ReadingHow To Update a Class Or Assembly Reference in C/AL And Retain Event Trigger Code