cancel
Showing results for 
Search instead for 
Did you mean: 

Using Crystal Report for VS runtime from DLL which is called be C++ exe

Former Member
0 Kudos

Hello,


I am doing some evaluation about moving our current reportsystem to a newer state using the newest "Crystal Report for Visual Studio" with the newest servicepack 5 and Visual Studio 2013.


I managed to create and load new reports to the CrystalReportViewer in C# quite easily and I is it also possible to load our existing reports, which were created with Crystal Report XI.

They use ODBC Text Drivers.

This all works perfectly fine in a stand alone application which uses .Net 4.5.2.

As the next step I tried to add this simple client as a dll library to our existing program, which is written in c++.

When debugging it works just fine and as expected, but when I then start the main program normaly and try to show a report Crystal Report crashes with the following message when CrystamReportViewer.ReportDocument is set.:

As you see the message does not help that much here.

Since it is working as a stand alone application and it gives the same error in all reports I suppose it is not a problem of the reports.

Have someone experienced something like this before?

The Crystal Report Assemblies use .Net Framework 2.0.

I have read that it is needed for standalone programs to add a app.config file with

<?xml version="1.0" encoding="utf-8"?>

<configuration>

  <startup useLegacyV2RuntimeActivationPolicy="true">

    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>

  </startup>

</configuration>


But this is not possible for library dlls.

As far as I know this needs to be set in the main program, which is the exe written in C++.


So the problem is to use the Crystal Report runtime in a .Net 4.5.2 library dll which is called from an exe written in C++.

Do someone maybe have an idea what to do here and how this can be fixed.



Help is pretty much appreciated and thanks in advance.


Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Thomas,

If your app is not using ADO.NET or ADOPlus then it's not required. if you are using it a quick Google search in setting that MS property found this:

Setting useLegacyV2RuntimeActivationPolicy At Runtime : Reed Copsey, Jr.

What you may want to do is some DB debugging, looks like CR runtime can't find the required DB drivers or dependencies.

See if ProcessMonitor shows you more info on the error.

Don

Former Member
0 Kudos

Thanks for the response Don,

I am pretty new to this and I can't really grasp where the problem can be, so I am thankful for any tips

I will try to make some debugging, but the reports only use ODBC text drivers, which work perfectly when the Crystal Report Viewer is used in a seperate standalone app.

I noticed, that I get the warning, that the reports use an invalid printer and that the default one is used. Might that allso cause the problem?

0 Kudos

Go to Page Setup in CR Designer and set the report to use a specific printer or check on the Dissociate option to remove the printer specifics.

And to be clear you made a typo when you said using SP 5, did you mean SP 15?

Check your reports also, make sure no formula fields are referencing fields that do not exist. Click the X-2 button for each formula to confirm they are valid, if not fix them and test again.

Don

Former Member
0 Kudos

Ah, yes. Thanks. That was a typo. I meant SP15, sorry for that.

I want to share my progress here.

I made a report that is as simple as possible.

It only has one textbox and no datasources at all.


I still get the same message when calling it.

So I would say it is not a problem of the reports.


I also tried the code from your link and let the RuntimePolicyHelper set the LegacyV2Runtime flag before calling the ReportViewer. Sadly no change in the behaviour...


Is there maybe some example code for using the viewer in a c# dll?

All examples I can find are simple stand alone applications.

former_member183750
Active Contributor
0 Kudos

I wonder if writing the CR part in C++ rather than using C# will help. See:



(There are more C++ samples - just enter the string 'crystal net C++' in the search box in top right corner, then filer for "Collaborative Documents".)


Having a look at Process Monitor log may give you a clue - not sure but it may tell you if there is an issue loading an assembly or a dependency.


Is the app / dll compiled as 32 bit or 64 bit?




- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow me on Twitter

  Got Enhancement ideas? Use the SAP Idea Place

Former Member
0 Kudos

Ok, I tried to get some clues from the ProcessMonitor you recommended.

The only strange calls I have found are these:

Do you know if these can cause problems or are pretty normal?

I do not get errors about loading assemblies or dependencies.

The app is compiled in 32 bit.

But I will also try the .Net c++ samples, but I do not think this changes the behaviour, because it also lays upon the .net Framework, doesn't it?

I also found out that the error does not show up when I try to show an empty report or a report with only a Picture of tpye ICROIeObject.

Maye this is relatied to text rendering or fonts?

former_member183750
Active Contributor
0 Kudos

The logs are fine. However fonts...

There is a thread on here regarding issues with Times New Roman font (if memory serves right) when used on a WIN 2012 server. I just can't recall the specifics... But the report would not load - changing the font to anything else (say Calibri) made the error go away and report loaded. E.g.; it may be worthwhile experimenting with couple of fonts(?).

- Ludek

0 Kudos

Did you replace the viewer in your dll? those errors appear to be your dll trying to render the viewer.

Did you update the references as well, could be it's loading both versions...

Don

Former Member
0 Kudos

Hi Don,

I checked the path and all references show to the path

"C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet\CrystalDecisions.CrystalReports.Engine.dll",

which is the same than in the example projects I found.

The Version is 13.0.2000.0 and I have installed the newest servicepack 15.

This sound about right, doesn't it?

Do you know about a way to check if this can be the problem?

0 Kudos

Path looks good.

On your form where CR Viewer is did you delete the viewer and add the version 13 viewer?

Don

Former Member
0 Kudos

Yes, and the error still shows up.

Can you tell me how I can find out if both versions are loaded?

0 Kudos

Do you have more than one version of CR installed?

Go to Programs and features and see what other SAP CR installs.

What happens if you set the framework back to 4.0 or 3.5?

Don

Answers (1)

Answers (1)

Former Member
0 Kudos

Hey guys,

after some time past I made same more investigation and found something out:

When I open a report with dynamic parameters everything works as expected. The report is loading and I do not get any errors.

After that I can open any report without problems, when I use the same instance of the CrViewer.

So the paths to the crystal reports assemblies and the setup seems to be correct, which narrows down the problem.

But I still get the error message pasted in the first page when I try to open a report without dynamic parameters.

For me it seems like not everything is properly loaded at the first start, which causes the error.

Do you have an idea or hint where to look at here and what can cause that?

Have you experienced something like this before?

0 Kudos

That is very odd behaviour... CR's parameter prompt is a JS file. Could be permissions.

See if Fiddler catches the problem.

Former Member
0 Kudos

I might have some additional information.

I also enabled first chance exceptions in the debugger and got these 3 exceptions when loading the report. The report is totally empty, so it should not be a problem of the report.

It makes no difference if it is run as a normal user or as an admin.

Have you already experienced such problems and maybe know a solution for it?

Maybe this is also the reason for the other problems.

Is it possible to get more infos with Fiddler? I thought it can only be used for Web development.

0 Kudos

Ah, that could be the problem. The engine does not like to open completely blank reports, I had this same problem last week also when testing.

Add anything to the report, a text object with hello world in it or something...

Don

Former Member
0 Kudos

Hi Don,

thanks for the input.

I think you got me wrong.

I tested it with an empty report to have as less distractions as possible, but it also shows up when loading other reports with more infos.

The behaviour is always the same.

When loading a report with dynamic parameters I also get this error:

Have you seen this behaviour before?

0 Kudos

Hi Thomas,

Oops, correct Fiddler is for debugging WEB app's.

Can you run DebugDiag from MS and capture the exception and analyse it?

The Parameter Dialog box is Java Script, js files, possibly permissions or maybe it not installed???

What line of code is the exception being triggered on? If it's the Load() then have you tried adding the OpenAsTemp... property? It can happen if you ahve the report open in CR Designer or another application.

You may want to delete all files in your \UserName\appdata\local\temp folder. Could be some left over files are locked...

Don

Former Member
0 Kudos

Can you run DebugDiag from MS and capture the exception and analyse it?

     Thanks, I will check that.


The Parameter Dialog box is Java Script, js files, possibly permissions or maybe it not installed???

     Ah, okay. The parameter dialog box is opening but I still get this exception. Kind of      strange, isn't it?


What line of code is the exception being triggered on? If it's the Load() then have you tried adding the OpenAsTemp... property? It can happen if you ahve the report open in CR Designer or another application.

     Yes, the errors occur when ReportDocument.Load is called.

     Mh, I haven't seen the OpenAsTemp property before and a Google search does not give      any results, too. Can you tell me where to set it?


You may want to delete all files in your \UserName\appdata\local\temp folder. Could be some left over files are locked...

     deleting the temp does change anything, but thanks for the suggestion.

0 Kudos

Open as Temp:

rpt.Load(rptName.ToString(), OpenReportMethod.OpenReportByTempCopy);

Have you tried doing a repair install of VS and Cr for VS?

Don

Former Member
0 Kudos

Open as temp sadly makes no difference.

As a test I also tried to export the reports directly to pdf instead of opening them in the CrystalReportViewer control. This seems to work, so I guess it is a problem with the ViewerControl the framework provides.

If a try to view them I get the message from the very first entry of this post.

Strange thing is, that it is working when the js dialog for setting the parameters is used in the projects.

When such a project is loaded I can click on any other report and it also opens in the same instance of the CrystalReportViewer without errors.

But I need to open in correctly at the first time of course.

Do you have any more suggestions?

The installations of CR runtime are looking good, too.

We have this problem on all our PCs, so I doubt it is an installation problem.

Is there maybe a hotline which can help in such cases and maybe can look on my screen for a debugging session? I am out of ideas...

0 Kudos

Hi Thomas,

Did you ever try those sample C++ app Ludek posted a link to earlier?

Crystal Reports .NET C++ - View Report

I just ran the Viewer one and it works fine, I did have to update the path to the references though:

#using <C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet\CrystalDecisions.Shared.dll>

The hotline is Sales to purchase a single case. but since this does work on my PC it's not a bug...

Don

Former Member
0 Kudos

Thanks for all the input.

I guess you started it as a standalone exe?

When I run it as a standalone it works fine here, too.

The problem only appears when I open it from our main program, which communicates with it over a over a C++/CLI bridge.

Can you please tell me what to do to get technical support?

Pay for it would be no problem.

I haven't found any infos on the Home | SAP Support Portal

about Crystal Reports for Visual Studio. Is it not possible to get direct support here?

0 Kudos

Hi Thomas,

Select Crystal Reports for the purchase is good. Mention to the Sales person to set the Component to BI-DEV-NET.

So is your dll COM, we don't support COM to .NET, there are known issues when passing COM objects to .NET and trying to keep them in scope. Nothing we can do about that, it's the nature of the beasts....

Can you explain the work flow of your main app? How are the report objects passed and what does it do?

Don

Former Member
0 Kudos

Hi Don,

thanks for the answer.

The COM comunication between c++ and the .net assembly is pretty basic.

There is call for initialize and one for showing the UI:

The only class which is passed to .Net is for getting needed paths.

All datasources are already generated before the call of the ReportViewer and this is done in c++.

The module should only be used for showing the reports with the already created datasources, so no values are moved over the com interface. The reports use odbc textdrivers to get the data from the datasources.

So the workflow is:

1: click on button for show reports (c++)

2. generate datasource file (c++)

3. call report viewer over com

4. show reports

So nearly all what is done over COM is calling the UI with the report.

Except for some passed paths everything is done directly in the module.

For clarification: Possible reports on the left. When the report is clicked a ReportDocument is created and shown in the CrystalReportViewer.

Can you tell if it is a general fact, that CrystalReport for .NET does not work over COM or should it work cases like this?

And is this planned to be fixed in the next time?

0 Kudos

This is the issue:

2. generate datasource file (c++)

3. call report viewer over com

So nearly all what is done over COM is calling the UI with the report.

All of the connection info and other properties are set in your C++ app. Passing that object through COM interOpt is being lost.

Export the report to RPT format and then open the saved report in the viewer, it will have saved data.

See if that works for you.

Nothing to fix, we don't support passing objects around multiple hops.... Never has and never will be supported. Others have tried and sometimes it works and sometimes not....

Don