Calling a .NET dll from NAV 2009R2

dnadna Member Posts: 6
edited 2012-07-05 in NAV Three Tier
Hi,

http://msdn.microsoft.com/en-us/library/gg502473.aspx but I can't figure out what's the problem.

I have registered my dll into the GAC and created a variable in NAV as mentioned in the link above.
Name: test, DataType:DotNet, Subtype: MyDll, version ..........

My dll contains a single class with a static method which his called like that :
test.StaticMethod();

Then when opening the page containing this modification boum :
This message is for C/AL programmers: Unable to create an instance of .NET object: assembly MyDll ....

I have no idea why NAV try to create an instance, it should not. If I uninstall the dll from the GAC the same message appears. I tried to put the dll in the Add-ins folder but still the same result.
Any help will be appreciated :)

Comments

  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    As far as I understand the usage of .NET in NAV you need an instance of any Object that you want to use. That means you have to either call the constructor of that Object or use the result of another method that gives you an instance of that Object.

    In your linked example the .NET variable named 'xml' is instanced by constructor:
    xml := xml.XmlDocument();
    
    The .NET variable named 'items' is "instanced" by result value:
    items := xml.SelectNodes('/rss/channel/item');
    
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • dnadna Member Posts: 6
    Hi einsTeIn.NET and thanks for your answer.
    In your linked example the .NET variable named 'xml' is instanced by constructor:
    Code: Select all
    xml := xml.XmlDocument();

    The .NET variable named 'items' is "instanced" by result value:
    Code: Select all
    items := xml.SelectNodes('/rss/channel/item');
    You are right. However as mentioned above, I'm using a static method. -> No need to instantiate an object.

    I finally succeed to load my dll. I have no clue why. I have clean my system and put the dll in the Add-ins folder of NAV. Hocus Pocus !

    Thanks for the help anyway.
  • SogSog Member Posts: 1,023
    there still is a need to instanciate the object. .NET is OO. Even static objects are instanciated, but only once.

    And any addin .dll is required to be in the addin folder before NAV can instanciate it.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • dnadna Member Posts: 6
    there still is a need to instanciate the object. .NET is OO. Even static objects are instanciated, but only once.
    ... Don't tell me to do the CLR job :)
    And any addin .dll is required to be in the addin folder before NAV can instanciate it.
    from MS:
    If the assembly that you want to reference is a custom assembly and not installed in the global assembly cache, then copy the assembly to the Add-ins folder of the Microsoft Dynamics NAV installation folder.
    So installing it in the GAC is enough right?
  • kinekine Member Posts: 12,562
    And are you using client side dotnet or server side? If serverside, is the assembly in GAC on server?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • chris-petcheychris-petchey Member Posts: 1
    This message is for C/AL programmers: Unable to create an instance of .NET object: assembly MyDll ....

    Having installed my dll in the server's GAC, I kept getting this message also.
    It went away when I restarted the navision service on the server
Sign In or Register to comment.