[.Net Core 2] jsreport Initialization Error
-
Hi there,
I've started to use jsreport a few days ago, as we plan to include it into our reporting solution.
I've encountered some issues and many I can find some help here.
I'm working with VS 2017, .Net Core 2 Web Api project.
I've installed nuget jsreport packages (Local, Shared, Types and Binaries for OSX, Linux et Windows).
I've only one Template defined, but I've made a lot of testing. I'm wondering if the issue is not related to the 5 max templates for on premise jsreport. I'm also unable to find any log file anywhere, but there should be some logs by default, right?
Anyway, I get the following error :
Error: An error occurred while trying to execute the command: at onCriticalError ([eval]:29603:25) at [eval]:29558:13 at tryCatcher ([eval]:36038:23) at Promise._settlePromiseFromHandler ([eval]:34061:31) at Promise._settlePromise ([eval]:34118:18) at Promise._settlePromise0 ([eval]:34163:10) at Promise._settlePromises ([eval]:34238:18) at Async._drainQueue ([eval]:31008:16) at Async._drainQueues ([eval]:31018:10) at Immediate.Async.drainQueues [as _onImmediate] ([eval]:30892: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]:30773:13) at listener ([eval]:8172:10) at EventEmitter.emit ([eval]:8260:22) at onData ([eval]:85844:8) at Lazy.<anonymous> ([eval]:51354:13) at Lazy.<anonymous> ([eval]:51336:19) at emitTwo (events.js:87:13) at Lazy.emit (events.js:172:7) at Lazy.<anonymous> ([eval]:51337:22) at emitOne (events.js:77:13) at Lazy.emit (events.js:169:7) at yieldTo ([eval]:51444:18) at Function.<anonymous> ([eval]:51482:27) at Lazy.<anonymous> ([eval]:51450:21) at emitOne (events.js:77:13) at Lazy.emit (events.js:169:7) at Socket.<anonymous> ([eval]:51313: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) {}Here is my GenerateDocument method :
private string GenerateDocument<T>(EDocumentFormat format, string documentPath, string documentName, IEnumerable<T> data)where T : IApiData
{
Report report = null;
byte[] FileData = new byte[] { };
string GeneratedFilePath = string.Empty;
IReportingBinary BinaryToUse = null;
//ILocalWebServerReportingService service = null;
ILocalUtilityReportingService service = null;try { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) BinaryToUse = jsreport.Binary.JsReportBinary.GetBinary(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) BinaryToUse = jsreport.Binary.Linux.JsReportBinary.GetBinary(); if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) BinaryToUse = jsreport.Binary.OSX.JsReportBinary.GetBinary(); switch (format) { case EDocumentFormat.Pdf: service = new LocalReporting() .RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport")) .KillRunningJsReportProcesses() .UseBinary(BinaryToUse) .Configure(cfg => cfg.AllowLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory()) .AsUtility() .Create(); /*service = new LocalReporting() .UseBinary(BinaryToUse) .KillRunningJsReportProcesses() .RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport")) .Configure(cfg => cfg.AllowLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory()) .AsWebServer() .RedirectOutputToConsole() .Create(); service.StartAsync().Wait();*/ string documentNamePdf = $"{documentName}.pdf"; string Json = $"{{\"items\": {JsonConvert.SerializeObject(data)}}}"; report = service.RenderByNameAsync("Call", data).Result; if (report != null && report.Content != null) { using (var fileStream = System.IO.File.Create(Path.Combine(FilePath, documentNamePdf))) { report.Content.CopyToAsync(fileStream); } } GeneratedFilePath = Path.Combine(FilePath, documentNamePdf); break; case EDocumentFormat.Csv: documentName = $"{documentName}.csv"; break; case EDocumentFormat.Rtf: documentName = $"{documentName}.rtf"; break; } return GeneratedFilePath; } catch (Exception ex) { Console.WriteLine($"Error : {ex}"); return string.Empty; } finally { if (service != null) service.KillAsync().Wait(); BinaryToUse = null; FileData = null; service = null; } }
Please note that I can start and run jsreport from command line, from "Temp\jsreport\dotnet\binary-default-1.10.0.0".
I hope someone could help me.
regards,
Stéphane
-
A little update :
I've setup the solution @home and no more error. I guess it should be related to the licence and max number of templates.How does it work, as for now, I only have one template defined? (Even if I've made multiple various tmeplates tests, like the samples and some personal testing)
It looks like the check to avoid using more than 5 templates is generating the error, and the error is quite unclear here.
Thanks in advance,
Stéphane
-
Moreover, where can I find the log. I can only access Exception content but can't find any log file. Does the default config with jsreport.Local includes logs, and if not, how can I set them up?
Thanks,
Stéphane
-
just to add my two cents, logs to files are not enabled by default, i think you can configure the logging to files by doing this (extracted from dotnet local docs:
The first you need to make sure you have jsreport folder created in the project and everything in it is being marked to be replicated into the bin folder as mentioned in the previous chapter. Then create inside file jsreport.config.json
in the
jsreport.config.json
file add this:{ "logger": { "file": { "transport": "file", "level": "info" }, "error": { "transport": "file", "level": "error" } } }
then you should see a new "logs" folder created inside the "jsreport" folder of your project.
-
Thanks, logs are working now.
And I finally get everything working, I put the initialization in Startup.cs, as a WebServer, and it seems to work without issue.