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"?>