Get Instrument Type from existing liens via api

Discussions related to custom development with Select.
Post Reply
sweinstock
Posts: 18
Joined: Thu Jun 16, 2016 2:45 pm

Get Instrument Type from existing liens via api

Post by sweinstock »

Hi,

I'm trying to get all existing liens from the softpro file to display on my web page.

I'm accessing via api the mortagee, mortgagor, originalprincipalamount, etc. all return fine. When I try to access the insrumenttype I get the following error
Object reference not set to an instance of an object.

When debugging it also gives the following error:
- InstrumentType '(existingLiensSelect.FirstOrDefault()).InstrumentType' threw an exception of type 'System.NullReferenceException' SoftPro.Select.Client.Enumerations.IInstrumentType {System.NullReferenceException}

How can I access it?

Thanks
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Get Instrument Type from existing liens via api

Post by BobRichards »

Are you sure you have the list? The exception generated (NullReferenceException) means that the "existingLiensSelect" collection was null valued.
Bob Richards, Senior Software Developer, SoftPro
sweinstock
Posts: 18
Joined: Thu Jun 16, 2016 2:45 pm

Re: Get Instrument Type from existing liens via api

Post by sweinstock »

Thanks for your reply, I can get all the info from existing liens but when I add InstrumentType to the list I get a null exception.

This works:

Code: Select all

IEnumerable<dynamic> ExistingLiens = existingLiensSelect.Select(x => new
                      {
                          x.Mortgagor,
                          x.Mortgagee,
                          x.OriginalPrincipalAmount,
                          x.ConsiderationAmount,
                          x.Recording.Dated, 
                          x.Recording.RecordedDate,
                          x.Recording.PlaceRecorded,
                          x.Recording.AdditionalInfo
                      });

This code returns the error (I added x.InstrumentType...)

Code: Select all

 IEnumerable<dynamic> ExistingLiens = existingLiensSelect.Select(x => new
                      {
                          x.InstrumentType,
                          x.Mortgagor,
                          x.Mortgagee,
                          x.OriginalPrincipalAmount,
                          x.ConsiderationAmount,
                          x.Recording.Dated, 
                          x.Recording.RecordedDate,
                          x.Recording.PlaceRecorded,
                          x.Recording.AdditionalInfo
                      });

The error is
{
"message": "An error has occurred.",
"exceptionMessage": "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.",
"exceptionType": "System.InvalidOperationException",
"stackTrace": null,
"innerException": {
"message": "An error has occurred.",
"exceptionMessage": "Object reference not set to an instance of an object.",
"exceptionType": "System.NullReferenceException",
"stackTrace": " at SoftPro.Select.Client.Enumerations.EnumToValueTypeConverter`1.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)\r\n at SoftPro.EntityModel.ProxyField`1.ConvertFromFieldValue(Object value)\r\n at SoftPro.EntityModel.ProxyField`1.get_Value()\r\n at CallSite.Target(Closure , CallSite , Object )\r\n at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)\r\n at Title.Softpro.API.Controllers.ExistinsLiensController.<GetExistingLiens>b__f(Object x) in "" :line 20\r\n at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext()"
}
}

Thank you!
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Get Instrument Type from existing liens via api

Post by BobRichards »

The JSON serialization may be having trouble with the IInstrumentType interface. Try retrieving the Code or Description (String types) instead.

Code: Select all

IEnumerable<dynamic> ExistingLiens = existingLiensSelect.Select(x => new
{
    x.InstrumentType.Code,
    ...
});
Bob Richards, Senior Software Developer, SoftPro
sweinstock
Posts: 18
Joined: Thu Jun 16, 2016 2:45 pm

Re: Get Instrument Type from existing liens via api

Post by sweinstock »

Thanks for your reply. I changed it to code and description but both still gave me an error. I don't think it's a JSON issue though because in debug mode when I look at the object, it's showing instrument type with an error, while the other properties have values


This is from the debugger window, InstrumentType throws an exception :

- [0] {ExistingLien} ExistingLien
- Raw View
+ base {ExistingLien} SoftPro.EntityModel.ParentedEntity<Order,Order> {ExistingLien}
+ Assignments Count = 1 SoftPro.EntityModel.Collections.Set<ExistingLienAssignment>
+ AssumptionModification {AssumptionModification} AssumptionModification
ConsiderationAmount 7028 decimal
ExistingLoanNumber null string
+ InstrumentType '((new System.Linq.SystemCore_EnumerableDebugView<ExistingLien>(((SoftPro.EntityModel.Collections.EntityCollection<ExistingLien,ExistingLien>)(existingLiensSelect)) as System.Collections.Generic.IEnumerable<ExistingLien>)).Items[0]).InstrumentType' threw an exception of type 'System.NullReferenceException' SoftPro.Select.Client.Enumerations.IInstrumentType {System.NullReferenceException}

Thank you!
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Get Instrument Type from existing liens via api

Post by BobRichards »

I can't simulate your problem even though I used your code sample. I used the following code:

Code: Select all

using SoftPro.OrderTracking.Client.Orders;
using SoftPro.Select.Client;
using SoftPro.Select.Client.Enumerations;   // *** For IInstrumentType ***
using System.Collections.Generic;
using System.Linq;

// Pass in an open order.
public static void Liens(IOrder iOrder)
{
	IEnumerable<dynamic> liens = (IEnumerable<dynamic>)iOrder.GetProperty("ExistingLiens");

	IEnumerable<dynamic> ExistingLiens = liens.Select(x => new
	{
		// Added....
		((IInstrumentType)x.InstrumentType).Name,

		// Your original post...
		x.InstrumentType,
		x.Mortgagor,
		x.Mortgagee,
		x.OriginalPrincipalAmount,
		x.ConsiderationAmount,
		x.Recording.Dated,
		x.Recording.RecordedDate,
		x.Recording.PlaceRecorded,
		x.Recording.AdditionalInfo
	});
}
Note that you will have to add the IInstrumentType casting and namespace to access the enumeration properties. Since we are using a dynamic, VS2015 won't detect the runtime error of not including these items when it resolves "Name".
Bob Richards, Senior Software Developer, SoftPro
sweinstock
Posts: 18
Joined: Thu Jun 16, 2016 2:45 pm

Re: Get Instrument Type from existing liens via api

Post by sweinstock »

Thank you, I needed to add the casting. Also after seeing your code and testing I see that the instrument type only works within an open connection. I was first retrieving the dynamic objects and then setting the columns with the .select. It seems like instrument type needs an open connection. All is working now.
Thanks so much for all your help!
Post Reply