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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / How to call C# class m...
Finance forum

How to call C# class method from X++ ?

(0) ShareShare
ReportReport
Posted on by 336

Hi guys, 

A quick technical question.

How can i call C# class from X++.

I have 1 solution : 2 projects, and i need to call my method on C# class.

Let me know if I need to add some references on D365 project to be able use the c# class on from my 1st project ,

or just call it directly.( not worked :p )

Thanks in advance :) 

I have the same question (0)
  • Suggested answer
    Pedro Tornich Profile Picture
    955 on at

    Hi Adax,

    You have to create a reference from the X++ project to the C# project, please check the following documentation for more information:

    docs.microsoft.com/.../write-business-logic

  • AdnDalhi Profile Picture
    336 on at

    Hi Pedro,

    Thank, already Added the reference of c# project, into AX project, but still.

    Is there any namespace i have to add more using Microsoft.Dynamics.AX.... ?

  • AdnDalhi Profile Picture
    336 on at

    I've Added the reference , but still not recongize my CSharp class on AX

    Any namespaces to add,

    using .. ?

  • Suggested answer
    Pedro Tornich Profile Picture
    955 on at

    Hi Adax,

    I'm sorry to hear that it didn't work.

    Another option you can try is to wrap your C# code into a DLL and add it as a reference.

    The following blog post gives a good example on how external DLLs can be added to D365:

    stoneridgesoftware.com/.../

  • Suggested answer
    Sukrut Parab Profile Picture
    71,741 Moderator on at

    Did you  add your dll in references node ? If not do that and then see if you can access  methods in your x++ code.

  • Martin Dráb Profile Picture
    239,992 Most Valuable Professional on at

    The namespace to refer to it's the namespace you've used in your C# project. We can't tell you what it is, because we've never seen your code. I suggest you use the fully-qualified name at first (e.g. MyNamespace.MyClass) and switch to the 'using' statement only when it works.

    Also, make sure that both the class and the method are public.

  • AdnDalhi Profile Picture
    336 on at

    Hi All ,  Yes 

    Both of them are public, Class and methods.

    I've Added the C# project reference to D365 project.

    + adding the (using [name of class]) namespace on D365Project

    it's worked the first time. and was able to execute the code correctly. just after the second execution

    i received the following error message, is that normal, aftre adding the reference.

    pastedimage1568638440573v1.png

    Thanks

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans