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)

Executing Code from C# Class Library in X++ Job Appears to do nothing

(0) ShareShare
ReportReport
Posted on by 36

I have created a C# class library that uses document services for SalesSalesOrderService to create a sales order (just the header) and then a separate class method that updates a salesorder by adding a sales line to an existing sales order.  The class library is added to the AOT in AX, it deploys fine, the intellisense in AX works fine, etc.  I get no errors.  

The problem, however, is that nothing happens when I execute the code in my test job and the debugging doesn't make it to the infolog statement. I also tried debugging with VS by attaching to the AX process but it never goes into VS.  I am perplexed as this seems to be pretty simple.  If you need more information just let me know.  Thanks in advance for any help.

Below is the code from the class library and the job code that I am executing.  I am using .NET framework 4.5.1 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ALTAIFIntegration.DEVERP7SalesOrders;

namespace ALTAIFIntegration
{
    public class Deverp7SalesOrders
    {
        public string createSOHeader(string company, string custAccount, string invAccount, string delName, string poFormNum, 
                                          string city, string county, string state, string street, string zip, string countryRegionId)
        {
            var salesTableAddressRec = new AxdEntity_TableDlvAddr()
            {
                City = city,
                County = county,
                State = state,
                Street = street,
                ZipCode = zip,
                CountryRegionId = countryRegionId
            };

            var salesTable = new  AxdEntity_SalesTable()
            {
                CustAccount = custAccount,
                InvoiceAccount = invAccount,
                DeliveryName = delName,
                PurchOrderFormNum = poFormNum,
                ReceiptDateRequested = DateTime.Now.Date,
                SalesType = AxdEnum_SalesType.Sales,
                TableDlvAddr = new AxdEntity_TableDlvAddr[] { salesTableAddressRec }
            };

           AxdSalesOrder newSalesOrder = new AxdSalesOrder()
            {
                SalesTable = new AxdEntity_SalesTable[] { salesTable }
            };

            var callContext = new CallContext { Company = company };
            var client = new SalesOrderServiceClient();

            try
            {
                client.create(callContext, newSalesOrder);
                client.Close();
                return "Created";
            }
            catch
            {
                client.Abort();
                return "Failed";
                throw;
            }
        }

        private static EntityKey[] EntityKeyForSalesId(string salesId)
        {
            KeyField field = new KeyField()
            {
                Field = "SalesId",
                Value = salesId
            };

            EntityKey key = new EntityKey()
            {
                KeyData = new[] { field }
            };

            return new[] { key };
        }
 
        public string addSOLine(string soId, string soItemId, decimal qty, string invColorId)
        {
            using (SalesOrderServiceClient client = new SalesOrderServiceClient())
            {
                EntityKey[] entityKeyList = EntityKeyForSalesId(soId);

                // Retrieve the order to modify
                var order = client.read(new CallContext(), entityKeyList);

                var inventDim = new AxdEntity_InventDim()
                {
                    InventColorId = invColorId
                };

                var salesLineAddressRec = new AxdEntity_TableDlvAddr()
                {
                    City = order.SalesTable[0].TableDlvAddr[0].City,
                    County = order.SalesTable[0].TableDlvAddr[0].County,
                    State = order.SalesTable[0].TableDlvAddr[0].State,
                    Street = order.SalesTable[0].TableDlvAddr[0].Street,
                    ZipCode = order.SalesTable[0].TableDlvAddr[0].ZipCode,
                    CountryRegionId = order.SalesTable[0].TableDlvAddr[0].CountryRegionId
                };

                var salesLine = new AxdEntity_SalesLine()
                {
                    ItemId = soItemId,
                    QtyOrdered = qty,
                    action = AxdEnum_AxdEntityAction.create,
                    actionSpecified = true,
                    InventDim = new AxdEntity_InventDim[] { inventDim }
                };

                var salesTable = new AxdEntity_SalesTable()
                {
                    _DocumentHash = order.SalesTable[0]._DocumentHash,
                    PurchOrderFormNum = order.SalesTable[0].PurchOrderFormNum,
                    ReceiptDateRequested = order.SalesTable[0].ReceiptDateRequested,
                    action = AxdEnum_AxdEntityAction.update,
                    actionSpecified = true,
                    SalesLine = new[] { salesLine }
                };

                AxdSalesOrder newOrder = new AxdSalesOrder()
                {
                    SalesTable = new[] { salesTable }
                };

                try 
	            {	        
		            // Update the order
                    client.update(new CallContext(), entityKeyList, newOrder);
                    return "Updated";
	            }
	            catch (Exception)
	            {
                    return "Failed";
		            throw;
	            }
                

            }
        }
    }
}

