I'm using late binding to automate to Outlook and I'm getting an
ArgumentException when I create a delegate. The arguments I pass seem valid.
This is my code: -
Type oType = Type.GetTypeFromProgID("Outlook.Application");
-
oApp = Activator.CreateInstance(oType);
-
-
oInspectors = oApp.GetType().GetProperty("Inspectors").GetValue(oApp, null);
-
-
e_NewInspector = oInspectors.GetType().GetEvent("NewInspector");
-
d_NewEventDelegate = Delegate.CreateDelegate(e_NewInspector.EventHandlerType,
-
this, "Inspectors_NewInspector");
-
The class that is supposed to handle the event is defined as follows: -
private void Inspectors_NewInspector(object insp){ .... }
-
What am I doing wrong? 7 5969
Max,
When you look at the type for the event handler for NewInspector in
reflector, what is the signature.
Also, you don't really specify the details of the ArgumentException.
Those would be helpful.
I've noticed you are doing a lot of late binding to Outlook. Is there a
reason you aren't using the Primary Interop Assemblies, or even using VB to
handle the late binding (it's MUCH easier in VB).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.com> wrote in message
news:uw****************@TK2MSFTNGP14.phx.gbl... I'm using late binding to automate to Outlook and I'm getting an ArgumentException when I create a delegate. The arguments I pass seem valid. This is my code:
- Type oType = Type.GetTypeFromProgID("Outlook.Application");
- oApp = Activator.CreateInstance(oType);
- oInspectors = oApp.GetType().GetProperty("Inspectors").GetValue(oApp,
- null);
- e_NewInspector = oInspectors.GetType().GetEvent("NewInspector");
- d_NewEventDelegate =
- Delegate.CreateDelegate(e_NewInspector.EventHandlerType, this,
- "Inspectors_NewInspector");
-
The class that is supposed to handle the event is defined as follows:
- private void Inspectors_NewInspector(object insp){ .... }
-
What am I doing wrong?
Hi Nicholas,
Thank you for your help. The exception I'm getting for CreateDelegate says:
System.ArgumentException: Error binding to target method.
at System.Delegate.InternalCreate(Object target, String method, Boolean ignoreCase)
at System.Delegate.CreateDelegate(Type type, Object target, String method)
Obviously it means "this" is not the way to go but "Inspectors_NewInspector" is defined in the
class that calls all the late binding code.
The debugger says that:
e_NewInspector has EventHandlerType with BaseType as {"System.MulticastDelegate"}
While the signature with early binding for the handler is like this:
InspectorsEvents_NewInspectorEventHandler(void(Mic rosoft.Office.Interop.Outlook.Inspector)target)
OR
InspectorsEvents_NewInspectorEventHandler(object param, System.UIntPtr param)
The software I'm working on runs on a server which is on 24/7 and to which units in the field
equipped with modems connect to and upload their data. The data is stored in a database and
displayed to the user. I need an option that will generate a service call in the sense that it
will launch either of: MS Outlook 2000, 2002, 2003 or Outlook Express and create an email and fill
the body with some HTML text (I use HTML for indentation purposes). I could use the 2003 PIA but
that won't cover MS Outlook 2000 hence I use late binding. I could use VB but I don't have too
much experiece with it so I work in C# :)
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:uH**************@TK2MSFTNGP14.phx.gbl... Max,
When you look at the type for the event handler for NewInspector in reflector, what is the signature.
Also, you don't really specify the details of the ArgumentException. Those would be helpful.
I've noticed you are doing a lot of late binding to Outlook. Is there a reason you aren't using the Primary Interop Assemblies, or even using VB to handle the late binding (it's MUCH easier in VB).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.com> wrote in message news:uw****************@TK2MSFTNGP14.phx.gbl... I'm using late binding to automate to Outlook and I'm getting an ArgumentException when I create a delegate. The arguments I pass seem valid. This is my code:
- Type oType = Type.GetTypeFromProgID("Outlook.Application");
- oApp = Activator.CreateInstance(oType);
- oInspectors = oApp.GetType().GetProperty("Inspectors").GetValue(oApp,
- null);
- e_NewInspector = oInspectors.GetType().GetEvent("NewInspector");
- d_NewEventDelegate =
- Delegate.CreateDelegate(e_NewInspector.EventHandlerType, this,
- "Inspectors_NewInspector");
-
The class that is supposed to handle the event is defined as follows:
- private void Inspectors_NewInspector(object insp){ .... }
-
What am I doing wrong?
I could be wrong, but It looks like you are running this on a system that
has the PIA's installed in the GAC, where do you think reflection and the
debugger gets this "Microsoft.Office.Interop.Outlook.Inspector" from?
Watch the loaded assemblies in the debugger, bet you'll see that
"Microsoft.Office.Interop.Outlook.dll" is loaded from the GAC, your program
will probably fail when run on a system that won't have the outlook PIA
installed.
Willy.
"Max" <ma******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Hi Nicholas,
Thank you for your help. The exception I'm getting for CreateDelegate says:
System.ArgumentException: Error binding to target method. at System.Delegate.InternalCreate(Object target, String method, Boolean ignoreCase) at System.Delegate.CreateDelegate(Type type, Object target, String method)
Obviously it means "this" is not the way to go but "Inspectors_NewInspector" is defined in the class that calls all the late binding code.
The debugger says that: e_NewInspector has EventHandlerType with BaseType as {"System.MulticastDelegate"}
While the signature with early binding for the handler is like this:
InspectorsEvents_NewInspectorEventHandler(void(Mic rosoft.Office.Interop.Outlook.Inspector)target) OR InspectorsEvents_NewInspectorEventHandler(object param, System.UIntPtr param)
The software I'm working on runs on a server which is on 24/7 and to which units in the field equipped with modems connect to and upload their data. The data is stored in a database and displayed to the user. I need an option that will generate a service call in the sense that it will launch either of: MS Outlook 2000, 2002, 2003 or Outlook Express and create an email and fill the body with some HTML text (I use HTML for indentation purposes). I could use the 2003 PIA but that won't cover MS Outlook 2000 hence I use late binding. I could use VB but I don't have too much experiece with it so I work in C# :)
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:uH**************@TK2MSFTNGP14.phx.gbl... Max,
When you look at the type for the event handler for NewInspector in reflector, what is the signature.
Also, you don't really specify the details of the ArgumentException. Those would be helpful.
I've noticed you are doing a lot of late binding to Outlook. Is there a reason you aren't using the Primary Interop Assemblies, or even using VB to handle the late binding (it's MUCH easier in VB).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.com> wrote in message news:uw****************@TK2MSFTNGP14.phx.gbl... I'm using late binding to automate to Outlook and I'm getting an ArgumentException when I create a delegate. The arguments I pass seem valid. This is my code:
- Type oType = Type.GetTypeFromProgID("Outlook.Application");
- oApp = Activator.CreateInstance(oType);
- oInspectors = oApp.GetType().GetProperty("Inspectors").GetValue(oApp,
- null);
- e_NewInspector = oInspectors.GetType().GetEvent("NewInspector");
- d_NewEventDelegate =
- Delegate.CreateDelegate(e_NewInspector.EventHandlerType, this,
- "Inspectors_NewInspector");
-
The class that is supposed to handle the event is defined as follows:
- private void Inspectors_NewInspector(object insp){ .... }
-
What am I doing wrong?
That is correct. I am working on two solutions at the same time: one using early binding
and one using late binding. I installed the PIA's in the GAC and the setup project ships
with the dlls needed by the application for early binding. Am I doing this wrong?
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message news:eS****************@TK2MSFTNGP14.phx.gbl... I could be wrong, but It looks like you are running this on a system that has the PIA's installed in the GAC, where do you think reflection and the debugger gets this "Microsoft.Office.Interop.Outlook.Inspector" from? Watch the loaded assemblies in the debugger, bet you'll see that "Microsoft.Office.Interop.Outlook.dll" is loaded from the GAC, your program will probably fail when run on a system that won't have the outlook PIA installed.
Willy.
"Max" <ma******@yahoo.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... Hi Nicholas,
Thank you for your help. The exception I'm getting for CreateDelegate says:
System.ArgumentException: Error binding to target method. at System.Delegate.InternalCreate(Object target, String method, Boolean ignoreCase) at System.Delegate.CreateDelegate(Type type, Object target, String method)
Obviously it means "this" is not the way to go but "Inspectors_NewInspector" is defined in the class that calls all the late binding code.
The debugger says that: e_NewInspector has EventHandlerType with BaseType as {"System.MulticastDelegate"}
While the signature with early binding for the handler is like this:
InspectorsEvents_NewInspectorEventHandler(void(Mic rosoft.Office.Interop.Outlook.Inspector)target) OR InspectorsEvents_NewInspectorEventHandler(object param, System.UIntPtr param)
The software I'm working on runs on a server which is on 24/7 and to which units in the field equipped with modems connect to and upload their data. The data is stored in a database and displayed to the user. I need an option that will generate a service call in the sense that it will launch either of: MS Outlook 2000, 2002, 2003 or Outlook Express and create an email and fill the body with some HTML text (I use HTML for indentation purposes). I could use the 2003 PIA but that won't cover MS Outlook 2000 hence I use late binding. I could use VB but I don't have too much experiece with it so I work in C# :)
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:uH**************@TK2MSFTNGP14.phx.gbl... Max,
When you look at the type for the event handler for NewInspector in reflector, what is the signature.
Also, you don't really specify the details of the ArgumentException. Those would be helpful.
I've noticed you are doing a lot of late binding to Outlook. Is there a reason you aren't using the Primary Interop Assemblies, or even using VB to handle the late binding (it's MUCH easier in VB).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.com> wrote in message news:uw****************@TK2MSFTNGP14.phx.gbl... I'm using late binding to automate to Outlook and I'm getting an ArgumentException when I create a delegate. The arguments I pass seem valid. This is my code:
- Type oType = Type.GetTypeFromProgID("Outlook.Application");
- oApp = Activator.CreateInstance(oType);
- oInspectors = oApp.GetType().GetProperty("Inspectors").GetValue(oApp,
- null);
- e_NewInspector = oInspectors.GetType().GetEvent("NewInspector");
- d_NewEventDelegate =
- Delegate.CreateDelegate(e_NewInspector.EventHandlerType, this,
- "Inspectors_NewInspector");
-
The class that is supposed to handle the event is defined as follows:
- private void Inspectors_NewInspector(object insp){ .... }
-
What am I doing wrong?
As I said, you think you are using "late binding", but you are using
reflection to retrieve the CLR type information in order to bind
dynamically, this is not exactly the same thing as using COM late binding.
That means that this...
Type.GetProperty("Inspectors").GetValue(oApp, null);
uses the IA metadata to get the Property "Inpectors", it's obvious that this
will fail if there is no IA.
That means that you rely on the correct IA to be available when deploying,
right?. Question is who's going to install this IA, and who is going to
install a new version of the IA when the enduser install a new version of
outlook?
As I said before, what you need is real COM late binding (using the Outlook
Typelib), and this is realy hard to do in .NET, and it makes little sense as
you have better options.
What you can do for instance is build an assembly per outlook version you
want to target (using early binding), after you've checked the outlook
version installed you dynamically load the versioned assembly, all you need
to do is distribute the IA's and the versioned assemblies with your
application.
Another option is to build a simple SMTP mail client, so you don't need to
rely on outlook automation at all, I guess you don't need that fancy stuff
anyway, so it should trivial to do.
Willy.
"Max" <ma******@yahoo.com> wrote in message
news:u9**************@TK2MSFTNGP12.phx.gbl... That is correct. I am working on two solutions at the same time: one using early binding and one using late binding. I installed the PIA's in the GAC and the setup project ships with the dlls needed by the application for early binding. Am I doing this wrong? "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message news:eS****************@TK2MSFTNGP14.phx.gbl...I could be wrong, but It looks like you are running this on a system that has the PIA's installed in the GAC, where do you think reflection and the debugger gets this "Microsoft.Office.Interop.Outlook.Inspector" from? Watch the loaded assemblies in the debugger, bet you'll see that "Microsoft.Office.Interop.Outlook.dll" is loaded from the GAC, your program will probably fail when run on a system that won't have the outlook PIA installed.
Willy.
"Max" <ma******@yahoo.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... Hi Nicholas,
Thank you for your help. The exception I'm getting for CreateDelegate says:
System.ArgumentException: Error binding to target method. at System.Delegate.InternalCreate(Object target, String method, Boolean ignoreCase) at System.Delegate.CreateDelegate(Type type, Object target, String method)
Obviously it means "this" is not the way to go but "Inspectors_NewInspector" is defined in the class that calls all the late binding code.
The debugger says that: e_NewInspector has EventHandlerType with BaseType as {"System.MulticastDelegate"}
While the signature with early binding for the handler is like this:
InspectorsEvents_NewInspectorEventHandler(void(Mic rosoft.Office.Interop.Outlook.Inspector)target) OR InspectorsEvents_NewInspectorEventHandler(object param, System.UIntPtr param)
The software I'm working on runs on a server which is on 24/7 and to which units in the field equipped with modems connect to and upload their data. The data is stored in a database and displayed to the user. I need an option that will generate a service call in the sense that it will launch either of: MS Outlook 2000, 2002, 2003 or Outlook Express and create an email and fill the body with some HTML text (I use HTML for indentation purposes). I could use the 2003 PIA but that won't cover MS Outlook 2000 hence I use late binding. I could use VB but I don't have too much experiece with it so I work in C# :)
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:uH**************@TK2MSFTNGP14.phx.gbl... Max,
When you look at the type for the event handler for NewInspector in reflector, what is the signature.
Also, you don't really specify the details of the ArgumentException. Those would be helpful.
I've noticed you are doing a lot of late binding to Outlook. Is there a reason you aren't using the Primary Interop Assemblies, or even using VB to handle the late binding (it's MUCH easier in VB).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.com> wrote in message news:uw****************@TK2MSFTNGP14.phx.gbl... > I'm using late binding to automate to Outlook and I'm getting an > ArgumentException when I create a delegate. The arguments I pass seem > valid. > This is my code: > > - > Type oType = Type.GetTypeFromProgID("Outlook.Application");
- > oApp = Activator.CreateInstance(oType);
- >
- > oInspectors = oApp.GetType().GetProperty("Inspectors").GetValue(oApp,
- > null);
- >
- > e_NewInspector = oInspectors.GetType().GetEvent("NewInspector");
- > d_NewEventDelegate =
- > Delegate.CreateDelegate(e_NewInspector.EventHandlerType, this,
- > "Inspectors_NewInspector");
- >
> > The class that is supposed to handle the event is defined as follows: > > - > private void Inspectors_NewInspector(object insp){ .... }
- >
> > What am I doing wrong?
> What you can do for instance is build an assembly per outlook version you want to target (using early binding), after you've checked the outlook version installed you dynamically load the versioned assembly, all you need to do is distribute the IA's and the versioned assemblies with your application.
I'm kind of new to this, as you might have realized already....
So you are saying to use the tlbimp.exe utility to create my own IAs for MS Outlook 2000, 2002, 2003
then make 3 separate dlls each one using early binding to do the work for each of the
MS Outlook versions 2000, 2002, 2003 resp. Then at run time based on the user selection to load the
correct assembly and call the right functions inside.... right?
Thanks,
Max
"Max" <ma******@yahoo.com> wrote in message
news:e8**************@TK2MSFTNGP15.phx.gbl... What you can do for instance is build an assembly per outlook version you want to target (using early binding), after you've checked the outlook version installed you dynamically load the versioned assembly, all you need to do is distribute the IA's and the versioned assemblies with your application.
I'm kind of new to this, as you might have realized already....
So you are saying to use the tlbimp.exe utility to create my own IAs for MS Outlook 2000, 2002, 2003 then make 3 separate dlls each one using early binding to do the work for each of the MS Outlook versions 2000, 2002, 2003 resp. Then at run time based on the user selection to load the correct assembly and call the right functions inside.... right?
Thanks, Max
No, it's not up to the user to decide which assembly to load, it's your
program code that checks the version by creating an instance of the outlook
server, something like this...
string progId = "Outlook.Application";
Type type1 = Type.GetTypeFromProgID(progId);
object outl = Activator.CreateInstance(type1);
// Get installed version of outlook, note that this call might load
the IA from the GAC when present.
object version = outl.GetType().InvokeMember("Version",
BindingFlags.GetProperty , null, outl, null);
// verions should hold a string that looks like "10.0.xxx or
11.0.0.xxxx etc..
// depending on the version you should load your versioned assembly
if(version = 11)
Assembly.Load("V11Assembly, Version=..., Culture=...")
if(version= 10)
...
Willy. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Max |
last post by:
Hello,
I'm using late binding to automate to multiple versions of MS Outlook and I'm getting an ArgumentException when I create a delegate.
System.ArgumentException: Error binding to target...
|
by: deko |
last post by:
I use this convention frequently:
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
|
by: Nivek Eroom |
last post by:
Can anyone tells me how can i add a delegate to an object remotly created as
this :
object patate =
Activator.GetObject(tt,"http://localhost:8080/DynamicTemplateServer.soap");
...
|
by: redhotsly |
last post by:
Hi,
Is is possible to create an event handler method that can handle any
type of event no matter what the delegate signature is.
Here is the code I have so far:
public class class1
{...
|
by: p |
last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also
have Crystal 9 pro on my development machine. The web app runs fine on my
dev machine but am having problems deploying....
|
by: snibril |
last post by:
Hi,
I'm trying to delegate all events of a command button to a single
method, handlesAll. I wrote the following code in VS.NET 2005, and it
worked fine:
public void setUpDelegates()
{
...
|
by: tesvit |
last post by:
Hi there,
I am working on a class library that should incpect a given class,
make a delegate to a get Property and use it later on.
Here is the code snippet:
public delegate int...
|
by: Klaudiusz Bryja |
last post by:
Hi,
I need Delegate.CreateDelegate method equivalent in compact
framework.
Best regards,
Klaudiusz
|
by: Michael C |
last post by:
If we have something like this
object x = null;
MessageBox.Show(x.ToString())
we get an error. That kindof makes sense but there is no reason the
behaviour couldn't be to return an empty...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |