ASP.net - An error has occurred when trying to initialize jsreport
-
Sorry about disappearing for a few days!
The path is C:\Windows\Temp. It requires admin access, which explains why it might not have appeared on searches. I ran jsreport.exe, and it works properly!
-
Ok, thanks. The things to try...
Try to run this command
echo hello > test.html jsreport.exe render --keepAlive --template.engine=handlebars --template.recipe=phantom-pdf --template.content=test.html --out=out.pdf
Does this work?
Perhaps changing the tempDirectory out from the Windows could help. This can be done in c# using:
var rs = new LocalReporting() .Configure((cfg) => { cfg.TempDirectory = Path.Combine(Directory.GetCurrentDirectory(), "jsreport", "temp"); return cfg; })...
-
Here's the config for JSreport's we're using:
JSReport.Service= new LocalReporting() .KillRunningJsReportProcesses() .UseBinary(JsReportBinary.GetBinary()) .RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport", "temp")) .Configure(cfg => cfg.AllowLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory()) .AsUtility() .Create();
I tried changing the directory to what you posted. The application did not launch. It threw an error, telling me that access was denied to the path c:\windows\system32\inetsrv\jsreport\temp. Which makes sense, because there is no jsreport exe in there.
I tried to then run it in the directory directly (.RunInDirectory(@"C:\Windows\Temp\jsreport"), and it threw a different error, pertaining to how it was unable to find the template. That also makes sense, because we've been running and keeping our jsreport files in the bin.
-
Thank you for more info. I spent now half day trying to figure out why the error message your provided doesn't include the actual error why the init failed.
I found out that we swallow the inner error in one place. I was able to fix that and rebuilt jsreport.exe.Now I would like to ask you to test it if you find time. It would be great. To run it...
Open
c:\Windows\Temp\jsreport\dotnet\binary-default-1.9.2.0\
. There you should seejsreport.exe
.
Download this exe and copy it there instead.
Run you original again and paste it here. We should see more info.
-
Thank you so much! I really appreciate the work you're putting in for this.
I placed it where you've directed, clean and rebuilt my project (even blew out the bin folder), and this is the error (still):
Error: An error occurred while trying to execute the command: at onCriticalError ([eval]:36106:25) at [eval]:36061:13 at tryCatcher ([eval]:9718:23) at Promise._settlePromiseFromHandler ([eval]:38241:31) at Promise._settlePromise ([eval]:38298:18) at Promise._settlePromise0 ([eval]:38343:10) at Promise._settlePromises ([eval]:38418:18) at Async._drainQueue ([eval]:4650:16) at Async._drainQueues ([eval]:4660:10) at Immediate.Async.drainQueues [as _onImmediate] ([eval]:4534:14) at processImmediate [as _immediateCallback] (timers.js:396:17) {"originalError":{}}(Original) Error: An error occurred while trying to start daemonized process: An error has occurred when trying to initialize jsreport.. at null.<anonymous> ([eval]:37276:13) at listener ([eval]:13761:10) at EventEmitter.emit ([eval]:13849:22) at onData ([eval]:85833:8) at Lazy.<anonymous> ([eval]:52268:13) at Lazy.<anonymous> ([eval]:52250:19) at emitTwo (events.js:87:13) at Lazy.emit (events.js:172:7) at Lazy.<anonymous> ([eval]:52251:22) at emitOne (events.js:77:13) at Lazy.emit (events.js:169:7) at yieldTo ([eval]:52358:18) at Function.<anonymous> ([eval]:52396:27) at Lazy.<anonymous> ([eval]:52364:21) at emitOne (events.js:77:13) at Lazy.emit (events.js:169:7) at Socket.<anonymous> ([eval]:52227:22) at emitNone (events.js:67:13) at Socket.emit (events.js:166:7) at emitReadable (_stream_readable.js:419:10) at emitReadable (_stream_readable.js:413:7) at readableAddChunk (_stream_readable.js:164:13) {}
-
Could you please reach me on skype or gitter "pofider" ? It would get faster if we solve this realtime.
Also would you be able to prepare a minimal project in which it fails for you? Just empty web app or something like that.
-
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 😄