web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Problem with custom dll in a NAV 2009 R2 Web Service

(0) ShareShare
ReportReport
Posted on by

Hello fellow NAV community,

Since I am new to this community I would like to introduce myself before i ask my first question to you:

My name is Martin and I started NAV development a year ago in germany. Since then i have been active learning C/AL and administration of NAV 2009 Classic Client as well as RTC.

Ever since i found many support articles that suited for solving my occuring problems, but now i got a problem which seems easy, but apparently isn't that easy for me. I hope you can help me

The Setup is as following: We access a Codeunit via Navision Web Service. This Web Service is configured on a VM only designed for the Web service. This Win Server 2008 VM Has no classic client installed, just an RTC Client with configured Web service. The RTC Service is disabled whereas the web service is started.

In the Codeunit we try to instantiate a custom .NET assembly which is not registered in the GAC, so we put it in the services Add-Ins folder.

When we access the Web service via http and try to intantiate the dll the following error occurs:

This message is for C/AL programmers: Unable to create an instance of .Net object: assembly [...]

The thing is: I triple checked the version, the name and the public key token of the dll and even checked the RunOnClient property (which is set to No) but it wont work. The user executing the service is local administrator on the VM.

What kind of error sources exist? Did i miss something in the configuration of the VM?

Hopefully you can help me. Thank you all in advance for suggestions and i am looking forward to your answers.

Best regards,

Martin 

*This post is locked for comments

