Options

Problem regarding Automation Server (NAV 5 and 2009)

LogikUserLogikUser Member Posts: 8
Hi there,

We've written a .NET DLL which provides Events and Functions for Navision.

The problem that we have is after registering the .NET DLL with regasm and loading it into Navision,
we can't create the object.

In Navision 5 the error msg is (translated by me):
"A type conversion couldnt be done, because on of the sides has an invalid type.
Automation := Integer"

In Navision 2009 the error msg is the following:
"This message is for C/AL programmers:
Could not create an instance of the OLE control or Automation server identify by GUID={9E18ABD1-02A4-4C9D-8F00-A51EA55F601B} 1.0:{38345F3F-ADDE-4089-B868-551EA7937528}:'Wrapper for CatWeazel'.CatWeazelNet.
Check that the OLE control or Automation server is correctly installed and registered."

The Automation server is a C/A Globals variable with filled subtypes. The events are shown also in the Sources (of the C/A CodeUnit).
My question is, what has to be done, that the .DLL works. Snippets of source-code follow:

ASSEMBLYINFO.CS
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("9E18ABD1-02A4-4c9d-8F00-A51EA55F601B")]

Class1.cs - Yeah I know that filename sucks...
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace CatWeazelLIBNet
{

    [GuidAttribute("C0BEE88F-01EC-4755-8B0A-A20E0563428A")] 
    public interface ICatWeazel
    {
        [DispIdAttribute(1)] 
        void Aboutbox();
        [DispIdAttribute(2)] 
        ....
    }

    [Guid("FD01AC61-673B-400a-BF2B-DF9E6EDCE421")]
    [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
    public interface ICatWeazelEvents
    {
        [DispIdAttribute(20)]
        void iDBOperation(int Operation, int DBType, string TableName, string FieldList, string WhereStr, ref int Status);
        .....
     }
     [GuidAttribute("38345F3F-ADDE-4089-B868-551EA7937528")]
    [ClassInterface(ClassInterfaceType.None)]
    [ComSourceInterfaces(typeof(ICatWeazelEvents))] 

    public class CatWeazelNET : ICatWeazel
    {
       ....
        public iDBOperationEvent iDBOperation;
        public iDBRequestValueEvent iDBRequestValue;
        public iGetErrorTextEvent iGetErrorText;
        public UserEventEvent UserEvent;

    }
    [ComVisible(false)]
    public delegate void iDBOperationEvent(int Operation, int DBType, string TableName, string FieldList, string WhereStr, ref int Status);
    public delegate void iDBRequestValueEvent(int Operation, string Value, ref int Status);
    public delegate void iGetErrorTextEvent(int Func, ref string ErrText);
    public delegate void UserEventEvent(string Name, string Par1, string Par2, string Par3);
}



Thanks a lot in advance.

Comments

  • kinekine Member Posts: 12,562
    And could you post the C/AL code where the error is? Because it seems that there is mistake in the C/AL code, not in the automation...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • LogikUserLogikUser Member Posts: 8
    The C/AL Code is:
    Create(Logik);
    

    The Variable Logik is defined as automation server (global).
  • kinekine Member Posts: 12,562
    Check that there is no local variable with name Logik or field with name "Logik" on the Rec...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • LogikUserLogikUser Member Posts: 8
    Done, and there isn't any...
  • kinekine Member Posts: 12,562
    It is compile time error or runtime error?
    Is the error in this Create line or on some other line?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • LogikUserLogikUser Member Posts: 8
    As I can see,

    in Nav 5 the error occurs when I save the CodeUnit (and compile).
    In Nav 2009 the error occurs, as soon as I want to run the CodeUnit.
    No matter If the Create("Logik"); Line exists or not.
  • kinekine Member Posts: 12,562
    Then post all lines of the C/AL code which are using the variable...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • LogikUserLogikUser Member Posts: 8
    I put a screenshot, to show it to you...
    dynanaverror.jpg
  • kinekine Member Posts: 12,562
    May be you have not correct constructor in your class (without parameters)?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • jlandeenjlandeen Member Posts: 524
    How did you register the dll with Regasm?

    Have you signed the control and used the /codebase /tlb switches?
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • LogikUserLogikUser Member Posts: 8
    The constructur of the class has no parameters.
    regasm <DLL> /tlb
    The control is signed and codebase says its only working for exes.
  • jlandeenjlandeen Member Posts: 524
    Here's some code that I've used in the past to make these COM controls work within NAV. Note that the names have been changed to protect the innocent. Also an important note is that I used a different GUID for the interface and the instance of the wrapper class that Implments the interface.
    namespace JeffsCoolCOM
    {
        [ComVisible(true)]
        [Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"), InterfaceType(ComInterfaceType.InterfaceIsDual)]
        public interface IJeffsWrapper
        {
            void DoSomething()
        }
    
        [ComVisible(true)]
        [Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"), ClassInterface(ClassInterfaceType.None)]
        public class JeffWrapper : IJeffsWrapper
        {
            public void DoSomething()
            {
                //More code goes here
            }
        }
    }
    

    Here's a few other links that I used when making my wrapper class that helped me:
    https://blogs.msdn.com/freddyk/archive/2008/11/09/edit-in-excel-part-4-out-of-4.aspx
    http://www.codeguru.com/csharp/csharp/cs_misc/com/article.php/c9065/
    http://msdn.microsoft.com/en-us/library/57kx88c8(VS.71).aspx
    http://msdn.microsoft.com/en-us/library/2044hysa(VS.71).aspx
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • LogikUserLogikUser Member Posts: 8
    I've looked at the links you posted,

    and the only difference I see is:

    InterfaceType(ComInterfaceType.InterfaceIsDual)] <- this lines.
    For what are they?
    What do they do?
    As you can see I use different GUids for the interface and the class itself, I read somewhere on the internet that I shouldn't use InterfaceIsDual, but what it is, no one can tell.

    Something which maybe interesting.
    If I re-register (deregister, and register new) the part of the messagebox in Nav 09 beginning with 1.0 changes.
    It seems that somehow another GUid is registered.
    What I don't understand, in the registry the first Guid (which I have given in source) exists, the other one, doesn't.
  • jlandeenjlandeen Member Posts: 524
    That particular attribute refers to the type of binding that the interface will support - if it's dual it supports both early and late binding (you may want to brush up on your COM programming terminology).

    You may want to check out this link to see if it can describe a few of the things going on: http://www.simple-talk.com/dotnet/visual-studio/build-and-deploy-a-.net-com-assembly/
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
Sign In or Register to comment.