Reply
Highlighted
Member
Posts: 1
Registered: ‎03-28-2011

NullReferenceException when using Transaction Details API via C#

Code to reproduce the exception (built against the latest version of the C# SDK):

 

var reportingGateway = new ReportingGateway("-- your api login id --", "-- your transaction key --", ServiceMode.Live);
var batches = reportingGateway.GetSettledBatchList();

I rebuilt the SDK from the provided source code, and figured out that the problem is in one two places. 

 

The first possible fix is In ReportingGateway::GetSettledBatchList:

 

        public List GetSettledBatchList(DateTime from, DateTime to) {
            var req = new getSettledBatchListRequest();
            req.firstSettlementDate = from;
            req.lastSettlementDate = to;
            req.includeStatistics = true;
            var response = (getSettledBatchListResponse)_gateway.Send(req);

            return Batch.NewFromResponse(response);
        }

This method is missing assignments to the *Specified properties that exist on getSettledBatchRequest (see http://msdn.microsoft.com/en-us/library/bb402199.aspx). Modifying this method to set each of the *Specified properties to true fixes the issue.

 

The other possible fix is to remove the *Specified properties from getSettledBatchRequest. The code for that class is currently: 

    /// 
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd", IsNullable = false)]
    public partial class getSettledBatchListRequest : ANetApiRequest {

        private bool includeStatisticsField;

        private bool includeStatisticsFieldSpecified;

        private System.DateTime firstSettlementDateField;

        private bool firstSettlementDateFieldSpecified;

        private System.DateTime lastSettlementDateField;

        private bool lastSettlementDateFieldSpecified;

        /// 
        public bool includeStatistics {
            get {
                return this.includeStatisticsField;
            }
            set {
                this.includeStatisticsField = value;
            }
        }

        /// 
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool includeStatisticsSpecified {
            get {
                return this.includeStatisticsFieldSpecified;
            }
            set {
                this.includeStatisticsFieldSpecified = value;
            }
        }

        /// 
        public System.DateTime firstSettlementDate {
            get {
                return this.firstSettlementDateField;
            }
            set {
                this.firstSettlementDateField = value;
            }
        }

        /// 
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool firstSettlementDateSpecified {
            get {
                return this.firstSettlementDateFieldSpecified;
            }
            set {
                this.firstSettlementDateFieldSpecified = value;
            }
        }

        /// 
        public System.DateTime lastSettlementDate {
            get {
                return this.lastSettlementDateField;
            }
            set {
                this.lastSettlementDateField = value;
            }
        }

        /// 
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool lastSettlementDateSpecified {
            get {
                return this.lastSettlementDateFieldSpecified;
            }
            set {
                this.lastSettlementDateFieldSpecified = value;
            }
        }
    }

 

Changing it to the following (just removing those *Specified properties) fixes the issue and the SDK works as expected:

 

    /// 
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "AnetApi/xml/v1/schema/AnetApiSchema.xsd", IsNullable = false)]
    public partial class getSettledBatchListRequest : ANetApiRequest {

        private bool includeStatisticsField;

        private bool includeStatisticsFieldSpecified;

        private System.DateTime firstSettlementDateField;

        private bool firstSettlementDateFieldSpecified;

        private System.DateTime lastSettlementDateField;

        private bool lastSettlementDateFieldSpecified;

        /// 
        public bool includeStatistics {
            get {
                return this.includeStatisticsField;
            }
            set {
                this.includeStatisticsField = value;
            }
        }

		/// 
        public System.DateTime firstSettlementDate {
            get {
                return this.firstSettlementDateField;
            }
            set {
                this.firstSettlementDateField = value;
            }
        }

        /// 
        public System.DateTime lastSettlementDate {
            get {
                return this.lastSettlementDateField;
            }
            set {
                this.lastSettlementDateField = value;
            }
        }
    }

I am currenlty using a modified version of the SDK in which I removed the *Specified properties from the getSettledBatchListRequest class. However this is not ideal; I would prefer to be using the SDK as provided by Authorize.Net without any modifications.

Highlighted
All Star
Posts: 1,072
Registered: ‎08-17-2009

Re: NullReferenceException when using Transaction Details API via C#

Hey there,

 

We need a little more information to try and figure out what's going on. For instance, what exactly are you trying to do, where is the error happening, and what's the stack trace?

 

Thanks,

 

Michelle

Developer Community Manager

Highlighted
Member
Posts: 8
Registered: ‎06-22-2011

Re: NullReferenceException when using Transaction Details API via C#

I am see this same problem - I am getting a null reference error everytime I call GetTransactionList.

 

Here's the trace:

 

System.NullReferenceException: Object reference not set to an instance of an object.
   at AuthorizeNet.Batch.NewFromResponse(getSettledBatchListResponse batches)
   at AuthorizeNet.ReportingGateway.GetSettledBatchList(DateTime from, DateTime to, Boolean includeStats)
   at AuthorizeNet.ReportingGateway.GetTransactionList(DateTime from, DateTime to)

 

My system is not in test mode and the transaction detail API is on.  There is only one transaction, unseltted. 

 

This is kind of a shower stopper.

 

Highlighted
Member
Posts: 8
Registered: ‎06-22-2011

Re: NullReferenceException when using Transaction Details API via C#

Ok I see it looks like there's a new SDK to fix this.  NM