Click here to Skip to main content
13,407,023 members (54,814 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Everyone!

I'm trying to include ReportViewer.WinForms.dll for using in my system.

The system supports only a short number of supported namespaces, and reflection in my case is the only way.

I've loaded dll and created report instances:
System.Reflection.Assembly myDllAssembly =System.Reflection.Assembly.LoadFile(@"c:\docs\Microsoft.ReportViewer.WinForms.dll");
            System.Reflection.Assembly CommonAssembly = System.Reflection.Assembly.LoadFile(@"c:\docs\Microsoft.ReportViewer.Common.dll");
            var MyRDSInstance = myDllAssembly.CreateInstance("Microsoft.Reporting.WinForms.ReportDataSource");
            System.Reflection.PropertyInfo rdsName = MyRDSInstance.GetType().GetProperty("Name");
            System.Reflection.PropertyInfo rdsValue = MyRDSInstance.GetType().GetProperty("Value");
            rdsName.SetValue(MyRDSInstance, "DataSet1_DataTable1", null);
            rdsValue.SetValue(MyRDSInstance, ds.Tables[0], null);
            var MyRWInstance = myDllAssembly.CreateInstance("Microsoft.Reporting.WinForms.ReportViewer");
            var MyLRInstance = myDllAssembly.CreateInstance("Microsoft.Reporting.WinForms.LocalReport");
            System.Reflection.PropertyInfo ReRProperty = MyLRInstance.GetType().GetProperty("ReportEmbeddedResource");
            ReRProperty.SetValue(MyLRInstance, "Reflecting.test.rdlc", null);
            var lrDataSources = MyLRInstance.GetType().GetProperty("DataSources");

Here i get in stuck, the method Add() for adding the reportdatasource to datasource property is in the base class, in all BindingFlag values GetMethod() returns null, i supposed that it's a member, and that returned me the member wrap, but how i can add item working with member?

var mem = MyLRInstance.GetType().GetMember("Add", BindingFlags.FlattenHierarchy | BindingFlags.NonPublic);
 var meth = MyLRInstance.GetType().GetMethod("Add", BindingFlags.FlattenHierarchy | BindingFlags.NonPublic);
//meth.Invoke(MyRWInstance, new object[] { MyRDSInstance });

Can someone give an advice that i'm wrong at my thoughts and there exists more trivial solution? The main goal is to load rw dll and generate report data in backward, and after that depict and transform.

Thanks in advance.
Posted 25-Jul-12 7:40am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02-2016 | 2.8.180212.1 | Last Updated 25 Jul 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100