We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

System.NullReferenceException while Exporting


I'm having an issue, when I'm exporting to excell the Grid, I have the following error message

El código de usuario no controló System.NullReferenceException
  Message=Object reference not set to an instance of an object.
       at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordCell(Object row, Column column)
       at Syncfusion.EJ.Export.GridExcelExport.<>c__DisplayClassf.<ProcessRecordRow>b__e(Column column)
       at System.Collections.Generic.List`1.ForEach(Action`1 action)
       at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordRow(Object row)
       at Syncfusion.EJ.Export.GridExcelExport.RenderRecord()
       at Syncfusion.EJ.Export.GridExcelExport.ProcessGridContents()
       at Syncfusion.EJ.Export.GridExcelExport.IterateElements()
       at Syncfusion.EJ.Export.GridExcelExport.ExportHandler()
       at Syncfusion.EJ.Export.GridExcelExport.ExecuteResult(GridProperties GridModel, Object dataSource)
       at Syncfusion.EJ.Export.GridExcelExport.ExportHelper(GridProperties gridModel, Object dataSource)
       at Syncfusion.EJ.Export.GridExcelExport.Export(GridProperties gridModel, Object dataSource, Boolean multipleExport)
       at Syncfusion.EJ.Export.ExcelExport.Export(GridProperties gridmaodel, Object datasource, String excelname, ExcelVersion excelversion, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, String theme)
       at Syncfusion.EJ.Export.ExcelExport.Export(GridProperties gridmaodel, IEnumerable datasource, String excelname, ExcelVersion excelversion, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, String theme)
       at HumanResourcesJAR.Controllers.ReportesController.ExportToExcel(String GridModel) in D:\Trabajo\Aplications\RRHH\HumanResoursesJAR\HumanResourcesJAR\Controllers\ReportesController.cs:line 482
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.<>c__DisplayClass1.<WrapVoidAction>b__0(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
       at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()

I have been searching the web, and have no solution to my problem.

Web config, the version of the dlls Syncfusion.EJ and  Syncfusion.EJ.Export are the same
<compilation debug="true" targetFramework="4.5.2">
        <add assembly="Syncfusion.Linq.Base, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.EJ, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.EJ.Export, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.Compression.Base, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.XlsIO.Base, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.Pdf.Base, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.DocIO.Base, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.OfficeChart.Base, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.EJ.MVC, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />

Also, the columns in the grid are the same in the datasource from the export, because I'm calling the same function in both cases. 

So what else should I check.

Thanks in advance.

9 Replies

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team January 11, 2017 12:57 PM UTC

Hi Dayne, 

We are unable to reproduce your reported issue  “System.NullReference Exception while exporting” at  our end in v14.4.0.15 . We have created the sample on Excel Exporting which can be downloaded from the below location. 

Could you please share us the following details so that we could sort out the cause of the issue and provide a solution as early as possible? 
1.       Please share us the Grid code example (both view and controller page). 
2.       Code example of datasource did you bind to the Grid. 
3.       Please make ensure that columns you have given are defined in the datasource. 
4.       If possible replicate the issue in the above sample and send us back. 
5.       Replication procedure for the issue. 
6.       Screenshot/ Video regarding the issue. 

The provided information will help us to analyze the issue and provide you the response as early as possible.  
Farveen T. 

DA Dayne January 11, 2017 04:09 PM UTC

I can't execute the code provided, it has a configuration error

Server Error in '/' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: Could not load file or assembly 'Syncfusion.Compression.Base, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error: 

Line 19:     <compilation debug="true" targetFramework="4.5">
Line 20:       <assemblies>
Line 21:         <add assembly="Syncfusion.Compression.Base, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
Line 22:         <add assembly="Syncfusion.EJ, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
Line 23:         <add assembly="Syncfusion.EJ.Mvc, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />

Source File: D:\Trabajo\Aplications\SAMPLE-1341969362\Sample142103\web.config    Line: 21 

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Syncfusion.Compression.Base, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89' could not be loaded.

=== Pre-bind state information ===
LOG: DisplayName = Syncfusion.Compression.Base, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89
LOG: Appbase = file:///D:/Trabajo/Aplications/SAMPLE-1341969362/Sample142103/
LOG: Initial PrivatePath = D:\Trabajo\Aplications\SAMPLE-1341969362\Sample142103\bin
Calling assembly : (Unknown).
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Trabajo\Aplications\SAMPLE-1341969362\Sample142103\web.config
LOG: Using host configuration file: C:\Users\dayne.perez\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Syncfusion.Compression.Base, Version=14.4400.0.15, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89
LOG: Attempting download of new URL file:///C:/Users/dayne.perez/AppData/Local/Temp/Temporary ASP.NET Files/vs/6fb5fef3/7d6a8866/Syncfusion.Compression.Base.DLL.
LOG: Attempting download of new URL file:///C:/Users/dayne.perez/AppData/Local/Temp/Temporary ASP.NET Files/vs/6fb5fef3/7d6a8866/Syncfusion.Compression.Base/Syncfusion.Compression.Base.DLL.
LOG: Attempting download of new URL file:///D:/Trabajo/Aplications/SAMPLE-1341969362/Sample142103/bin/Syncfusion.Compression.Base.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

So, I will re-attach your code example with all the files related with my grid, so you can see the code...

Best regards

Attachment: Sample142103_2f7d152c.rar

RU Ragavee U S Syncfusion Team January 12, 2017 12:39 PM UTC

Hi Dayne, 

Query #1: I can't execute the code provided, it has a configuration error 

As we have provided the sample in v14.4.0.15 and the dlls being referred from system GAC, the reported configuration error occurred. 

Please refer to the below knowledge base link for more information on resolving this issue. 

Query #2: I will re-attach your code example with all the files related with my grid, so you can see the code.. 

From your code examples, we found that, you have defined a field “Alta_Nominal” in grid columns whereas, the field name is defined as “AltaNominal” in ConsultarEmpleados_ReportResult class. Since the field name differs, the null exception has been obtained as explained in the below knowledge base link. 

So, please change the defined name same as that of the database in order to avoid reported Null exception. 

Ragavee U S. 

DA Dayne January 12, 2017 03:11 PM UTC


Thanks!! It is true, I didn't realize the underscore. That fix this issue.

But, I have another, I have a multiple export, and when I click excell export button once, all my tables are exported correctly, but if I click the export button again, without doing anything else, it pop up this message error, and I don't know why, It seems that the GridModel variable, with the grid properties is empty some how.. This behavior does not occur when I'm exporting a single grid, it just happend with multiple export.

Invalid JSON primitive: "EmptyRecord":"No records to display","GroupCaptionFormat":"{{:headerText}}: {{:key}} - {{:count}} ","GroupText":" item","True":"true","False":"false"}.

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.ArgumentException: Invalid JSON primitive: "EmptyRecord":"No records to display","GroupCaptionFormat":"{{:headerText}}: {{:key}} - {{:count}} ","GroupText":" item","True":"true","False":"false"}.

