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

  • Home
  • SEARCH
  • 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 563377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:39:14+00:00 2026-05-13T12:39:14+00:00

I’ve noticed some seemingly weird issues in Visual Studio 2008 (.NET 3.5) and also

  • 0

I’ve noticed some seemingly weird issues in Visual Studio 2008 (.NET 3.5) and also in Visual Studio 2010 Beta 2 (.NET 4.0). These issues may have existed in prior versions as well. Maybe they are not an issue, but either way, I would like to see if there is are logical explanations for these before I submit a report on Microsoft Connect.

The Setup (in VB, C# results differ and are included later in the post):

Public Class SomeClass
    Public Property SomeProperty() As String
        Get
            Return String.Empty
        End Get
        Set(ByVal value As String)
        End Set
    End Property
End Class

Public Class SomeOtherClass
    Public Sub New()
        Dim sc As New SomeClass()
        Me.SomeFunction(sc.SomeProperty)
    End Sub

    ''' <summary>The param as Object fn()</summary> '''
    Public Sub SomeFunction(ByVal param As Object)
    End Sub

    ''' <summary>The param as T fn()</summary> '''
    Public Sub SomeFunction(Of T)(ByRef param As T)
    End Sub
End Class

In this sutation, the Me.SomeFunction(sc.SomeProperty) call, from the point of view of IntelliSense, looks like this:
alt text
and, not surprisingly, this is also what is called at runtime.

So, I guess the first question I have is, why was the ByRef templated overload version of the function chosen over the ByVal Object overload version of the function? My guess is that the compiler and IntelliSense simply favor the templated versions over non-templated versions. At runtime, it is in fact the ByRef templated version of the function that is called. (This is not the defect, this is simply a personal want-to-know question.)

Now, make a slight change to the SomeProperty property such that the setter is now private:

Public Property SomeProperty() As String
    Get
        Return String.Empty
    End Get
    Private Set(ByVal value As String)
    End Set
End Property

As soon as you do this, the following happens to the Me.SomeFunction(sc.SomeProperty) line:
alt text

In this case, IntelliSense is suggesting that the ByVal Object overload version of the function is being called, however the error message is the 'Set' accessor of property 'SomeProperty' is not accessible indicating that the compiler is still expecting to call the ByRef templated version. So, this is my second question. Why is Intellisense claiming one thing while the VB compiler is clearly trying something else? This seems broken to me. Or am I missing something?

If instead of having a private setter on SomeProperty but instead the property was simply marked ReadOnly and the setter part removed, then the ByRef templated version of the function is shown in IntelliSense and is called at runtime (with no runtime errors). So this leads me to my third question, why is the VB compiler treating the input to ByRef params different for properties that are ReadOnly vs not-ReadOnly, but have an out-of-scope setter in VB As far as SomeFunction(Of T)(…) is concerned, in its current scope, that property should be as if it were ReadOnly and I would expect it to be callable just as if the property was in fact ReadOnly. But instead it produces a build error.

In correlation with question three, doing the exact same setup (with the Private setter), C# has the result I was expecting.
alt text
Here, you can see IntelliSense is claiming that the SomeFunction(Object) overload of the function is being called and there is no build error. At runtime the SomeFunction(Object) version is in fact called. So, why isn’t the same SomeFunction(Object) version being called in the VB.NET situation? Why does VB.NET still think the SomeFunction(Of T)(ByRef T) version need to be called? It looks like IntelliSense is nailing it correctly in both C# and VB.NET, the C# compiler is doing the right thing, but the VB.NET compiler is still convinced that it should be calling the ByRef templated version. To me it seems that the C# compiler is picking one overload, while the VB.NET compiler is picking a different overload, in the exact same situation. Am I wrong?

  • 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-13T12:39:14+00:00Added an answer on May 13, 2026 at 12:39 pm

    Regarding your third question:

    Why is the VB compiler treating the input to ByRef params different for properties that are ReadOnly vs not-ReadOnly, but have an out-of-scope setter in VB

    In CLR, it is not possible to pass a property as a ByRef. The VB.NET team, however, decided that this would be useful and implemented a workaround. Internally,

    Me.SomeFunction(sc.SomeProperty)
    

    is converted into either

    Dim vbTemp = sc.SomeProperty
    Me.SomeFunction(vbTemp)
    

    which is called Don’t Copy Back ByRef and used, e.g., for Read-Only properies, or

    Dim vbTemp = sc.SomeProperty
    Me.SomeFunction(vbTemp)
    sc.SomeProperty = vbTemp
    

    which is called Copy Back ByRef and used for properties containing both a getter and setter. All these things (and a few more complicated cases) are explained in jaredpar’s WebLog: The many cases of ByRef.

    Now, you are saying that when the setter is out of scope, a Don’t Copy Back ByRef should be performed. However, that would lead to inconsistent behavior: SomeFunction(sc.SomeProperty) would update sc.SomeProperty when called inside of SomeClass, but the same line of code would silently not update the property when called outside (because the setter is out of scope).


    About your first and second question:

    Why was the ByRef templated overload version of the function chosen over the ByVal Object overload version of the function? My guess is that the compiler and IntelliSense simply favor the templated versions over non-templated versions.

    They favor the templated versions over a version that would require a widening cast to Object. Overload resolution is described in detail in Chapter 11.8.1 of the Visual Basic Language Specification.

    Why is Intellisense claiming one thing while the VB compiler is clearly trying something else?

    Looks like a bug to me.

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

Sidebar

Ask A Question

Stats

  • Questions 454k
  • Answers 454k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From the IBM RFT online help: You can use the… May 15, 2026 at 9:52 pm
  • Editorial Team
    Editorial Team added an answer Do you know the SA password for the database? Long… May 15, 2026 at 9:52 pm
  • Editorial Team
    Editorial Team added an answer By custom component, do you mean view? Those will be… May 15, 2026 at 9:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.