Automation to DotNet how to port?

LboettcherLboettcher Member Posts: 6
edited 2014-03-20 in NAV Three Tier
Hello,

I started 7 days ago to port my DLL ,to comunicate to a external webservice, to NAV 2013.

With the NAV objects I had no problems, except that in 2009, my C# dll with automation was involved but in NAV 2013 server it does not work anymore.
CREATE(Automation,TRUE,FALSE)

This dont works anymore in NAV 2013.
Alright, so I run the automation on the client side.
Problem is now, it loads with File.open (test.xml) an XML to a stream, but since the automation on the client side he can not be passed to the Three Tier Server.

The solution: DotNet
DotNet can be running on the server, but now I need to customize my dll in C#
but i get this error:
Microsoft Dynamics NAV
---------------------------

This message is for C / AL programmers:. A NET variable has not been instantiated. Attempting 'asp.Test.RequestFileNameAddon' in 'codeunit test management interface' call: requestHitList
---------------------------
OK
---------------------------

my interface is a dll that contains 1 main class, 20 subclasses (with 20-40 methods) and 20 interface of the subclasses
with the the automation, i was able to use the DLL esayli with the 20 interfaces to access each of them. The main class includes methods that are used by all classes.

How can i create an interface for integration into NAV DotNet? What should I do with it in C# to instantiated it?

I hope you understand what my problem is. and my pretty bad english.

Leo

