stiReport object incompatible with NewtonSoft Json.NET

Stimulsoft Reports.WEB discussion
Post Reply
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

stiReport object incompatible with NewtonSoft Json.NET

Post by brianj774 »

Hi,

In my (MVC4) project, the primary action method (to generate a report) sets up and executes all the database calls, converts the data to a datatable object, and synch's with the dictionary, etc. Once this step is done, I stuff the report object in the session, and present the view. On the GetReportSnapshot callback action, I retrieve the report object from the session, and proceed with the rendering.

The motivation for this is to spread out the operations between different parts of the system, in order to alleviate timeouts on large reporting datasets.

However, I would like to remove any dependency on the session object, so I have built a mechanism of saving session information to the database, which relies heavily on NewstonSofts Json.NET serialization/deserialization. Following you'll find my attempted serialization code, and then the stacktrace.

Please advise how I should proceed.

Code: Select all

			var obj = new reportRenderState {
				oReport = report,
				reportID = rptVO.oTblReport.ID,
				lRowCount = rptVO.dtResult.Rows.Count,
				nvcQueryString = Request.QueryString
			};

			
			string jsonObj = JsonConvert.SerializeObject(
				obj,
				Formatting.Indented,
				new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects }
			);

Code: Select all

 Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 295:
Line 296:			
Line 297:			string jsonObj = JsonConvert.SerializeObject(
Line 298:				obj,
Line 299:				Formatting.Indented,


Source File: C:\Work\Webstore\ws_trunk\tmpFlex_RenameMe\RevTrakPortal\RevTrakPortal\Controllers\ReportController.cs    Line: 297

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   Stimulsoft.Report.StiReport.get_PageNumberThrough() +21
   GetPageNumberThrough(Object ) +50
   Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target) +86

[JsonSerializationException: Error getting value from 'PageNumberThrough' on 'Reports.Report'.]
   Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target) +187
   Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue) +125
   Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) +330
   Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) +261
   Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) +330
   Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) +261
   Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value) +41
   Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value) +376
   Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonSerializerSettings settings) +165
   RevTrakPortal.Controllers.ReportController.Render(Int32 id, Boolean edit, Boolean dup) in C:\Work\Webstore\ws_trunk\tmpFlex_RenameMe\RevTrakPortal\RevTrakPortal\Controllers\ReportController.cs:297
   lambda_method(Closure , ControllerBase , Object[] ) +194
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +205
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +50
   System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +58
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +237
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +237
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +126
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +45
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +25
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +61
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +25
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +49
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +28
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +25
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +49
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9042429
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

Re: stiReport object incompatible with NewtonSoft Json.NET

Post by Vladimir »

Hello,

Please try to use the code below for these purposes:

Code: Select all

var obj = new reportRenderState {
            oReport = report.SavePackedReportToString(),
            reportID = rptVO.oTblReport.ID,
            lRowCount = rptVO.dtResult.Rows.Count,
            nvcQueryString = Request.QueryString
         };
Thank you.
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

Re: stiReport object incompatible with NewtonSoft Json.NET

Post by brianj774 »

Doesn't seem to do the trick... when I get the report back out in the GetReportSnapshot() action method, it blows up on render.... if I just pass the actual report object, instead of the string, all works as expected (presently I have not yet implimented the save to db part, so we're still just using the session to store the data).
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

Re: stiReport object incompatible with NewtonSoft Json.NET

Post by Vladimir »

Hello,

To work MvcViwer uses a cache or session server storage for the rendered report. To disable this behavior, you can use the "ServerCacheMode = StiCacheMode.None" option.

Thank you.
Post Reply