ASP.net - An error has occurred when trying to initialize jsreport
-
Certainly! Allow me a few moments to prepare the project, and I will contact you shortly. Thank you!
-
SOLVED/SOLUTION: As it turns out, my license key was improperly applied. I have it applied through my environment variable and it is currently working. Big thanks to Jan, who worked with me for hours on this!
-
Hi i'm facing the same issue. However earlier the same piece of code was working like a charm, below are the details.
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup><PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>7.2</LangVersion>
</PropertyGroup><ItemGroup>
<PackageReference Include="jsreport.Binary" Version="1.10.0" />
<PackageReference Include="jsreport.Client" Version="2.0.2" />
<PackageReference Include="jsreport.Local" Version="1.1.2" />
</ItemGroup>Code Snippet. The same i downloaded from your github repo.
https://github.com/jsreport/jsreport-dotnet-example-consoleappRunning above app gives me an error.
Also i have created a Web API project there also same error persist. Code snippet is below.
Start Up file:
public void ConfigureServices(IServiceCollection services)
{
services.AddNodeServices();
services.AddSingleton<IConfiguration>(_config);
services.AddMvcCore(opt =>
{
opt.OutputFormatters.RemoveType<TextOutputFormatter>();
opt.OutputFormatters.RemoveType<HttpNoContentOutputFormatter>();
})
.AddJsonFormatters() // Adding Json Formatters in Pipeline
.AddDataAnnotations() // Always keep it in config for Model Validation
.AddJsonOptions(opts =>
{
opts.SerializerSettings.ContractResolver = new DefaultContractResolver();
opts.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
opts.SerializerSettings.DefaultValueHandling = DefaultValueHandling.Include;
opts.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
})
.AddMvcOptions(opts =>
{
opts.RespectBrowserAcceptHeader = true;
opts.ReturnHttpNotAcceptable = true;
});
}method to generate HTML TO PDF
public static async Task<byte[]> Generate_PDFReport(string template, string headerTemplte, string footerTemplte, string content, string helper)
{
try
{
var runExePath = Path.Combine(Directory.GetCurrentDirectory(), "jsreport", "temp");
var rs = new LocalReporting()
.RunInDirectory(runExePath)
.KillRunningJsReportProcesses()
.Configure(cfg => cfg.AllowLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory())
.UseBinary(JsReportBinary.GetBinary()).AsWebServer().Create();await rs.StartAsync(); var report = await rs.RenderAsync(new RenderRequest() { Template = new Template() { Recipe = Recipe.PhantomPdf, Engine = Engine.Handlebars, Content = template, Helpers = helper, //XlsxTemplate = new XlsxTemplate { // Content = "", // Shortid = "" //}, Phantom = new Phantom { Header = headerTemplte, Footer = footerTemplte, Orientation = PhantomOrientation.Portrait, Format = PhantomFormat.A4, BlockJavaScript = true, Margin = MarginNew } }, Data = content }); using (var ms = new MemoryStream()) { report.Content.CopyTo(ms); byte[] byteContent = ms.ToArray(); await rs.KillAsync(); return byteContent; } } catch (Exception ex){ throw; } }
EXceptions:-
Win32Exception: Access is denied
System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
System.Diagnostics.Process.Start()
jsreport.Local.Internal.BinaryProcess+<InnerExecute>d__18.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult()
jsreport.Local.Internal.BinaryProcess+<ExecuteExe>d__17.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
jsreport.Local.Internal.LocalWebServerReportingService+<StartAsync>d__32.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Net_Core_Poc.PDFGenerator_jsReport+<Generate_PDFReport>d__1.MoveNext() in PDFGenerator_jsReport.cs-
catch (Exception ex){ throw; }
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Net_Core_Poc_API.Controllers.PDFController+<Get_jsReportPDF>d__9.MoveNext() in PDFController.cs-
var bytesContent = await PDFGenerator_jsReport.Generate_PDFReport(htmlContent, "<div style='text-align:left'></div>", "<div style='text-align:center'>{#pageNum}</div>", jsonData, helper);
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeActionMethodAsync>d__12.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeNextActionFilterAsync>d__10.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeInnerFilterAsync>d__14.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeFilterPipelineAsync>d__17.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeAsync>d__15.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__7.MoveNext()Show raw exception details
System.ComponentModel.Win32Exception (0x80004005): Access is denied
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at jsreport.Local.Internal.BinaryProcess.<InnerExecute>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at jsreport.Local.Internal.BinaryProcess.<ExecuteExe>d__17.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
at jsreport.Local.Internal.LocalWebServerReportingService.<StartAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Net_Core_Poc.PDFGenerator_jsReport.<Generate_PDFReport>d__1.MoveNext() in G:\RND\RnD_Solutions\Net_Core_Poc\PDFGenerator_jsReport.cs:line 68 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
at Net_Core_Poc_API.Controllers.PDFController.<Get_jsReportPDF>d__9.MoveNext() in G:\RND\RnD_Solutions\Net_Core_Poc_API\Controllers\PDFController.cs:line 923
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
-
-
I'm far less qualified than Jan to comment, but I'll give a few thoughts! If you error message is "Access is denied", then I would first try running the project as administrator. If that doesn't work, go to every place that jsreports will be accessing (temp folder, folder where you store templates, etc) and make sure the security allows access. If you're using IIS, then you'll have to grant full control to "IUSR" and "IIS_IUSRS"
-
Hi great help incredible. But things went the other way around.
I can run the project irrespective of modes(admin/standard user), now i'm getting an error from the antivirus(Avast Free Ware) that i have installed on my workstation. But however if i unchecked the Checkbox to (Scan programs when executing, it's an option in the Avast antivirus dashbord) the code works like a charm.What I don't understand is that is it good practice to disable "Scan programs when executing," option in the antivirus. Coz when i disable the option, i can run the poc effortlessly. Vice versa is leading to a malware Detect error, avast antivirus recognizing .jsReport.exe as some maleware and removing it after clicking yes to remove.
Also now im getting a popup saying its been submitted to Avast Lab, and soon will be hearing about it.
-
When i'm adding the jsReport.exe as a trusted file the code works great, seems like some issue on jsReport.exe thing.
-
Is there any way to put this whole observation into some mspaint file or somewhere so that everybody will get the idea.
-
Adding to above issue, observation made while running the project with admin mode, and trying to give jsReport.exe the admin permission i'm getting Windows defender smartscreen alert saying Windows Defender
Windows protected your PC
Windows Defender SmartScreen prevented an unrecognized app from starting. Running this app might put your PC at risk.App:
jsreport.exe
Publisher:
Unknown publisherAnd i'm not able to give the jsreport.exe admin permission.
-
Is there any way to put this whole observation into some mspaint file or somewhere so that everybody will get the idea.
click the "Reply" button, and then drag and drop an image in the box that has the "compose" text
-
After adding the path of jsreport.exe in the exclusion category inside Avast antivirus console, and removing below two codes i'm able to generate the reports.
var rs = new LocalReporting()
//.RunInDirectory(runExePath)
.KillRunningJsReportProcesses()
//.Configure(cfg => cfg.AllowLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory())
.UseBinary(JsReportBinary.GetBinary()).AsUtility().Create();Still i want to know why avast and windows defender behaves like this?
-
That's a great question. My guess is that avast and windows defender don't like seeing random executables being started seemingly out of the blue, and not many users with them have added them as exclusions to the database. It's probably just a growing pain of sort for JSreports.
Keep in mind, that's my guess as a user, not a developer or anything.
-
Observations
Running the project in admin mode.
Code shot:-
Avast Antivirus:-
Conclusion:-
I'm able to download the Pdf file generated from the HTML contents.
Removing Exclusion from Avast antivirus:-
Running the Application and the observation :-
Above are all my observations.
-
as @tyler-shuhnicki has said i think all of this is just the result of antivirus being defensive by default (the same for windows defender), of course jsreport.exe is not a malware or something dangerous but antivirus says that because it doesn't know what it is so the best default for the antivirus is to block the executable and ask you (the user) to allow the executable explicitly. there should be a way to allow the executable in windows defender too.
btw i think all of this is caused by having
Publisher: Unknown publisher
maybe we can find a way to fill this "publisher" information so maybe it can help the executable to not be detected as something dangerous, in the mean time just allow the executable explicitly in your antivirus and windows defender rules.
-
and just for the record, every software in the world at some point has to deal with incorrect antivirus reports so i think the easy workaround for now is to configure them to always allow the jsreport.exe 😄
-
Great response, keep the good work up.These were just some bunch of random observations while doing the POC. Thank you all again.
-
@explorer855 thanks for sharing your case, it is good to know new kind of problems that users can face.