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)

unable to Marshal .Net to X++

(0) ShareShare
ReportReport
Posted on by 1,370

Hi,

I have created a class library for USPS integration, which works good and performs its task accordingly.

Then I have added the reference to this dll into AX client and writes a job which sets and gets the value from that library. The issue is while I am getting values from .net library the returned values are of type System.String, I get these values in variables of type System.String and tried to marshal them into X++ string type. But it shows error during marshalling. Though this is very basic code,the part which is causing trouble is in bold and at the end of the code.

 

static void AddressVerification(Args _args)

{
CodeAccessPermission permission;

//USPS.USPS_AV AV;
AddressVerificationClassLibrary.USPS_AddressVerification AV;

LogisticsAddressStreet AX_Street;
LogisticsAddressCity AX_City;
LogisticsAddressCountyId AX_County;
LogisticsAddressStateId AX_State;
LogisticsAddressCountryRegionId AX_Country;
LogisticsAddressZipCodeId AX_Zip;

System.String USPS_Address1;
System.String USPS_Address2;
System.String USPS_City;
System.String USPS_State;
System.String USPS_Zip5;
System.String USPS_Zip4;

str strUSPS_Address1;
str strUSPS_Address2;
str strUSPS_City;
str strUSPS_State;
str strUSPS_Zip5;
str strUSPS_Zip4;

boolean result = false;

permission = new InteropPermission(InteropKind::CLRInterop);

permission.assert();

AV = new AddressVerificationClassLibrary.USPS_AddressVerification();

AX_Street = "6406 Ivy Lane"
AX_City = "Greenbelt";
AX_County = "";
AX_State = "MD";
AX_Country = "";
AX_Zip = "";

AV.set_AXStreet(AX_Street);
AV.set_AXCity(AX_City);
AV.set_AXCounty(AX_County);
AV.set_AXState(AX_State);
AV.set_AXCountry(AX_Country);
AV.set_AXZip(AX_Zip);

AV.validate();

//result = AV.get_Result();

USPS_Address1 = AV.get_USPSAddress1();
USPS_Address2 = AV.get_USPSAddress2();
USPS_City = AV.get_USPSCity();
USPS_State = AV.get_USPSState();
USPS_Zip5 = AV.get_USPSZip5();
USPS_Zip4 = AV.get_USPSZip4();

strUSPS_Address1 = USPS_Address1.ToString();
strUSPS_Address2 = USPS_Address2.ToString();
strUSPS_City = USPS_City.ToString();
strUSPS_State = USPS_State.ToString();
strUSPS_Zip5 = USPS_Zip5.ToString();
strUSPS_Zip4 = USPS_Zip4.ToString();


}

}

Rishi

*This post is locked for comments

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

    You said you got an error during marshaling, but you forgot to tell us what error.

    In general, an assignment from System.String to str should work and I don't see anything obviously wrong in your code, so I have to wait for more information from you. BTW code like strUSPS_Address1 = USPS_Address1 should suffice; calling ToString() on System.String returns the same System.String, so it's not very useful.

  • Rishi1403 Profile Picture
    1,370 on at

    Hello Martin,

    Thanks for the guidance and sorry for incomplete information.

    The system enters debugger on the same (first) line

    strUSPS_Address1 = USPS_Address1.ToString();

    and says,

    "Error executing code, object not initialized"

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

    It doesn't sound like anything about marshaling. It seems that the value of USPS_Address1 is null and you can't call methods on null references. Please check the value to be sure.

  • Rishi1403 Profile Picture
    1,370 on at

    First of all, many thanks for the help sir. You just saved my day.

    And yes, the USPS_Address1 was null, and that was the loop hole. :)

    Regards,

    Rishi Kumar

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