c# – casting delegate using errorbox returns fault – Education Career Blog

Im completely stumped on where to go from here.

heres my line of code that i cant get past.

  if (error.GetReaction(ErrorReaction.InformUser) == null)
                    error.SetReaction(new ErrorReactionClass(ErrorReaction.InformUser, (CachedAnonymousMethodDelegate1 != null) ? CachedAnonymousMethodDelegate1 : (CachedAnonymousMethodDelegate1 = new Method(ErrorMessageBox.ShowDialog)), "OK", ""));

i get the following errors from this

Error 30 ‘System.Windows.Forms.DialogResult System.Windows.Forms.Form.ShowDialog()’ has the wrong return type
Error 31 An object reference is required for the non-static field, method, or property ‘System.Windows.Forms.Form.ShowDialog()’


There are two errors here.

  1. The call to ShowDialog doesn’t have the return type your delegate is expecting.
  2. You can’t call “ShowDialog” on a type, since it’s not a static method. You need to provide an actual instance.

I suspect that this may do what you need:

// Not sure how many arguments your "Method" delegate gets
Method showDialog = (arg1, arg2) =>
     var form = new ErrorMessageBox();
     // Setup form with arg1/arg2/etc

     // return appropriate return type here...

    new ErrorReactionClass(
        (CachedAnonymousMethodDelegate1 != null) 
            ? CachedAnonymousMethodDelegate1 
            : (CachedAnonymousMethodDelegate1 = showDialog)
        , "OK", ""));

Leave a Comment