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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Is it possible to call a visual studio class method with parameters from AX 2012

(0) ShareShare
ReportReport
Posted on by

Hi All,

I have developed a class library project in Visual studio 2013 and have added to the AOT. 

And also I have added the (classLibrary.dll) to the Reference node on ax AOT.

Now I am trying to run the app via a Job and I am getting an Error at an if condition as "Wrong Types of Comparision".

static void clrManagedCode(Args _args)
{
    axUsersRolesLibrary.Class1 objClass1;
    InteropPermission          interopObj;
    str                     userIdObj;
    ;

    try
    {
        interopObj = new InteropPermission(InteropKind::DllInterop);
        interopObj.assert();
        objClass1 = new axUsersRolesLibrary.Class1();
        userIdObj = 'ravi';

        if(objClass1.getYourRole(userIdObj)==true)
        {
            info("You are an AX admin!!!!");
        }
        else
        {
            info("You are not an AX admin!!!!");
        }

    }
    catch
    {
        error('CLR Exception caught !!!!');
    }

}

I have highlighted the code where I got error.

My question can't I pass parameters from AX ?

Because that's an Boolean method in AX and return true or false based certain condition.

In visual studio the project is running fine.

Please help me to rectify the issue ?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    You're asking about parameters, but the error is somewhere else. It says that you're trying to compare values of types that can't be compared.

    If it's coming from X++, it means that the return value of getYourRole() returns a wrong type. If it returns System.Boolean, assign it to a boolean variable (= X++ boolean, not the CLR one) and use this variable in the comparison.

    By the way, adding a reference after adding the project to AOT isn't needed.

  • Suggested answer
    Community Member Profile Picture
    on at

    axMani,

    As per your question "Is it possible to call a visual studio class method with parameters from AX 2012", yes it is very much possible and I am sure your method is being called here.

    And the error is very much self-explanatory. Just assign your called method value to system.boolean as Martin told you and you will be good to go.

    Regards

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans