RTC - Automation with own developped DLL

veerleverbrveerleverbr Member Posts: 7
edited 2011-04-01 in NAV Three Tier
I had a problem with a custom created COM dll in the NAV 2009 R2 RTC:

I made my own COM visible dll in .NET to use in NAV by means of automation.
In the Classic Client, everything worked fine. When running the same code in RTC I got the error:
"The server ... is either unavailable or your connection has been lost. Do you want to attempt to reconnect?"
The event log contained the error message:
"Must specify binding flags describing the invoke operation required"

The dll was installed on the client and the service tier. The automation objects where set to be created on the clients. I changed this so that they be created on the service (which is better whatsoever because then all the clients don't need to have the dll installed). The RTC error message stayed the same. The event view error message changed to AmbiguousMatchException.

Then it occurred to me that the method being called on the automation variable was an overloaded method. In other words, there were two methods with the same name (but different parameters) in the dll class. Apperently the Classic client has no problems with that, but the RTC obviously doesn't know which of the two methods to take hence causing an AmbiguousMatchException. So I adjusted the dll removing the second method with the same name and that solved the problem.

It took quite some time to figure all this out, so I thought I'd share this :) .

Comments

  • jlandeenjlandeen Member Posts: 524
    One really good feature of NAV 2009 R2 is that you can now call managed assemblies (i.e. .NET classes) directly from NAV. So going forward you can skip creating COM controls/classes.

    This only works if you are using the RTC or Web Service Tier and it is not supported in the classic client.

    See: http://msdn.microsoft.com/en-us/library/gg502499.aspx
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • IsakssonMiIsakssonMi Member Posts: 77
    "Then it occurred to me that the method being called on the automation variable was an overloaded method."

    Are you sure? COM doesn't support overloading. When overloading it creates new methods with an end-prefix if I remember correctly (like method_2).
  • IsakssonMiIsakssonMi Member Posts: 77
    A feature, that you maybe meant, but could be interesting for others is the attribute: DefaultParameterValueAttribute.

    An example:
    void SetBackColor(int red, int green, int blue, [DefaultParameterValueAttribute(-1)]int alpha);

    This gives the optional argument, they must be placed after normal arguments.

    (RTC doesn't support this, so all existing arguments must be used.)
  • veerleverbrveerleverbr Member Posts: 7
    IsakssonMi wrote:
    "Then it occurred to me that the method being called on the automation variable was an overloaded method."

    Are you sure? COM doesn't support overloading. When overloading it creates new methods with an end-prefix if I remember correctly (like method_2).

    Yes it does create the extra methods with the suffixes like you say.
    But they only work in the classic client, not in RTC.
    It compiles correctly, but when running the code in RTC (first method or second method) I get the same error.

    When you look at the stack trace in the event viewer, it is clear that generated .NET code of the RTC calles the methods in the dll by reflexion and based only on the method name, it doesn't know which of the two methods to take, so an error is thrown.

    After removing the overloaded method, everything worked fine.
Sign In or Register to comment.