1

I am trying to use the RDORecipients.AddMultiple function to add a large number of recipients to a message.

RDOSession session = new RDOSession();
RDOMail mail = session.CreateMsgFromMsgFile("test.msg", "IPM.Note");
List<string> recipientsList = {"test1@test.com", "test2@test.com"};
Array recipients = recipientsList.ToArray();
rdoMail.Recipients.AddMultiple(ref recipients, 1);

An exception SafeArrayTypeMismatchException (specified array was not of expected type) is being thrown on the last line. I have tried creating the array in different ways with both new and Array.CreateInstance(typeof(string), number of elements). I have a feeling I need to do something between the managed/unmanaged code but I am not sure how. Either that or the documentation/pinvoke signature is incorrect but that is not likely.

Doug
  • 149
  • 2
  • 11

3 Answers3

0

Try to declare recipients variable as string[].

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • I have. The code will not compile (the best overloaded method match has some invalid arguments). Casting the string[] to System.Array results in the same exception in the original question. – Doug Nov 24 '15 at 05:02
  • 1
    How about copying the values to an array of objects (object[])? – Dmitry Streblechenko Nov 24 '15 at 16:13
0

I noticed the signature for the Recipients.Add(object) method takes an object and not a string. I tried declaring as an object[] instead of a string[] before casting to System.Array and it worked.

Doug
  • 149
  • 2
  • 11
0

I found the solution is:

RDOSession session = new RDOSession();
RDOMail mail = session.CreateMessageFromMsgFile("test.msg", "IPM.Note");
List<string> recipientsList = new List<string>{ "test1@test.com", "test2@test.com" };
Array recipients = recipientsList.ToArray<object>();
mail.Recipients.AddMultiple(ref recipients, 1);

the Array must use object type, and does not exist null element, or it will throw exception in AddMultiple().