Debugging ReportingEngine

I’m having some trouble debugging my application that uses the LINQ ReportingEngine. The following error is shown when I try to generate a report.

System.ArgumentNullException: ‘Value cannot be null.
Parameter name: value’

Below is the method where the exception occurs, with the offending line marked with a caret symbol (>)

 protected internal virtual Document Build<TData>(ReportingEngine Engine, TData Data, ITemplateProvider TemplateProvider)
        {
            Stream Template = TemplateProvider.GetTemplate(TemplateName);
            Template.Position = 0;
            Document Document = new Document(Template);
        >   if(Document != null) Engine.BuildReport(Document, Data);
            return Document;
        }

My steps to debug the problem:

  • I have ensured that Document and Data are both not null. The template file is found and loaded properly, and the Data object contains all the necessary information.
  • I have tried to run the code with different templates:
    • If I use a template without any fields in it, no errors are thrown and the document is outputted as is. This further confirms that the template file is loaded correctly.
    • If I use a template with only one field in it, the error is thrown again. The Field is definitely present in the Data Object (and even if it wasn’t, I’d expect a different error, saying that that specific property could not be found).
  • I have created a seperate project which just generates a report. It uses the same report generation code and template files. In this seperate project, the code works properly. However, in my main application (an ASP.NET MVC website), the error is thrown.

I cannot find the source of the exception in the Exception Details. The error message refers to the parameter ‘value’, but I don’t know which parameter that is (again, both Document and Data are not null). The stack trace only shows my own code up to the above method call.

Any ideas what the problem could be here? I’ll keep trying to reproduce the issue in a seperate project for now, to see if I can isolate what the difference between my two projects is.

@TPTWouter,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Hi Tahir,

thank you for your response.
I spent the better part of last week trying to reproduce the bug in a seperate project, but have been unsuccesful. I ultimately narrowed it down to a situation where I used an EntityFramework Entity Model in my ReportData object. So maybe the exception is related to the proxy-classes that Entityframework creates.

I have since implemented a workaround where I first copy all my entities to a seperate class (using Automapper) which solved the issue for now. Due to time constraints, I will not continue to look into it for now, but if I ever find out more I will let you know.


In the mean time, I have one more - slightly related - question. When an expression in my template (eg <<[Company.Address.Country.Name]>> contains an element that evaluates to null (in this case, if Address is null), the engine will crash with a slightly different NullReferenceException.

Would it be possible to see a more detailed exception for this scenario in the future, that shows which expression threw the error? And is there a way to handle such an exception gracefully (other than adding a lot of null-checks to the template)? Possibly using a callback function to allow me to handle the exception in the code (for example by outputting a log file or writing to the console).

Also, it’d be nice if the report generation could still continue if an exception occurs in one of the expressions, by leaving the expression unevaluated, removing the expression altogether, or replacing it with a default value.

Are any of these things possible in the current version of the ReportingEngine? If not, could they be considered as new features in the future?

@TPTWouter,

Thanks for your inquiry. We have logged a ticket in our issue tracking system as WORDSNET-16480 to throw meaningful exception for ReportingEngine.BuildReport. Once we have any information about this feature, we will update you via this forum thread.

Please let us know if you have any more queries.

1 Like