[v8i C#] Standards Checker ref parameters

...and here's yet another problem with my standards checker code.

I just wanted to use something like this:

var choice = MsdStandardsCheckerReplaceChoice.Skip;
var description = "Bla bla bla";

USTN.ComApp.StandardsCheckerController.ShowCheckerError(
  ref choice,
  description,
  MsdStandardsCheckerReplaceOptions.CanFix,
  false);

if (choice == ...) { ... }

Well, the dialog opens and if I click "Fix" then the method throws an AccessViolationException.
Maybe it has something to do with ref parameter...

Hm, does anyone have a working example for a standards checker implementation using C#.
Did anyone in this forum ever tried to implement that stuff via C#???

A little help would be really appreciated!

Regards
Stephan

  • Unknown said:
    USTN.ComApp.StandardsCheckerController.ShowCheckerError(
      ref choice,
      description,
      MsdStandardsCheckerReplaceOptions.CanFix,
      false);

    The VBA method has two additional optional parameters, IgnoredBy and IgnoredWhen.  There is no C# equivalent to VBA's optional parameters, so you must include them even if you don't use them.

    Unknown said:
    Maybe it has something to do with ref parameter

    VBA passes parameters implicitly ByRef, equivalent to C# ref.  With VBA you don't need the keyword, with C# you do need the keyword.  However, it's likely that some of those arguments are passed ByVal (even though the documentation doesn't say so).  I'm thinking of those enumerations MsdStandardsCheckerReplaceChoice and MsdStandardsCheckerReplaceOptions, which probably translate to Int32 values in C#.  You'll need to experiment.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Jon,

    thank you for your help!

    Oh, you mean that C#'s optional parameters don't work like VBA's optional parameters?

    If I "go to definition" (F12) in Visual Studio it shows me this signature:

    void ShowCheckerError(
      ref MsdStandardsCheckerReplaceChoice ReplacementChoice,
     
    string ProblemDescription,
      MsdStandardsCheckerReplaceOptions ReplaceOptions,
      bool CurrentlyIgnored,
      string IgnoredBy = null,
      DateTime IgnoredWhen = default(DateTime)
    );

    At least the definition created from metadata seems to like C# optionals, well, whatever. I HAVE tried your tips and used some values for the optional parameters. Unfortunately without any luck...