Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Object is not set to an instance of an object in econnect

(0) ShareShare
ReportReport
Posted on by

Hi All,

Im getting this error (Object is not set to an instance of an object) at which i highlited in red line.while im getting the Item XMLs from GP by using Econnect.Please help me .

using (eConnectMethods eConnectMethod = new eConnectMethods())

{
eConnectOut myRequest = new eConnectOut();
myRequest.DOCTYPE = ecQuery.DocumentType;
myRequest.OUTPUTTYPE = 2;
myRequest.FORLIST = 1;
myRequest.WhereClause = ecQuery.WhereClause;
RQeConnectOutType[] eConnectOutType =
new RQeConnectOutType[1] { new RQeConnectOutType() };
eConnectOutType[0].eConnectOut = myRequest;
eConnectType eConnectDoc = new eConnectType();
eConnectDoc.RQeConnectOutType = eConnectOutType;
// Serialize the object to produce an XML document
MemoryStream memStream = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(typeof(eConnectType));
serializer.Serialize(memStream, eConnectDoc);
memStream.Position = 0;
XmlDocument myDoc = new XmlDocument();
myDoc.Load(memStream);
// Retrieve the specified customer document
result = eConnectMethod.GetEntity(sConnectionString, myDoc.OuterXml);
if (result == "<root></root>")
{
return "";
}
}

 

 

*This post is locked for comments

  • Tim Wappat Profile Picture
    5,703 on at
    RE: Object is not set to an instance of an object in econnect

    Sorry been on other things for a day, web API is the clue, I see you have seen this other thread that I think is relevant...

    community.dynamics.com/.../750245

  • Community Member Profile Picture
    on at
    RE: Object is not set to an instance of an object in econnect

    Hi Tim,

    Even though i'm getting the Same error.actually i'm using Message Queuing and WEB API .Is there any chance that error with Web Api or Message Queuing ?.

  • Tim Wappat Profile Picture
    5,703 on at
    RE: Object is not set to an instance of an object in econnect

    Using the listing that follows got the result as shown ran as a console app. It also returns an item XML if I change it to a valid item in my database. 

    I would start from here and work out what is different in your setup.

    2018_2D00_01_2D00_19_5F00_15_2D00_58_2D00_10.jpg

    Don't forget to wrap your memory stream in a using when you go to production though.

    Tim.

    using Microsoft.Dynamics.GP.eConnect;
    using Microsoft.Dynamics.GP.eConnect.Serialization;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Xml;
    using System.Xml.Serialization;
     
    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string connections = @"Data Source=LIVEGPHOST;Initial Catalog=AUDTS;Integrated Security=True";
     
                using (eConnectMethods eConnectMethod = new eConnectMethods())
                {
     
                    eConnectOut myRequest = new eConnectOut();
                    myRequest.DOCTYPE = "Item";
                    myRequest.OUTPUTTYPE = 2;
                    myRequest.FORLIST = 1;
                    myRequest.WhereClause = "ITEMNMBR in ('#783T','100/300W','LENOVOMOBILE')";
                    RQeConnectOutType[] eConnectOutType =
                    new RQeConnectOutType[1] { new RQeConnectOutType() };
                    eConnectOutType[0].eConnectOut = myRequest;
                    eConnectType eConnectDoc = new eConnectType();
                    eConnectDoc.RQeConnectOutType = eConnectOutType;
                    // Serialize the object to produce an XML document
                    MemoryStream memStream = new MemoryStream();
                    XmlSerializer serializer = new XmlSerializer(typeof(eConnectType));
                    serializer.Serialize(memStream, eConnectDoc);
                    memStream.Position = 0;
                    XmlDocument myDoc = new XmlDocument();
                    myDoc.Load(memStream);
                    // Retrieve the specified customer document
                    Console.WriteLine("=== Requester Doc:");
                    Console.WriteLine(myDoc.OuterXml);
                    Console.WriteLine("");
                    Console.WriteLine("");
                    Console.WriteLine("=== Result Doc:");
                    string result = eConnectMethod.GetEntity(connections, myDoc.OuterXml);
                    Console.WriteLine(result);
                }
            }
        }
    }
    



  • Community Member Profile Picture
    on at
    RE: Object is not set to an instance of an object in econnect

    I set the break point at Getentity.i got below xml please see the below for the same.

    <?xml version="1.0"?><eConnect xmlns:xsd="www.w3.org/.../XMLSchema&quot; xmlns:xsi="www.w3.org/.../XMLSchema-instance&quot;><RQeConnectOutType><eConnectProcessInfo xsi:nil="true" /><taRequesterTrxDisabler_Items xsi:nil="true" /><eConnectOut><DOCTYPE>Item</DOCTYPE><OUTPUTTYPE>2</OUTPUTTYPE><FORLIST>1</FORLIST><WhereClause>ITEMNMBR in ('#783T','100/300W','LENOVOMOBILE')</WhereClause></eConnectOut></RQeConnectOutType></eConnect>

  • Tim Wappat Profile Picture
    5,703 on at
    RE: Object is not set to an instance of an object in econnect

    I can't go much further, critical question to answer is the one about if the serializer has correctly generated your XML document before you submit it.

    So if you set a break point on the GetEntity line and inspect the myDoc object, does can you see the XML in the OuterXml property?

  • Community Member Profile Picture
    on at
    RE: Object is not set to an instance of an object in econnect

    Hi Tim,

    Thanks for responding,

    I am trying to get DOC type is 'Item' and whereClause is 'Item number'.Please tell me if you want any else.

  • Tim Wappat Profile Picture
    5,703 on at
    RE: Object is not set to an instance of an object in econnect

    So if you set a break point on the GetEntity line and inspect the myDoc object, does can you see the XML in the OuterXml property? 

    2018_2D00_01_2D00_19_5F00_12_2D00_00_2D00_32.jpg

    2018_2D00_01_2D00_19_5F00_12_2D00_00_2D00_32.jpg

    I can running a similar version of your code. It happily tried to contact the server. I've not got your server nor do i know what you are querying so I can't test much beyond that. 

    Only changes are I don't know what your doctype or whereclause strings look like. 

    Tim

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
Almas Mahfooz Profile Picture

Almas Mahfooz 3 User Group Leader

Featured topics

Product updates

Dynamics 365 release plans