reporting services - SSRS ReportViewer nullreference exception on Disposing -


we're using windows service generate pdf files. optimizing code , noticed abusive use of memory. caused lack of using statement around var reportviewer = new reportviewer()

however, after adding code threw runtime nullreference exception after closing using block, code originating in internal dispose method.

why error occur , how can dispose object properly?

the answer, can found in visual basic here because reason reportviewer expects httpcontext. if none present, error occur.

as workaround following lines can added resolve issue:

                if (system.web.httpcontext.current == null)                 {                     system.web.httpcontext.current = new system.web.httpcontext(                         new system.web.httprequest(system.io.path.getrandomfilename(), "https://www.stackoverflow.com", string.empty),                         new system.web.httpresponse(system.io.textwriter.null)                         );                 } 

this create fake httpcontext, allowing somehow dispose reportviewer instance properly.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -