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)
Answered

Calling visual studio c# classes in x++

(0) ShareShare
ReportReport
Posted on by

I have a visual studio project (which is already added in the AOT) which I need to access from X++. For example to run a method from the vs project when a button is clicked.

It is very simple using proxy classes to use AX classes and tables from visual studio, but I do not know how to do this the other way round.

Thanks

*This post is locked for comments

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

    It's even easier - you can call them directly; no proxy classes are needed. Just be aware of that X++ requires fully-qualified names, doesn't have properties (therefore you have to call underlying methods such as set_Name() for Name property), doesn't support generics and a few other things.

    You'll find more details in .NET Interop from X++.

  • Community Member Profile Picture
    on at

    Thanks a lot! did not realise it was that easy

  • Community Member Profile Picture
    on at

    Regarding the same scope as explained above, I was now able to call the methods I needed in the visual studio project from x++ code.

    I am now having trouble running the code from x++. The program works fine when running in visual studio, however when I call the program from AX some CLR exceptions are thrown.

    Firslty - "System.InvalidOperationException: Could not find default endpoint element that references contract 'XXX' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."

    I was also having an exception thrown regarding AX Logon. From visual studio, I logon using session.Logon(null, null, null, null) by using the ManagedInterop. Any issues how these can be solved?

    Thanks again

  • Martin Dráb Profile Picture
    237,924 Most Valuable Professional on at

    Please tell us what you're trying to achieve.

    The first error is about missing WCF configuration and I'll likely have a solution for you when you tell me what you're doing.

    The other is about connection back to AX and I have no idea why you're doing that. You already are inside an AX session.

  • Community Member Profile Picture
    on at

    Ok, so basically, I have a visual studio project which connects to a web service, gets some data from ax, and saves a pdf file that is returned from the web service. Now, I am trying to run this method (inside visual studio) when a button is clicked inside ax. I added the project to the AOT and called the methods I need inside the clicked method of the button.

    I hope this makes it clearer :)

    Thanks

  • Verified answer
    Martin Dráb Profile Picture
    237,924 Most Valuable Professional on at

    Regarding WCF: you would get exactly the same error if you did the same steps in any other .NET application. What you would normally have to do is adding the WCF client config to app.config - it would work with AX as well, nevertheless it offers an easier and more manageable approach. You can create the service client with AifUtil::createServiceClient(), which will apply the config file from your library:

    System.Type clienType = CLRInterop::getType('Your.Client.Type');
    Your.Client.Type client = AifUtil::createServiceClient(type);

    If may not be directly applicable to your solution, depending on what you do there. In that case, either refactor your implementation to make it possible or use the same solutions you would use in any other .NET application.

    Regarding the attempt to create new AX session, the best approach will be to get rid of it.

  • Community Member Profile Picture
    on at

    I was able to solve the AX session issue. I am still having a problem however with the WCF error. I have searched a lot, and your solution should work. However, it isn't. I also tried to see if manually inserting the <system.servicemodel> in  the ax32.exe.config would work, and it did. But that is definately not feasible. For some reason, the client config file is not being loaded. Any other ideas on what might be the cause of this?

    thanks again!

  • Martin Dráb Profile Picture
    237,924 Most Valuable Professional on at

    I see you modified the client config file. Can you please verify that your configuration file gets successfully deployed to the client computer? Add a breakpoint to AifUtil::createServiceClient(), check the value of configFilePath and then verify that the file exists and contains the right configuration.

    Also consider if you really want run it on client. (Typically such things are kept on server, but it depends.)

  • Community Member Profile Picture
    on at

    during debugging, I noticed that all elements give an error: Symbol " " was not found. Could this be a cause?

  • Martin Dráb Profile Picture
    237,924 Most Valuable Professional on at

    Can you please give us more information? What you're debugging, where you see the error, if it happens everywhere/everytime or in which cases, and so on.

    You probably should create a new thread for it.

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