Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#
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?

C#
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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900