Comments

  • SogSog Member Posts: 1,023
    Call the constructor first in NAV.
    It's similar to the create(automation) function, however, you have to call it yourself
    So you don't have to change your C# dll, it is .net from the beginnning, the automation exposure is the backwards compatiblity.

    I just had the delight of having a similar task, where the dll would be both automation and .net (to support classic and rtc).
    With registration of regasm (for automation) and gacutil (for .net)

    so this should do it:
    yourdotnetvariableInNAV.yourclassconsturctor(any parameters)
    
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • LboettcherLboettcher Member Posts: 6
    I try it but i still get this message:
    Type: Microsoft.Dynamics.Nav.Types.Exceptions.NavNCLDotNetCreateException
    SuppressMessage: False
    FatalityScope: Call
    Message: Diese Meldung richtet sich an C/AL-Programmierer: Es konnte keine Instanz des folgenden .NET Framework-Objekts erstellt werden: Assembly: aCrefoInterfaceTypeLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fa49e2c43590ba97, Typ: anaptis.aCrefoInterface_OnlineSearch.
    StackTrace:
         bei Microsoft.Dynamics.Nav.Types.NavAutomationHelper.GetTypeFromAssembly(String assemblyFullName, String typeName)
         bei Microsoft.Dynamics.Nav.Types.NavAutomationHelper.CreateDotNetObject(String assemblyFullName, String typeName, Object[] arguments)
         bei Microsoft.Dynamics.Nav.Runtime.NavDotNet.CreateDotNet(Object[] arguments)
    Source: Microsoft.Dynamics.Nav.Types
    HResult: -2146233088
    ----------------------------------
    Type: System.IO.FileNotFoundException
    Message: Die Datei oder Assembly "aCrefoInterfaceTypeLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fa49e2c43590ba97" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
    FileName: aCrefoInterfaceTypeLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fa49e2c43590ba97
    FusionLog:
      WRN: Protokollierung der Assemblybindung ist AUS.
      Sie können die Protokollierung der Assemblybindungsfehler aktivieren, indem Sie den Registrierungswert [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) auf 1 festlegen.
      Hinweis: Die Protokollierung der Assemblybindungsfehler führt zu einer gewissen Leistungseinbuße.
      Sie können dieses Feature deaktivieren, indem Sie den Registrierungswert [HKLM\Software\Microsoft\Fusion!EnableLog] entfernen.
      
    StackTrace:
         bei System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
         bei System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
         bei System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
         bei System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
         bei System.Reflection.Assembly.Load(String assemblyString)
         bei Microsoft.Dynamics.Nav.Types.NavAutomationHelper.GetTypeFromAssembly(String assemblyFullName, String typeName)
    Source: mscorlib
    HResult: -2147024894
    

    i dont know what should missing? i have the dll in the gobla assambly cache.

    the code of the dll:
    using System;
    namespace hallowelt
    {
        public class hallowelt
        {
            private String answer = "";
            public String Answer
            {
                get { return answer; }
                set { answer = value; }
            }
        }
    }
    

    it is first to test it, but it still dont work maybe i have to do anything in the code what i am missing.
  • mdPartnerNLmdPartnerNL Member Posts: 802
    Sog wrote:
    Call the constructor first in NAV.
    It's similar to the create(automation) function, however, you have to call it yourself
    So you don't have to change your C# dll, it is .net from the beginnning, the automation exposure is the backwards compatiblity.

    I just had the delight of having a similar task, where the dll would be both automation and .net (to support classic and rtc).
    With registration of regasm (for automation) and gacutil (for .net)

    So you just extended the com? and that's all. Do you have a small example I can compile and try out?
  • nhsejthnhsejth Member, Microsoft Employee Posts: 34
    The error you see in the exception is due to a missing dependency to your assembly. It can be hard to find, but try one of the free .Net decompilers that can show you the full dependency list (an example is http://www.telerik.com/products/decompiler.aspx). If the problem continues, it's recommend to enable fusion logging on the machine to get extended log information that can be used to nail the problem.

    For more information about how you can use the interoperability feature, you can take a look at http://msdn.microsoft.com/en-us/library/gg502499.aspx or some of the related blogs on Mibuso.

    Notice that the constructor call is somewhat different from the CREATE call on the legacy automation type. The constructor must be used in an assignment like this:

    myVar := myVar.MyType();

    assuming that the variable myVar is defined as an instance of the MyType .Net type.

    If you ignore the assignment you will create an instance of your type, but if will not be assigned to the variable and the application code will fail. You don't have to call the constructor if you use a static class or if you only want to access static members in a class.

    Hint: Development and debug of .Net componets should be done an a sandboxed server that you can start and stop as needed. As soon as you have loaded one version of your assembly you cannot replace it before the server has been restarted as the OS will lock the file while it's loaded. It can be easier to manage if you don't gac you r assembly but instead distribute it to the Add-ins folder for the development environment (C/Side), the client (if client side interoperability is needed) and the server.
    _________________
    Niels-Henrik Sejthen
    Senior Software Developer
    Microsoft Dynamics NAV

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • SogSog Member Posts: 1,023
    Hello Lboettcher,

    If we don's see the NAV code, we can't help you.
    Your .net class is simple enough, so it must be on how you call this dll.

    Mberger, here is a small example
        [ComVisible(true), Guid("A beautiful GUID")]    (a beautiful GUID is just a GUID instead of that string)
        [ClassInterface(ClassInterfaceType.AutoDual)]  //I didn't really found out if early or late binding worked, so I just sticked with this
        [ProgId("Mycompany.Users.Management")]
        public class Hashing
        {
            public Hashing()
            {          
            }
            [DispId(1)]
            public String EncryptCredentials(String userName, String Password)
            {
                if (Password != null)
                {
                    userName = userName.ToUpper();//username case insensitive
                    return (Encrypt(String.Concat(Password, Salt, userName))); 
                }
                else
                    return ("");
            }
            [DispId(2)]
            public String Encrypt(String source)
            {
               lets face it, I'm not showing this
            }
    

    I check with ISSERVICETIER if I have to create the automation or the dotnet variable both referencing to the same dll.
    And thank you for your insights nhsejth
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • pandrei91pandrei91 Member Posts: 1
    Hi there,
    Would you be kind and post the full code ?
    I am struggling with the report "Export Instrastat to XML", the problem is the fact that automation is no longer used/supported in NAV2013 R2, so somehow I have to fix the report to compile and run again.

    Any specific suggestions please?

    Thank you in advance.
Sign In or Register to comment.