我在尝试使用 Crystal Reports 时在 ASP.NET Core 中遇到以下错误:
System.IO.FileNotFoundException: 'Could not load file or assembly
'file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET
Framework 4.0\Common\SAP BusinessObjects Enterprise XI
4.0\win32_x86\dotnet1\crdb_adoplus.dll' or one of its dependencies. The system
cannot find the file specified.'
dotnet1
文件夹不是在我安装 SDK 时创建的。我已经看到将以下内容添加到 web.config 可以在 ASP.NET 4 中工作:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
这在 ASP.NET Core 中似乎不起作用,所以我被卡住了。
到目前为止,我已经安装了 SDK,并使用 NuGet 安装了以下内容:
CrystalDecisions.CrystalReports.Engine
CrystalDecisions.Shared
CrystalDecisions.ReportAppServer
目标框架是.NET 4.6
最佳答案
我最终在代码中设置了它。我找到了答案 here .
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("BD39D1D2-BA2F-486A-89B0-B4B0CB466891")]
private interface ICLRRuntimeInfo
{
void XGetVersionString();
void XGetRuntimeDirectory();
void XIsLoaded();
void XIsLoadable();
void XLoadErrorString();
void XLoadLibrary();
void XGetProcAddress();
void XGetInterface();
void XSetDefaultStartupFlags();
void XGetDefaultStartupFlags();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void BindAsLegacyV2Runtime();
}
public Startup(IHostingEnvironment env)
{
ICLRRuntimeInfo clrRuntimeInfo =
(ICLRRuntimeInfo)RuntimeEnvironment.GetRuntimeInterfaceAsObject(
Guid.Empty,
typeof(ICLRRuntimeInfo).GUID);
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
clrRuntimeInfo.BindAsLegacyV2Runtime();
关于c# - ASP.NET Core MVC 中的 Crystal Reports 错误。无法加载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43769736/