0

I am trying to understand a late-binding issue i am having. I am trying to implememnt an out-of-process customsink as described here: https://msdn.microsoft.com/en-us/library/dn775003(v=pandp.20).aspx

I have created this test so you can quickly see my problem:

static void Main(string[] args)
        {

        object[] arg = new object[] {         
 "smtp.live.com"
,587
, "bill@adatum.com"
, "Simple Custom Email Sink"
, "etw"
    };
        try
        {
            var locationDir = @"C:\Git\slab\bin\Debug\";
            var assm = System.Reflection.Assembly.LoadFrom(locationDir + "MyElasticSearch.dll");

            var typ = assm.GetType("MyElasticSearch.EmailSink");
            var t = Activator.CreateInstance(typ, args);


        }
        catch (MissingMethodException e)
        {
            throw new ArgumentException("error", e);

        }

    }

This is the simple version, bellow is the elaboration

I am sending information to create an instance of my EMail Sink object this is the objectarray im sending :

    args=    {object[5]}
    [0]: "smtp.live.com"
    [1]: 587
    [2]: "bill@adatum.com"
    [3]: "Simple Custom Email Sink"
    [4]: "etw"

I am loading via this line:

  try
        {

            var type = "MyElasticSearch.EmailSink, MyElasticSearch";
            return (T)Activator.CreateInstance(Type.GetType(type, true), args);
        }
        catch (MissingMethodException e)
        {
           throw new ArgumentException(Properties.Resources.IncompleteArgumentsError, e);

        }

The Exception thrown is :

     System.MissingMethodException was caught
  HResult=-2146233069
  Message=Constructor on type 'MyElasticSearch.EmailSink' not found.
  Source=mscorlib
  StackTrace:
       at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
       at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       at System.Activator.CreateInstance(Type type, Object[] args)
       at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Etw.Utility.XmlUtil.CreateInstance[T](XElement element) in c:\Git\slab\source\Src\SemanticLogging\Utility\XmlUtil.cs:line 52
  InnerException: 

I looked, and the private Signature field is empty

This is my constructor signature

namespace MyElasticSearch 
 {
    public class EmailSink
    {
         //6 params
         public EmailSink(string host, int port,
              string recipients, string subject, string credentials,
              IEventTextFormatter formatter)
            {
              //do something
            }

           //5 params
           public EmailSink(string host, int port,
              string recipients, string subject, string credentials )
            {
              //do something else
            }
    }
 }

can someone help debug this mess please?

Mickey Perlstein
  • 2,508
  • 2
  • 30
  • 37
  • Your constructor is (string,int,string,string,string,IEventTextFormatter) - 6 parameters. You pass (string, int, string,string,string) - 5 parameters. – Evk Sep 17 '15 at 09:16
  • @Evk nope, it doesn't work with a new 5 param constructor either – Mickey Perlstein Sep 17 '15 at 14:18
  • 1
    Can you update post with your real constructor then? Your EmailSink constructor still lists 6 parameters in your question. – Evk Sep 17 '15 at 14:48

0 Answers0