I have the same question (0)
  • jcastro Profile Picture
    2,245 on at
    RE: Problem with custom dll in a NAV 2009 R2 Web Service

    Hello Martin,

    First of all I'd like to give you a warm welcome to the beautiful dynamics community :-) I hope you stay around. 

    Regarding what you're describing: have you tried running that same codeunit from an actual client with UI (classic and RTC)? What's the result in those cases?

  • Community Member Profile Picture
    on at
    RE: Problem with custom dll in a NAV 2009 R2 Web Service

    Hello José,

    Thank you for your welcome wishes and for the answer. :)

    When I run the codeunit via the classic client a different error appears: the .net interop type cannot be used in code for the classic cside runtime

    Reading this error still leaves me confused since it seems to work for other web services we are using.

    I would like to mention (since i forgot to write it in my first post) that the application is not intended to be used as RTC. Therefore we disabled the service for the RTC on the VM.

  • Suggested answer
    jcastro Profile Picture
    2,245 on at
    RE: Problem with custom dll in a NAV 2009 R2 Web Service

    If it is at all possible I would advise you to try to make it run in an RTC client, even if it requires you to temporarily activate the RTC services. The last error you got is quite clear: those kinds of add-ins can't be run from the classic environment. So you must do it on RTC.

    By the way, did you register the add-in in the add-in table too?

    msdn.microsoft.com/.../dd983818.aspx

  • Community Member Profile Picture
    on at
    RE: Problem with custom dll in a NAV 2009 R2 Web Service

    I made a test page where i initiate the dll via the RTC using the codeunit. No errors occured, so it is instantiated without problems.

    However i need to run it as classic version. Is there any possibility to set a property or something like that to tell the service that he has to execute it this way?

    Maybe i can try to describe our architecture causing this problem to you:

    We have different NAV 2009 applications which need to exchange data with each other. Our approach to this was a table where we transform the data as a BLOB-like data provided with information whereto it should go. This transformation is done by the dll we cant initiate. A third DB polls the web service for new data and if there is new data he gets the destination and transfers it to the other web service where it is processed in a timely interval.

    I am sorry if there are problems caused by the translation but hopefully i could clear up my problem somehow.

  • Suggested answer
    jcastro Profile Picture
    2,245 on at
    RE: Problem with custom dll in a NAV 2009 R2 Web Service

    Have you registered the add-in in the add-in table in NAV? (https://msdn.microsoft.com/en-us/library/dd983818.aspx)

    Also, what kind of variable have you declared to use with this customized DLL? Is it a DotNet variable? Automation? OCX?

    If all your DLL does is transform the blob-like data into something that can be more easily transmitted through webservice, you might want to consider doing this without using the customized DLL. I don't know if this will apply to you but I posted a while ago about how to transform to BLOB after having received text (base64) via webservice some information. In your case instead of receiving you are sending info and instead of turning it into BLOB you have to turn it from BLOB into something else. If that's the case you might want to check out the following link: http://code4nav.com/2014/07/31/how-to-store-an-image-blob-received-via-web-service

  • Mahesh U Profile Picture
    433 on at
    RE: Problem with custom dll in a NAV 2009 R2 Web Service

    Hi Martin,

    can you please put runonclient property to "true" for your Dotnet variables and run again.

    Thanks,

    Mahesh U

  • Community Member Profile Picture
    on at
    RE: Problem with custom dll in a NAV 2009 R2 Web Service

    Yes, the add-in is registered in the system table. With the same public key token as stated in the error message in my initial post. (sorry, i forgot to mention it in my previous reply)

    The variable in the code unit is a DotNet type which is local in every trigger of the CU and is therefore instantiated seperately for each trigger.

    Thank you for the recommendation of your blog post! :) We will check if we could improve our procedure with this, yet of course we still search a solution to this problem.

  • jcastro Profile Picture
    2,245 on at
    RE: Problem with custom dll in a NAV 2009 R2 Web Service

    In order to try this I just created a codeunit and created a function inside that used a dotnet variable. I published the codeunit as a webservice and called it from outside NAV. It worked fine. My settings were "standard" (run on client = no, SuppressDispose = no).

    Would it be possible for you to show us part of the code that is contained in that webservice and failing in order to try to help you more efficiently?

  • Community Member Profile Picture
    on at
    RE: Problem with custom dll in a NAV 2009 R2 Web Service
    This is the function which is called to get the data of the source.

    Params:
    GlobalEntryNo Code 50
    SourceApplNo Integer
    VAR Data BigText
    Local variables:
    ConnectorEntry2 Record of the table where the data is located
    InStr InStream
    Utils DotNet //<<< Failing DLL

    CLEAR(Data); IF ConnectorEntry2.GET(GlobalEntryNo,SourceApplNo) THEN BEGIN ConnectorEntry2.CALCFIELDS(Data); IF ConnectorEntry2.Data.HASVALUE THEN BEGIN Utils := Utils.NAVUtils(); //<<<<<<< Instantiate DLL ConnectorEntry2.Data.CREATEINSTREAM(InStr); Data.ADDTEXT(Utils.encodeBase64FromStream(InStr)); END; END;

    I would like to add a big "Thank you!" for taking the time to have a look on my problem and showing many different approaches for a possible solution. :) 

  • Community Member Profile Picture
    on at
    RE: Problem with custom dll in a NAV 2009 R2 Web Service

    [quote user="José Castro"]

    Have you registered the add-in in the add-in table in NAV? (https://msdn.microsoft.com/en-us/library/dd983818.aspx)

    Also, what kind of variable have you declared to use with this customized DLL? Is it a DotNet variable? Automation? OCX?

    If all your DLL does is transform the blob-like data into something that can be more easily transmitted through webservice, you might want to consider doing this without using the customized DLL. I don't know if this will apply to you but I posted a while ago about how to transform to BLOB after having received text (base64) via webservice some information. In your case instead of receiving you are sending info and instead of turning it into BLOB you have to turn it from BLOB into something else. If that's the case you might want to check out the following link: http://code4nav.com/2014/07/31/how-to-store-an-image-blob-received-via-web-service

    [/quote]

    Hello José,

    I tried to reconstruct our codeunit to using mscorelib like in your blog post. Therefore our custom dll is not needed now, but i get another kind of error now: 

    Metadata for object of type CodeUnit with id 51850 is in a failed state.  This is caused by a previous exception: 
    
    Compilation of assembly '[...] (error message is cut down due to length)


    Googling it suggested a full recompile of all objects, but after this the error still occurs.

    Could it be that an installed .NET Framework v4.5.2 is causing this problem?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Alexander Ermakov Profile Picture

Alexander Ermakov 2

#2
SC666 Profile Picture

SC666 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans