rgvassar
rgvassar

Reputation: 5811

Crystal Reports Error in ASP.NET Core MVC. Could Not Load File

I am getting the following error in ASP.NET Core when trying to use Crystal Reports:

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.'

The dotnet1 folder was not created when I installed the SDK. I have seen that the adding the following to web.config could work in ASP.NET 4:

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>

This doesn't seem to work in ASP.NET Core, so I'm stuck.

So far I have installed the SDK, and installed the following using NuGet:

CrystalDecisions.CrystalReports.Engine
CrystalDecisions.Shared
CrystalDecisions.ReportAppServer

The target framework is .NET 4.6

Upvotes: 3

Views: 1151

Answers (1)

rgvassar
rgvassar

Reputation: 5811

I ended up setting it in code. I found the answer 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();

Upvotes: 1

Related Questions