Source Error: 

Line 1572:                    gridProp.AutoFormat = auto;
Line 1573:
Line 1574:                    book = exp.Export(gridProp, DataSource, "Export.xlsx", ExcelVersion.Excel2013, false, true, "default-theme", true);
Line 1575:                    count = book.ActiveSheet.Rows.Count();
Line 1576:                    initial = initial + 1;

Thanks in advance.

PK Prasanna Kumar Viswanathan Syncfusion Team January 13, 2017 11:11 AM UTC

Hi Dina, 

Query : “Null Exception” 

We are happy to hear that your issue has been resolved. 

Query 2 : “Pop-up message error” 

Before we proceed with this error, we need the following details. 

1. Share the code example of a Grid and controller. 

2. Share the full stackrace of an issue. 

3. If possible, share the issue reproducible sample with us. 
Prasanna Kumar N.S.V 

DA Dayne January 13, 2017 06:29 PM UTC

1. Share the code example of a Grid and controller. 

   I will attach the project with a sample

2. Share the full stackrace of an issue. 
  Just open the GridFeatures View, fill all the data, and then clic on the magnifying glass icon, and then on the Excel icon to export all data, the export occurs just fine, the clic again on the Excell icon, without doing anithing else..

Thanks in advance

Attachment: Sample142103_33146777.rar

RU Ragavee U S Syncfusion Team January 20, 2017 03:50 AM UTC

Hi Dayne,  

We can reproduce the mentioned issue in the attached sample and a support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates.   

As a workaround, use the below code example.  
    function template(args) {  

Prasanna Kumar N.S.V  

DA Dayne January 20, 2017 05:04 PM UTC


Thanks for the reply.  The workaround you provided works perfectly.


RU Ragavee U S Syncfusion Team January 23, 2017 04:29 AM UTC

Hi Dayne, 

We are happy that the issue is resolved. Please don’t hesitate to call us back, if you have need any further assistance. 

Ragavee U S. 

Live Chat Icon For mobile
Up arrow icon