Late binding with c#

G

Guest

I'm trying to write a c# command line app that runs report dll's at set
times. The dll's are written in c# with a common interface so by passing the
object name from the command line I can create ao instance ot the object &
create the report.

In VB I used code like:
Set obj = CreateObject(objName)
Call obj.Init(databaseName, fromDate, toDate)

I've tried the c# code:
System.Type oType = System.Type.GetTypeFromProgID("rptName.Init");
object obj = System.Activator.CreateInstance(oType);
oType.InvokeMember("createReport",
System.Reflection.BindingFlags.InvokeMethod, null,0, new object[]{})
obj.createReport(dbName,fromDate,toDate);

but so far not been able to get it to work.

I'm sure I'm just missing something silly but at present can't see it, Maybe
because it's Friday!!!

Any help/advise would be welcome.

Thanks,
John
 
G

Guest

objType.InvokeMember("Init", System.Reflection.BindingFlags.InvokeMethod,
null, obj, new object[] {databaseName, fromDate, toDate});

You were passing '0' instead of 'obj'.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter
Instant C++: VB to C++ converter
 
G

Guest

What I'm getting at present is the Type is not being created.
After the following line is executed the Type is still <undefined value>
System.Type oType = System.Type.GetTypeFromProgID("rptName.Init");

Documentation on GetTypeFromProgID states that it's for compatability with
COM objects & that it's superceded with namespaces in .NET. As the dll's are
written in c# do I have to use another method to late bind?

Thanks for the help,
John

David Anton said:
objType.InvokeMember("Init", System.Reflection.BindingFlags.InvokeMethod,
null, obj, new object[] {databaseName, fromDate, toDate});

You were passing '0' instead of 'obj'.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter
Instant C++: VB to C++ converter


John Clennett said:
I'm trying to write a c# command line app that runs report dll's at set
times. The dll's are written in c# with a common interface so by passing the
object name from the command line I can create ao instance ot the object &
create the report.

In VB I used code like:
Set obj = CreateObject(objName)
Call obj.Init(databaseName, fromDate, toDate)

I've tried the c# code:
System.Type oType = System.Type.GetTypeFromProgID("rptName.Init");
object obj = System.Activator.CreateInstance(oType);
oType.InvokeMember("createReport",
System.Reflection.BindingFlags.InvokeMethod, null,0, new object[]{})
obj.createReport(dbName,fromDate,toDate);

but so far not been able to get it to work.

I'm sure I'm just missing something silly but at present can't see it, Maybe
because it's Friday!!!

Any help/advise would be welcome.

Thanks,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top