Click here to Skip to main content
11,805,035 members (65,855 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# reflection
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 6:40am

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

  Print Answers RSS
0 OriginalGriff 305
1 Sergey Alexandrovich Kryukov 268
2 CPallini 210
3 Richard Deeming 190
4 CHill60 150
0 OriginalGriff 3,255
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 25 Jul 2012
Copyright © CodeProject, 1999-2015
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