Options

.NET-Event "AssemblyResolve" only fires in Dynamics NAV on client side, not server side?

FS_9FS_9 Member Posts: 1
So, the setup in this issue is maybe a bit complicated. I will explain it with editted names and try to keep it simple:

I have a .NET-Assembly "Processor.dll" with a single class "Processor" that I want to make use of inside a CodeUnit in Dynamics NAV 2017.

"Processor" requires another dll "Logger", which is held inside a file "container.libz" created with - as the name suggests - LibZ.

Inside a method of "Processor" I resolve the container and load the "Logger"-Assembly. A simple Version of the Code would look like this:

In NAV CodeUnit (given that "P" is the Processor variable and "T" a text variable):
P := P.Processor;
T := P.DoStuff;
MESSAGE(T);
In the Processor class:
public Processor()
{
    Initialize(); 
    //this among other things causes LibzResolver to be initialized
}

public string DoStuff()
{
    LibzResolver.RegisterFileContainer("container.libz");
    Assembly dll = AppDomain.CurrentDomain.Load("Logger");

    //more code using the dll
    return someText;
}
The assembly is found as LibzResolver makes the container's contents known to the domain by subscribing to the AssemblyResolve Event.

So problem here is the following: This code in fact works fine in test Applications and when running the NAV CodeUnit on the client (Setting RunOnClient = Yes for "P")

When I try to run this code on server side though (Setting RunOnClient = No for "P"), the AssemblyResolve Event is not fired. As a result the dll is not found the code stops with a FileLoadException.

I checked various articles about AssemblyResolve and .NET-Assemblies in NAV, but I did not find anything that applied to my case or could be applied at all.

Does anybody have an idea what may cause this behaviour?

Answers

  • Options
    zaidtariqzaidtariq Member Posts: 52
    Hi FS_9,
    If you make the property of your .Net type variable to true it will never run on the server side. To run the dll on the server side place you dll and all required resources(dlls) in the Add-ins folder of the server. The path could be like C:\Program Files\Microsoft Dynamics NAV\90\Service\Add-ins

    Best Regards:
    Zaid Tariq
    Dynamics NAV/365 BC Developer at Dynamics 360

    please like / agree / verify my answer, if was helpful.
Sign In or Register to comment.