Welcome Guest Search | Active Topics | Sign In | Register

.NET Core exception at StreamResponseBodyFeature - value cannot be null Options
Ray Riopel
Posted: Thursday, March 18, 2021 4:52:30 PM
Rank: Newbie
Groups: Member

Joined: 3/18/2021
Posts: 6
I'm upgrading an older .NET framework ASP.NET MVC app to .NET 5. Can't seem to get EO.pdf's RenderAsPDF() function to work as it did with .NET framework. I've created a new ASP.NET MVC Core app using VS2019 and have done the following:

1. Added EO.Pdf.Mvc, System.Drawing.Common, System.Text.Encoding.CodePages nuget packages.
2. Called AddLicense()
3. Called RegisterFiltersAspNetCore as follows

services.AddControllersWithViews(options =>
{
//Register EO.Pdf MVCToPDF filters
EO.Pdf.Mvc.MVCToPDF.RegisterFilterAspNetCore(options);
});

4. Setup controller with RenderAsPDF() as follows

[EO.Pdf.Mvc.RenderAsPDF(AutoConvert = false)]
public IActionResult Index(string format)
{
if (!string.IsNullOrEmpty(format) && format.ToLower() == "pdf")
{
EO.Pdf.Mvc.MVCToPDF.ResultFileName = "eo-pdf.pdf";
EO.Pdf.Mvc.MVCToPDF.RenderAsPDF();
}

return View();
}

I get this exception.

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.ArgumentNullException: Value cannot be null. (Parameter 'stream')
at Microsoft.AspNetCore.Http.StreamResponseBodyFeature..ctor(Stream stream, IHttpResponseBodyFeature priorFeature)
at Microsoft.AspNetCore.Http.DefaultHttpResponse.set_Body(Stream value)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at EO.Pdf.Mvc.MVCToPDF.vrlw.sjgr.fbjr()
at EO.Pdf.Mvc.MVCToPDF.dbei()
at EO.Pdf.Mvc.Emit.Filter.IResultFilter.OnResultExecuted(ResultExecutedContext )
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)


Anything else I need do?
eo_support
Posted: Monday, March 22, 2021 10:03:34 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

What version do you use? We tested it on the latest version and we are not able to reproduce the problem.

Thanks!
Ray Riopel
Posted: Monday, March 22, 2021 10:44:18 AM
Rank: Newbie
Groups: Member

Joined: 3/18/2021
Posts: 6
I'm using version 21.0.32. Is there working sample available that I could download? I don't see an ASP.NET Core sample included in the download.
Ray Riopel
Posted: Monday, March 22, 2021 11:09:32 AM
Rank: Newbie
Groups: Member

Joined: 3/18/2021
Posts: 6
I think this is probably a licensing issue. If I switch to RenderAsPDF(AutoConvert = true), I get a license error (due to using a license from an old version). If i comment out the license, it renders with the license warning. I'll get the latest license from the client and update here after that.
eo_support
Posted: Monday, March 22, 2021 11:23:50 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

There isn't much to the working sample at all --- it's just an empty ASP.NET MVC project generated straight from the .NET Core MVC template. The issue appear to have something to do with something else in your application. The basic logic for MvcToPDF is like this:

1. At the beginning of the request, we would replace the default output stream (of type Microsoft.AspNetCore.Server.IIS.Core.HttpResponseStream);
2. ASP.NET Core would take our output stream. Both ASP.NET Core and EO.Pdf would save the original stream object;
3. At the end of the request, EO.Pdf would try to restore the original stream based to the saved value on step 2;
4. ASP.NET would compare this value with the value that it previously saved. If it does not match, then it will cause the error you received;

Thus it appears that in your application somebody else also replaced the output stream between step 2 and step 3. So if you can isolate it into a test project and send it to us, we can look into it and see if we can change our code to accommodate this situation. See here for information on sending test project to us:

https://www.essentialobjects.com/forum/test_project.aspx

Thanks!

Ray Riopel
Posted: Monday, March 22, 2021 12:03:31 PM
Rank: Newbie
Groups: Member

Joined: 3/18/2021
Posts: 6
Correct license didn't fix it. I have uploaded a sample project that reproduces the exception. RenderAsPDF(AutoConvert = true) works fine. RenderAsPDF(AuthoConvert = false) will crash.
eo_support
Posted: Monday, March 22, 2021 4:36:31 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Thank you very much for your test project. We were able to find out the root of the problem. This will be fixed in our next build.
Ray Riopel
Posted: Monday, March 22, 2021 7:08:22 PM
Rank: Newbie
Groups: Member

Joined: 3/18/2021
Posts: 6
Great, thanks! I have a work around for now so all is good. We'll be on lookout for the next release.
eo_support
Posted: Tuesday, March 23, 2021 9:34:30 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
You are welcome. We will reply here again when the new build is out.
eo_support
Posted: Friday, March 26, 2021 3:13:12 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

This is just to let you know that we have posted a new build (20.0.69) that should resolve this problem. You can download the new build from our download page. Please take a look and let us know how it goes.

Thanks!
Ray Riopel
Posted: Monday, March 29, 2021 4:09:14 PM
Rank: Newbie
Groups: Member

Joined: 3/18/2021
Posts: 6
That fixed it. Thanks for the quick turnaround.
eo_support
Posted: Tuesday, March 30, 2021 9:47:45 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Great! Thanks for confirming the fix!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.