Options

the .net interop type cannot be used in code for the classic

iperutilityiperutility Member Posts: 18
edited 2014-12-09 in NAV Three Tier
Hello,

I had made a DLL in C#, easy, and put them under "C:\Program Files (x86)\Microsoft Dynamics NAV\60\Service\Add-ins".

The problem is :

1) I had declared a global variable DotNet of my DLL
2) I had Implemented the global variable
3) I had compiled my codeunit without error

but when I ran my codeunit, those got me this error : the .net interop type cannot be used in code for the classic.

C/AL code in form

sgatePXY := sgatePXY.SGATEProxy;

this is my DLL

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Xml;

namespace ClassLibrarySGATE
{
public class SGATEProxy
{
public X509Certificate certified;
public SgateWebService ProxySgate;

protected string Pass;
protected string User;
public tipoRispostaPresaInCaricoLotto result;
public tipoRichiestaPresaInCaricoLotto request;
public string requestXML;
public XmlDataDocument XDom;
public XmlNodeList xNodeList;
protected string idUltimoLottoRicevutoCorrettamente;
protected string NumeroMessaggi;


public SGATEProxy()
{
}

public bool CallSgateServer(string pathCertificati, string url, string username, string password)
{
ProxySgate = new SgateWebService();
XDom = new XmlDataDocument();
// Invio i certificati tramite il collegamento proxy web senza doverli registrare sul pc o server
ProxySgate.ClientCertificates.Add(X509Certificate.CreateFromCertFile(pathCertificati + "SGATE.cer"));
ProxySgate.ClientCertificates.Add(X509Certificate.CreateFromCertFile(pathCertificati + "GeoTrustPCA.cer"));
ProxySgate.ClientCertificates.Add(X509Certificate.CreateFromCertFile(pathCertificati + "GeoTrustEV.cer"));
ProxySgate.ClientCertificates.Add(new X509Certificate(pathCertificati + username, password));
ProxySgate.Timeout = 360 * 1000;
return false;
}

public tipoRispostaPresaInCaricoLotto InvokePresaInCaricoLotto(tipoRichiestaPresaInCaricoLotto request, int tentativo)
{
result = null;
try
{
result = ProxySgate.PresaInCaricoLotto(request);
}
catch
{
if (tentativo < 5)
result = InvokePresaInCaricoLotto(request, tentativo + 1);
}
return result;
}

public string EsitoRichiestaLotto(tipoRichiestaPresaInCaricoLotto rispostaLotto)
{
if (string.IsNullOrEmpty(result.lottoMessaggi.idLotto))
return result.lottoMessaggi.idLotto;
else
return "KO";
}

public tipoRichiestaPresaInCaricoLotto GeneraRequestRichiestaLotto(string requestXML)
{

// Reding the request in XML format
XDom.Load(requestXML);

XmlNode xNodeMittente = XDom.SelectSingleNode("/Mittente");
foreach (XmlNode xNode in xNodeMittente)
{
User = xNode["login"].InnerText;
Pass = xNode["Password"].InnerText;
}
XmlNode xNodeRichiestaPresaInCaricoLotto = XDom.SelectSingleNode("/richiestaPresaInCaricoLotto");
foreach (XmlNode xNode in xNodeMittente)
{
idUltimoLottoRicevutoCorrettamente = xNode["idUltimoLottoRicevutoCorrettamente"].InnerText;
NumeroMessaggi = xNode["numeroMessaggi"].InnerText;
}

request = new tipoRichiestaPresaInCaricoLotto();
request.idUltimoLottoRicevutoCorrettamente = idUltimoLottoRicevutoCorrettamente;
request.mittente = new tipoMittente() { login = User, password = Pass };
request.numeroMessaggi = Convert.ToInt32(NumeroMessaggi);

return request;
}


}
}

Comments

  • Options
    lvanvugtlvanvugt Member Posts: 774
    but when I ran my codeunit, those got me this error : the .net interop type cannot be used in code for the classic.
    So I guess you are running the code by means of a classic client ...
    Indeed you can develop the code (it will compile), but the classic runtime cannot execute it. It can only be executed in the 3-tier setup, so using a RTC (and service tier).
    If the code is both to run on classic and RTC you have to check whether it's running on either of them using the ISSERVICETIER function to determine that .Net Interop code will be executed only when ISSERVICETIER = TRUE.
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
Sign In or Register to comment.