Click here to Skip to main content
Rate this: bad
good
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 });
//mem.SetValue(MyRDSInstance,0);
 
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
0 OriginalGriff 277
1 Maciej Los 230
2 BillWoodruff 205
3 DamithSL 165
4 Sergey Alexandrovich Kryukov 155
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 25 Jul 2012
Copyright © CodeProject, 1999-2014
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