Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Unable to create an object of a custom class from C/AL code

(0) ShareShare
ReportReport
Posted on by 80

Hi,

I am new to Microsoft Navision and currently using Navision 2013 R2 demonstration copy. I was trying to create a POC for calling a ".Net framework Types from C/AL code". Firstly I have written a sample class with some basic properties and methods which doesnt do much but simply return some data. Below is my class defination

using System;

namespace TestDotNet

{

   public class TestInstanceObjects

   {

       public int ID;

       private string name;

       public string Name

       {

           get { return name; }

           set { name = value; }

       }

       public TestInstanceObjects(string paramname)

       {

           name = paramname;

       }

       public string Getname()

       {

           return name;

       }

       public static string GetTime()

       {

           return DateTime.Now.ToString();

       }

       public TestInstanceObjects()

       {

       }

   }

}

After this I have copied the dll to path "C:\Program Files (x86)\Microsoft Dynamics NAV\71\RoleTailored Client\Add-ins" and then proceeded to create a new page which define an object of type TestinstanceObjects and then in my InIt() event i am trying to create the object for the class by calling the constructor function using below code

obj := obj.TestInstanceObjects('Test Name');

But it always gives me an error "Cannot create an instance of the following .Net framework object: assembly TestDotNet version 1.0.0.0, culture:neutral,public key toke: null type: TestDotNet.TestInstanceObject"

In the same page I have tried creating an object from XMLDocument class defined by the framework from GAC as shown in the MSDN sample and it perfectly worked but when i try the same for my custom class it doesn't works.

I have tried creating strong name key for the dll, adding the dll into GAC, calling the code in OnRun function of a CodeUnit and then running it from a page, removing all code from the class except the default constructor to see if i am doing anything wrong in defining my class but nothing worked.

Can anyone help me in guiding me in the right direction to find what i am missing over here.

Thanks for the help

*This post is locked for comments

  • RE: Unable to create an object of a custom class from C/AL code

    I think is a limit of the version that you are using NAV 2013, it should work only using NAV 2013 R2

    "Add-ins that are developed with Microsoft Dynamics NAV 2013 are still supported and displayed on a Microsoft Dynamics NAV Windows client only. Using that framework you can continue to write add-ins for the Microsoft Dynamics NAV Windows client. Using the new framework in Microsoft Dynamics NAV 2013 R2, you can write add-ins that can be run from any client."

    source: msdn.microsoft.com/.../dn182553(v=nav.71).aspx

  • knaraharis Profile Picture
    knaraharis 80 on at
    RE: Unable to create an object of a custom class from C/AL code

    No the .net code in dll is getting updated and working fine.. But the problem i am facing is... The script written in the manifest file(XMl file which we write and import in the control addins page to make it work for both windows and web clients) is not getting updated.

  • RE: Unable to create an object of a custom class from C/AL code

    If you use the same name after installed in the GAC using

    gacutil /i YOURDLLNAME.dll

    to update it you whould UNINSTALL it using

    gacutil /u YOURDLLNAME

    then reinstall it, to be sure that you updated it, assign a different version number in Visual Studio so that in NAV you can see the version that you are using.

  • knaraharis Profile Picture
    knaraharis 80 on at
    RE: Unable to create an object of a custom class from C/AL code

    Hi, THanks for the reply... Actually i was missing copying the dll into the service addin folder due to which i was facing the issue... Now it is working...

    Also I am now struck with a different issue... I was trying to build a control addin in Nav 2013 which would need to work in both and window and web client. I was able to  make it work but i wanted some changes in the script defined in the manifest file... So when i tried updating the newly changed manifest file... It do not seem to overwrite the old scripts...

    Can you please let me know how do i need to update the changes in the manifest file...

  • RE: Unable to create an object of a custom class from C/AL code

    Hi KNARAHARIS,

     you should sign your dll and install it in the GAC using an elevated command prompt (run it as Administrator) and use the following command:

    gacutil /i YOURDLLNAME.dll

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,387 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans