Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7071709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:43:14+00:00 2026-05-28T05:43:14+00:00

I’m not sure if I should ask this here but here we go, while

  • 0

I’m not sure if I should ask this here but here we go, while unit testing a private static method that has as parameter a short I’m getting a MissingMethodException only when this parameter is 0.

I’m using VS 2010 SP1 targeting the Framework 4 (full), here is the bare minimum code to reproduce this error (we are upgrading a VB6 code so don’t be rude):

    [DataContract]
  public enum NotificationResult
  {
    [EnumMember]
    Success,
    [EnumMember]
    StoredError,
    [EnumMember]
    InvalidId,
    [EnumMember]
    OperationError,
  }

    public sealed class NotificationContext
  {
    private static NotificationResult GetExecuteResult(short result)
    {
      NotificationResult executeResult;
      switch (result)
      {
        case 0:
          executeResult = NotificationResult.Success;
          break;
        case 1:
          executeResult = NotificationResult.StoredError;
          break;
        case 2:
          executeResult = NotificationResult.InvalidId;
          break;
        default:
          executeResult = NotificationResult.OperationError;
          break;
      }

      return executeResult;
    }
  }

Here is how I’m testing the code:

 PrivateType privateHelperType = new PrivateType(typeof(NotificationContext));
      var actual = (NotificationResult)privateHelperType.InvokeStatic(
        "GetExecuteResult", (short)1);
      var actual2 = (NotificationResult)privateHelperType.InvokeStatic(
        "GetExecuteResult", (short)0); //here is where i get the exception

In the first invocation i get the expected result, in the second invocation I get the exception (I added the cast to short thinking that maybe the exception was because it was not finding a method with an int as a parameter).

Is anybody able to reproduce the behavior?, am I doing something wrong?

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:43:15+00:00Added an answer on May 28, 2026 at 5:43 am

    The problem is that there are two overloads of this method (there are others, but they don’t matter here):

    • public Object InvokeStatic(string name, params Object[] args)
    • public Object InvokeStatic(string name, BindingFlags invokeAttr, params Object[] args)

    The difference is that the second overload has a parameter of type BindingFlags, which is an enum. And when you pass literal 0 as the second parameter, this overload is chosen, because the literal 0 is implicitly convertible to any enum and not using params is deemed better than using it in overload resolution. So, basically

    • privateType.InvokeStatic("GetExecuteResult", 1) is compiled into privateType.InvokeStatic("GetExecuteResult", new object[] { 1 })
    • privateType.InvokeStatic("GetExecuteResult", 0) is compiled into privateType.InvokeStatic("GetExecuteResult", 0, new object[] { })

    This is the cause of your problem. I think the cleanest way to avoid it would be to create the array explicitly:

    privateType.InvokeStatic("GetExecuteResult", new object[] { 0 })
    

    Except in your code you don’t pass the literal 0 to the method, you cast it first. According to the specification, the BindingFlags overload should not be chosen in this case. But errors like this are a known bug, that won’t be fixed, because it would break some working programs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.