JSReport:ASP.net 核心部署 - 无法加载文件或程序集 jsreport.Local

JSReport: ASP.net Core Deployment - Could not load file or assembly jsreport.Local

我正在使用 ASP.net Core 3.0,我想要 html to pdf 导出功能,我找到了 JSReport 作为解决方案所以我按照 JSReport .net SDK 的 Jon Blaha's Implementation 导出html 到 pdf,我已经在我的开发机器上成功安装了 nugets jsReport.BinaryjsReport.LocaljsReport.AspNetCore。 以下是已安装的 dll

我遵循了 Jon Blaha 的实现并且 Export html to pdf 在我的开发机器上运行良好。但是当我用我的项目发布的 dll 上传 dll 时,我的应用程序停止工作

an error occurred while starting the application

我搜索了此错误,发现我必须使用

通过我的 web.config 启用日志记录
stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout"

获取启动失败背后的实际错误消息。

对我的 web.config 进行必要的更改后,我得到了生成的日志文件,它说

System.IO.FileNotFoundException: Could not load file or assembly 'jsreport.Local, Version=2.2.2.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
      Application startup exception
System.IO.FileNotFoundException: Could not load file or assembly 'jsreport.Local, Version=2.2.2.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'jsreport.Local, Version=2.2.2.0, Culture=neutral, PublicKeyToken=null'
   at Technicianspk.Startup.ConfigureServices(IServiceCollection services)
   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 Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__2(IApplicationBuilder app)
   at Microsoft.AspNetCore.Server.IISIntegration.IISSetupFilter.<>c__DisplayClass4_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)

我使用 FileZilla 通过 FTP 仔细检查了我的 wwwroot 目录,我的服务器上有所有这些必需的 jsReport dll,但我仍然找不到文件。

我什至比较了 dll 版本并确保我的 .csproj 文件引用了所有必需的 jsreport dll,但仍然无法找到 jsReport.Local.dll

我的开发机器和服务器的 wwwroot 目录中都有 jsReport.Local.dll,所有其他 dll 都存在,包括我的 project.dllproject.views.dll 以及 project.exe 等.

我的cs.proj文件还有以下内容

<ItemGroup>
 <PackageReference Include="jsreport.AspNetCore" Version="2.0.2" />
 <PackageReference Include="jsreport.Binary" Version="2.7.1" />
 <PackageReference Include="jsreport.Client" Version="3.0.1" />
 <PackageReference Include="jsreport.Local" Version="2.2.2" />
 <PackageReference Include="jsreport.Shared" Version="2.1.0" />
 <PackageReference Include="jsreport.Types" Version="2.6.1" />
</ItemGroup>

正如 Jan Blaha 在 Github issue 上所建议的那样。

Please try to create just a hello world app. Does it work there? Please upload somewhere your project and how the deployment output looks like.

I tried preparing a new asp.net core mvc 3 app. Referenced jsreport. Published to the folder and there is no issue when running the asp.net server through outputted exe.

我创建了一个新的 hello world 应用程序并引用了 jsReport 并将其发布并上传到我的子域以进行测试。我有几个原因导致它不起作用

  1. There was a file permission issue on my server
  2. jsReport tried to create a folder on the root directory called 'jsReport' that was not being created because of folder access rights (file permission issues)
  3. I was not uploading 2 of json files projectname.deps.json and projectname.runtimeconfig.json during my uploading process

对我的主域进行上述更改后,网站终于开始工作了!

我在 Startup.cs

中使用此代码解决了我的问题
services.AddJsReport(new LocalReporting()
                .KillRunningJsReportProcesses()
                .UseBinary(JsReportBinary.GetBinary())
                .AsUtility()
                .KeepAlive(false)
                .Create()
            );