Register dll!!!!

HanenHanen Member Posts: 281
Hello,

I have a dll written in c# (consuming a wcf service), I have registered the dll using regasm and then gacutil but when I've declared my variable type of automation but I can't found the dll registred :cry: is there a way to refresh the assembly or did I miss something????

Heeeeeeeelp!!!!!
Regards

Hanen TALBI

Comments

  • AdrianAkersAdrianAkers Member Posts: 137
    You need to build your .dll assembly in .NET but have it registered for COM Interop. Have you done this? You also need to define interfaces to your class methods in C# to see the methods properly. Have you done this?
  • HanenHanen Member Posts: 281
    Yes I've did all this steps :cry:
    Regards

    Hanen TALBI
  • AdrianAkersAdrianAkers Member Posts: 137
    Are you sure?

    Please see the example below of some old VB code that works using COM Interop. I think you may not have defined everything properly in your assembly...
    Imports System.Security.Cryptography
    Imports System.IO
    Imports System.Text
    Imports System.Text.Encoding
    Imports System.Runtime.CompilerServices
    Imports System.Runtime.InteropServices
    
    'GUID hard coded to prevent changing on recompile 
    <GuidAttribute("9a1ebc2c-f02f-463b-876d-b25431f0696b")> _
    'InterfaceType is Dual
    <InterfaceType(ComInterfaceType.InterfaceIsDual)> _
    'Public Interface created with signatures matching methods in class and properties… 
    Public Interface ICrypto
        'Methods 
        Function EncryptString(ByVal Content As String) As Boolean
        Function DecryptString() As Boolean
        Function EncryptFile(ByVal Filename As String, ByVal Target As String) As Boolean
        Function DecryptFile(ByVal Filename As String, ByVal Target As String) As Boolean
        Function GenerateHash(ByVal Content As String) As Boolean
        Function StandardBankGenerateHash(ByVal Content As String, ByVal fileName As String) As Boolean
        Function SetEncryptionAlgorithm(ByVal value As Integer) As Boolean
        Function GetEncryptionAlgorithm() As Integer
        Function SetEncoding(ByVal value As Integer) As Boolean
        Function GetEncoding() As Integer
        Sub Clear()
        'Properties
        Property Key() As String
        Property Content() As String
        ReadOnly Property CryptoException() As CryptographicException
    
    End Interface
    
    'Class defined as ComVisible and GUID static
    <ComVisible(True)> _
    <GuidAttribute("46155048-ff63-4e63-bc1e-f2e32b66e907")> _
    <ProgId("Crypto")> _
    <ClassInterface(ClassInterfaceType.None)> _
    'Public Interface is Implemented
    Public Class Crypto : Implements ICrypto
    'Have not expanded the region of Class Variables below…
    + Class Variables Regions
    
    #Region "Public Functions"
    Public Property Key() As String Implements ICrypto.Key
            Get
                Return _key
            End Get
            Set(ByVal value As String)
                _key = value
            End Set
    End Property
    Public Property Content() As String Implements ICrypto.Content
            Get
                Return _content
            End Get
            Set(ByVal Value As String)
                _content = Value
            End Set
    End Property
    Public ReadOnly Property CryptoException() As CryptographicException        Implements ICrypto.CryptoException
            Get
                Return _exception
            End Get
    End Property
    Public Function SetEncryptionAlgorithm(ByVal value As Integer) As Boolean Implements ICrypto.SetEncryptionAlgorithm
            _algorithm = value
            Return True
    End Function
    
    Public Function GetEncryptionAlgorithm() As Integer Implements ICrypto.GetEncryptionAlgorithm
            Return _algorithm
    End Function
    Public Function SetEncoding(ByVal value As Integer) As Boolean Implements ICrypto.SetEncoding
            _encodingType = value
            Return True
    End Function
    
    Public Function GetEncoding() As Integer Implements ICrypto.GetEncoding
            Return _encodingType
    End Function
    
    
    Public Function EncryptString(ByVal Content As String) As Boolean Implements ICrypto.EncryptString
            Dim cipherBytes() As Byte
    
            Try
                cipherBytes = _Encrypt(Content)
            Catch ex As CryptographicException
                _exception = New CryptographicException(ex.Message, ex.InnerException)
                Return False
            End Try
    
            If _encodingType = EncodingType.Hex Then
                _content = BytesToHex(cipherBytes)
            Else
                _content = System.Convert.ToBase64String(cipherBytes)
            End If
    
            Return True
    End Function
    
  • AdrianAkersAdrianAkers Member Posts: 137
    Also what is your regasm syntax? Also not sure you need to bother with gacutil...
  • AdrianAkersAdrianAkers Member Posts: 137
    Your syntax should be something like...

    regasm myNewInterface.dll /tlb:myNewInterace.tlb /codebase

    Clearly you would need to have navigated first to the file path where your .dll is otherwise you'll get errors.

    Then you should see everything in NAV!
    \:D/
  • AdrianAkersAdrianAkers Member Posts: 137
    Oh and to unregister the above then simply;

    regasm myNewInterface.dll /tlb:myNewInterface.tlb /u
  • HanenHanen Member Posts: 281
    My dll is written in c#

    Here is My syntaxe used:

    Regasm /tlb: AutInvoice.tlb AutInvoice.dll
    Gacutil /i AutInvoice.dll

    I've tried also this:

    Regasm AutInvoice.dll /tlb: AutInvoice.tlb /codebase
    Gacutil /i AutInvoice.dll

    and the result is : Assembly added to the cash successfully (for both ways) but I can't see it from Navision :cry::cry::cry:


    Regards

    Hanen TALBI
  • AdrianAkersAdrianAkers Member Posts: 137
    Have you checked this property in your interface declaration... I have seen this requires setting before... -

    InterfaceType(ComInterfaceType.InterfaceIsDual)

    Go through the code example I gave you above...
  • HanenHanen Member Posts: 281
    Here is the code:
    [ComVisible(true)]
        [Guid("0E3DBBD5-B0B8-43b2-8C53-78AABA6EA69F")]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    
        public interface IFactureCRM
        {
            //********************************* Traitement des Tarifs ****************************************
    
            bool GetConnection(string URL, string Login, string MP, string Domain);
    
            bool CreationFacture(string CompteF, string NumFre, string MontantFre);
        
    
            
    
        }//fin interface ITarifCRM
    
        [ComVisible(true)]
        [ComDefaultInterface(typeof(IFactureCRM))]
        [ClassInterface(ClassInterfaceType.None)]
        public class FactureCRM : IFactureCRM
        {
            //********************************* Traitement des Produits ****************************************
    
            public string AdressUrl = null;
            public string Password = null;
            public string DomainWCF = null;
            public string UserName = null;
    
            public bool GetConnection(string URL, string Login, string MP, string Domain)
            {//Préparer les params de connexion
                AdressUrl =  URL;
                UserName =   Login;
                Password =   MP;
                DomainWCF =  Domain;
    
                return true;
            }//Fin GetConnexion
            //Modifier le code afin de passer l URL, password, username et Domain en paramètre
            public bool CreationFacture(string CompteF, string NumFre, string MontantFre)
            {
                EndpointAddress ead = new EndpointAddress(AdressUrl);
                NetTcpBinding tcpbd = new NetTcpBinding();
    
                ChannelFactory<ControlFacture.ServiceFacture.IServiceFacturation> proxy = new      ChannelFactory<IServiceFacturation>(tcpbd, ead);
                proxy.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                proxy.Credentials.Windows.ClientCredential.Domain = DomainWCF;//"MACHINE-TEST";
                proxy.Credentials.Windows.ClientCredential.UserName = UserName;//"administrateur";
                proxy.Credentials.Windows.ClientCredential.Password = Password;//"M%test6";
    
                IServiceFacturation chanel = proxy.CreateChannel();
    
                decimal Montant;
    
                Montant = Convert.ToDecimal(MontantFre);
           
                Facture F = new Facture();
    
                F.CompteFacturation = CompteF;
                F.NumFacture = NumFre;
                F.MontantFacture = (double)Montant;
    
                FacturationResponseInfo respInfo;
                respInfo = chanel.CreationFacture(Origine.Billing, F);
    
                if (respInfo.Code == 0)
                    return true;
                else
                    return false;
            }//fin CreationFacture
    
    Regards

    Hanen TALBI
  • AdrianAkersAdrianAkers Member Posts: 137
    On your Project->Properties in Visual Studio have you ticked "Register for COM Interop"

    Also I am not sure about the;
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    
  • krikikriki Member, Moderator Posts: 9,110
    [Topic moved from 'NAV Tips & Tricks' forum to 'NAV/Navision Classic Client' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.