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 6376407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:44:28+00:00 2026-05-25T01:44:28+00:00

I have a class like this: class Foo private shared default_ = DEFAULT public

  • 0

I have a class like this:

class Foo
    private shared default_ = "DEFAULT"

    public shared function bar(val as object) as string
        if val is Nothing then return _default

        return getBar(val)
    end function

    private shared function getBar(val as string) as string
        return formatString(val)
    end function

    private shared function getBar(val as System.Int32) as string
        return formatInt(val)
    end function
end class

formatString and FormatInt being public shared methods.
When I call Foo.bar, I get a MissingMemberException:

System.MissingMemberException: Public member 'getBar' on type 'Foo' not found.

It works, when I make getBar methods public, but I don’t want to expose these unneccessarily. Why I can’t call private shared methods from a public one in the same class is over my head.

I’m using .net framework 4.0 in a web application.

  • 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-25T01:44:28+00:00Added an answer on May 25, 2026 at 1:44 am

    Your public method takes an object as parameter and your private methods are taking string/integer. So the runtime does not know which overloaded method it should use.

    If you make all overloaded methods public, the code only would compile if you have Option Strict Off. Then on runtime no exception migth be thrown because the actual type of the object will be detected via late-binding(or even silently casted to a matching type, f.e. from date to string). But nevertheless, avoid late binding with Option Strict On and use VB.NET as what it is supposed to be: a strong typed language.

    The Main-Reason why your code throws a MissingMemberException with Option Strict Off and private methods is:

    • If you are attempting to access members on a late-bound object variable, make sure it is declared Public(Protected , Friend, and Private variables cannot be late-bound in Visual Basic)

    You could check the type of val, cast the object to this type and then pass that parameter to the correct method. For example:

    Public Overloads Shared Function bar(ByVal val As Object) As String
          If val Is Nothing Then Return default_
    
          If TypeOf val Is String Then
              Return getBar(CStr(val))
          ElseIf TypeOf val Is Int32 Then
              Return getBar(CInt(val))
          Else
              Return default_
          End If
    End Function
    

    Another point: if you plan to create an Extension-Method that takes an object, forget it:

    Mainly, we do not allow extension methods to be called off of any
    expression that is statically typed as “Object”. This was necessary to prevent any > existing late bound code you may have written from being broken by extension methods

    • http://msdn.microsoft.com/en-us/library/bb384936.aspx (look for MissingMemberException)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class like this: private class MyClass { [DisplayName(Foo/Bar)] public string FooBar
If you have an object like this: public class Foo { private int _id;
I have a class like this public class foo { private void getThread() {
I have a class set up like this: class Foo { Foo(); private: Bar
I have a class that looks something like this: class Foo { private IEnumerable<Bar>
Let's say I have a model like this class Foo(db.Model): id = db.StringProperty() bar
I have two classes, Foo and Bar, that have constructors like this: class Foo
I have trouble when designing classes like this class C1 { public: void foo();
I have a class like this: class MyClass{ public: MyClass(int Mode); private: std::map <
Let say I have a class like this: public sealed class Foo { public

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.