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



我使用的是ASP.net Core 3.0,我想拥有html to pdf导出功能,我发现JSReport是一个解决方案,所以我遵循Jon Blaha的JSReport.net SDK实现将html导出为pdf,我已经成功地在我的开发机器中安装了nugetsjsReport.BinaryjsReport.LocaljsReport.AspNetCore。以下是安装的dll

  • jsReport.AspNetCore.dll(v2.0.2.0(
  • jsReport.Client.dll(v3.0.1.0(
  • jsReport.Local.dll(v2.2.2.0(
  • jsReport.Shared.dll(v2.1.0.0(
  • jsReport.Types.dll(v2.6.1.0(
  • jsReport.Binary.dll(v2.7.1.0(

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

启动应用程序时发生错误

我搜索了这个错误,发现我必须使用启用通过web.config的日志记录

stdoutLogEnabled="true" stdoutLogFile=".logsstdout"

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

在对我的web.config进行了必要的更改后,我生成了日志文件,上面写着

System.IO.FileNotFoundException:无法加载文件或程序集"jsreport.Local,Version=2.2.20,Culture=neutral,PublicKeyToken=null"。系统找不到指定的文件。

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,其中包括我的project.dllproject.views.dllproject.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问题的建议。

请尝试只创建一个helloworld应用程序。它在那里工作吗?请将您的项目和部署输出上传到某个位置。

我试着准备一个新的asp.net核心mvc 3应用程序。引用的jsreport。已发布到文件夹,运行asp.net时没有问题服务器通过输出的exe。

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

  1. 我的服务器上存在文件权限问题
  2. jsReport试图在名为"jsReport"的根目录上创建一个文件夹,但由于文件夹访问权限(文件权限问题(,该文件夹未被创建
  3. 在上传过程中,我没有上传两个json文件projectname.deps.jsonprojectname.runtimeconfig.json

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

我通过在Startup.cs中使用此代码解决了我的问题

services.AddJsReport(new LocalReporting()
.KillRunningJsReportProcesses()
.UseBinary(JsReportBinary.GetBinary())
.AsUtility()
.KeepAlive(false)
.Create()
);

最新更新