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)

AIF - Return System.Data.DataTable throws Input String was not in a correct format

(0) ShareShare
ReportReport
Posted on by 2,894

Hi, I'm trying to consume a service operation from AX in a console C# application, that returns a DataTable, but I keep getting:

Input String was not in a correct format

In the console application.

This is the method in AX:

[SysEntryPointAttribute(true)]
public System.Data.DataTable sendSalesOrderInfo()
{
	SalesTable salesTable = SalesTable::find("001");
	System.String salesId, accountNum, salesName;
	System.Data.DataTable dt = new System.Data.DataTable();
	System.Data.DataColumnCollection columns = dt.get_Columns();
	System.Data.DataRowCollection rows = dt.get_Rows();
	System.Data.DataColumn salesIdColumn, custAccountColumn, salesNameColumn;
	System.Data.DataRow dataRow; 
	
	salesIdColumn = new System.Data.DataColumn("SalesId", System.Type::GetType("System.String"));
	custAccountColumn = new System.Data.DataColumn("CustAccount", System.Type::GetType("System.String"));
	salesNameColumn = new System.Data.DataColumn("SalesName", System.Type::GetType("System.String"));
	
	columns.Add(salesIdColumn);
	columns.Add(custAccountColumn);
	columns.Add(salesNameColumn);
	
	dataRow = dt.NewRow();
	
	salesId = System.Convert::ToString(salesTable.SalesId);
	accountNum = System.Convert::ToString(salesTable.CustAccount);
	salesName = System.Convert::ToString(salesTable.SalesName);
	
	dataRow.set_Item("SalesId", salesId);
	dataRow.set_Item("CustAccount", accountNum);
	dataRow.set_Item("SalesName", salesName); 
	
	rows.Add(dataRow);
	
	return dt;
}

I would appreciate your help, thanks!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    keoma Profile Picture
    32,729 on at

    when using System.Convert::ToString, you should first check, if the given value - e.g. salesTable.SalesId - is not null.

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

    What's the point of converting a string to a string again?

    If your goal it to convert X++ string to System.String, a mere assignment will do the trick. Please read more about marshaling in documentation.

  • saman0suke Profile Picture
    2,894 on at

    It was just trying to resolve the error by doing a conversion from "x++ string" to a "System.String", but the result is the same. The value is found, I ran the same code in a job, and it worked correctly. Any idea? thanks!

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

    Of course the result is the same. The conversion does nothing, you don't even get rid of marshaling, because you still calling a method expecting System.String, therefore the interop layer must marshal your X++ string to the CLR type.

    Have you generated CIL? Have you debugged the code? Also, please give us all details from the exception.

  • saman0suke Profile Picture
    2,894 on at

    The first problem is that the person in charge did not install the tool that allows you to see the AOT methods from Visual Studio so I can't put a breakpoint from there to debug the code being called from the C# app. The other issue is that I cannot run Visual Studio as Admin so I don't see the AXServ32.exe to attach it for debugging.

    Error details:

    System.ServiceModel.FaultException was unhandled
      HResult=-2146233087
      Message=Input string was not in a correct format.
      Source=mscorlib
      StackTrace:
        Server stack trace: 
           at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
           at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
           at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
           at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
        Exception rethrown at [0]: 
           at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
           at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
           at InterOpWSConsumption.hsInterOpIntegration.hsInteropIntegration.sendSalesOrderInfo(hsInteropIntegrationSendSalesOrderInfoRequest request)
           at InterOpWSConsumption.hsInterOpIntegration.hsInteropIntegrationClient.hsInterOpWSConsumption.InterOpIntegration.InteropIntegration.sendSalesOrderInfo(InteropIntegrationSendSalesOrderInfoRequest request) in c:\Users\user\Documents\Visual Studio 2013\Projects\InterOpWSConsumption\InterOpWSConsumption\Service References\hsInterOpIntegration\Reference.cs:line 651
           at InterOpWSConsumption.hsInterOpIntegration.hsInteropIntegrationClient.sendSalesOrderInfo(CallContext CallContext) in c:\Users\user\Documents\Visual Studio 2013\Projects\InterOpWSConsumption\InterOpWSConsumption\Service References\InterOpIntegration\Reference.cs:line 657
           at InterOpWSConsumption.Program.Main(String[] args) in c:\Users\user\Documents\Visual Studio 2013\Projects\InterOpWSConsumption\InterOpWSConsumption\Program.cs:line 16
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: 
    


    Code in C# app:

    using InterOpWSConsumption.InterOpIntegration;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace hsInterOpWSConsumption
    {
    	class Program
    	{
    		static void Main(string[] args)
    		{ 
    			CallContext context = new CallContext();
    			InterOpIntegration.InteropIntegrationClient client = new InterOpIntegration.InteropIntegrationClient();
    			System.Data.DataTable dt = client.sendSalesOrderInfo(context);
    			Console.ReadKey();
    		}
    	}
    }
    

    Thanks for the help.

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

    If you don't have a proper development environment, trying to develop/debug something surely will be unnecessarily difficult...

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans