Skip to main content Skip to footer

Using CustomFields in WPF Report Applications

When the report definition files using Custom Fields (like Charts) is used in C1WpfReport, the following exception is observed: InvalidCastException (Failed to create custom field 'C1.C1Report.CustomFields.Chart' from assembly 'c1.c1report.customfields.4') This issue is observed as the CustomFields dll and the report definition file is generated with a specific version of C1WpfReport. This blog is to help you to resolve the error. Here are few specific steps that you need to take to make this work. Let me elaborate them in detail.

Step 1 : Regenerate C1.WPF.C1Report.CustomFields.dll

Open the WPF CustomFields sample in "....Documents\ComponentOne Samples\Studio for WPF\C1.WPF.Report\CS\CustomFields". This sample is built on .NET framework 3.0, so change its Target framework to 4.0. After this remove all the C1 references from the project. Also, remove the PresentatioCore.dll and add PresentationCore.dll compatible with .NET framework 4.0. You would find that under.NET tab in the "Add References.." window. Add following .NET framework 4.0 compatible C1 dll's available in "C:\Program Files\ComponentOne\Studio for WPF\C1WPFReport\Designer.4" folder :

  • C1.C1Report.4.Design
  • C1.C1Report.CustomFields.4
  • C1.Win.C1Chart.4
  • C1.WPF.C1Report.4

Modify the licenses file and replace the contents with the following line : C1.C1Report.C1Report, C1.WPF.C1Report.4 Rebuild this sample in order to generate C1.WPF.C1Report.CustomFields.dll. Now add the generated dll to your project.

Step 2 : Add references to your application

Open your application and add reference to the following dlls in your project :

  • C1.WPF.C1Report.4.dll (from "C:\Program Files\ComponentOne\Studio for WPF\bin\v4" folder")
  • C1.WPF.C1Report.CustomFields.dll (created in Step 1)
  • C1.Win.C1Chart.4.dll (from "C:\Program Files\ComponentOne\Studio for WPF\C1WPFReport\Designer.4" folder)

Step 3 : Modify report definition file

The xml report definitions that you are loading on the should be created with the same designer version. If not, you can change edit the xml definition. Generally,xml report definitions start with following text:- <?xml version="1.0"?> <!--Report * Products Report *--> THIS VERSION SHOULD BE SAME AS THE VERSION OF C1REPORT DLL IN YOUR PROJECT . . . .. You also need to edit the xml report definition with the assembly to be used in rendering the custom fields. So if you open up any report definition, you would notice following text in field definition:- chartField

5
540 180 6660 4680 1 THIS SHOULD BE EDITED AND REPLACED WITH WPF CUSTOMFIELDS REFERENCE.. ProductName [Unit Price];[Reorder Level] 8388608 So, the modified xml text would be:- chartField
5
540 180 6660 4680 1 ProductName [Unit Price];[Reorder Level] 8388608
Now you can load the report definition files in your WPF application without any problem. I am attaching a sample implementing the above steps with C1WpfReport build 4.6.20112.54408. Download Sample

MESCIUS inc.

comments powered by Disqus