pastedimage1568313907517v1.png

*This post is locked for comments

I have the same question (0)
  • RayBizee Profile Picture
    36 on at

    I should also mention that after about 10 minutes, the following pops up (like it's resuming the debugging).  Could this be a security issue?  The account associated with the endpoint is our service account used in AX but not sure if I have to explicitly supply the password for that.  I am a little ignorant on the security side of this whole process.

    pastedimage1568322460410v1.png

  • Suggested answer
    Khurshid Wali Profile Picture
    928 on at

    Hello Raybreakall,

    You did not mention where you put the dll file.

    I assume you have put that to the bin folder of the client and properly referenced that dll.

    Now for debugging did you attached ax32.exe or ax32Serv.exe process?

    it should be ax32Serv.exe.

    Do you agree with the above statements?

    Recently I have worked on a dll and I was able to use debugging on x++ code and dll code using VS.

    regards,

    Khurshid Wali

  • RayBizee Profile Picture
    36 on at

    Thanks for your reply Khurshid Wall.  

    At first, I just performed a build and then copied the dll to the client and server AX bin folders and added it to the GAC after giving it a "strong name" in Visual Studio.  I couldn't really get that to work after adding the reference in AX (even after several reboots of the server and client).  I then changed so the deploy to server and client was set to yes.

    pastedimage1568377955933v1.png

    I then removed the dll from the GAC because I read that it could prevent a successful debug process.  

    I am attaching to AX32Serv.exe and I get the warning that it could harm my computer.

    When I step into Line 7 below, it stops debugging in AX and Visual Studio does not pick it up at all.

    pastedimage1568378063245v2.png

    I was getting the message below at first because I had started with just the dll without deploying I suppose so I searched for all instances of the dll and replaced them with the latest one.

    pastedimage1568378136826v3.png

    Now that message doesn't appear but the result is the same.  The breakpoint doesn't get hit.  I should also mention that I am in X++ on a dev server and this dll is connecting to the inbound port on another dev server using the document process you see.  

    I see the C# project in the AOT under Visual Studio Projects

    pastedimage1568378387998v1.png

    If you need any other information just let me know.

    Thanks again!

    Ray

  • Suggested answer
    Khurshid Wali Profile Picture
    928 on at

    Dear Ray Breakall,

    The breakpoint did not hit because you are using old dll in the bin folder and debugging new code as clearly stated in below message.

    "A copy of Devrpsaleorder.cs was found in dll but the current source code is different from the version built into new dll".

    pastedimage1568378504066v1.png

    Please replace old dll with new dll and your breakpoint will start to get hit. This means your source code and dll should be in same state.

    regards,

    Khurshid Wali

  • RayBizee Profile Picture
    36 on at

    Thanks again for your reply Khurshid.  I mention in my post that I did replace all of the dlls on the server and I no longer get this message.

  • RayBizee Profile Picture
    36 on at

    I am currently performing a multi-threaded compile in AX to see if that clears anything up.

  • RayBizee Profile Picture
    36 on at

    I completed a full compile and full CIL without error and tried again and I get the same behavior.  Any ideas to try?  In the meantime I think I'm going to create a more simple one that just executes the code that has hard-coded values in the C# app, just to see if that works.  However if anyone offers something to try, I will try whatever you think is useful.

    Thanks again everyone, in advance.

  • Khurshid Wali Profile Picture
    928 on at

    Dear Ray breakall,

    Try to add VSS breakpoint to ax job and get inside the referenced method.

    In this way, you may get a clear view of code execution.

    regards,

    Khurshid Wali.

  • RayBizee Profile Picture
    36 on at

    By VSS breakpoint, do you mean the hard-coded "breakpoint;" in there?  If so I just tried that and the same thing happens.

    If that's not what you're talking about, please let me know how to do that.

  • RayBizee Profile Picture
    36 on at

    I created a new C# class library and even left the default names for class, etc and create a single public method that returns a string and deployed it, added to AOT and intellisense worked fine but nothing happens when I run it.  Same result so it's definitely not a problem with the dll files or the GAC or any of that.  

    To recap, I am on a dev server with AX 2012 R3 CU13, I've deployed my C# class library Visual Studio app and also manually added the dll file to the Client and Server bin directories, restarted the AOS and client several times and intellisense works great but the class doesn't execute the code.  The serviceReference1 points to another dev server's AIF inbound port.

    Again, how is security handled in this case?  I'll keep searching.  Examples out there are so basic it's hard to get a handle on how this works in a meaningful way (at least I can't find any examples or walkthroughs that actually do this).

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