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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:26:05+00:00 2026-05-30T21:26:05+00:00

Visual Studio seems to stop type checking function parameters when one of the parameters

  • 0

Visual Studio seems to stop type checking function parameters when one of the parameters is an interface.

Consider the following:

' An interface and the class that implements it:
Public Interface IA

End Interface

Public Class A
    Implements IA
End Class


' Another reference type for the demonstration:
Public Class MyReferenceType

End Class


' A function that uses IA as the type of one of its parameters:
Private Function SomeFunc(ByVal a As IA, ByVal r As MyReferenceType)
    Return Nothing
End Sub

And here is an example of the type checking problems:

Private Sub Example()
    Dim a As IA = New A
    Dim r As New MyReferenceType

    ' Some other random reference type, choose any 
    ' other reference type you like
    Dim list As New List(Of String)

    ' Each of these calls to SomeFunc compile without errors.
    SomeFunc(r, r)
    SomeFunc(r, a)
    SomeFunc(list, r)
    SomeFunc(list, a)

    ' Does not compile due to type mismatch
    'SomeFunc(list, list)
End Sub

As my comments suggest, this code compiles fine, with no errors in the editor either. If I execute the program though I get System.InvalidCastException, which isn’t a surprise at all. I guess this is a type checking bug in the compiler? I’m using Visual Studio 2005, so is this fixed in a later version of VS?

  • 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-30T21:26:06+00:00Added an answer on May 30, 2026 at 9:26 pm

    I believe it’s because you’ve got Option Strict off. If you turn Option Strict on to start with, your code fails to compile, exactly as we’d expect.

    Note that this:

    SomeFunc(list, a)
    

    is not like this:

    SomeFunc(list, list)
    

    In the first case, when Option Strict is off, the compiler is effectively inserting a cast for you. After all, a value of type IA can be a MyReferenceType.

    In the second case, a value of List(Of String) cannot ever be compatible with MyReferenceType (with the arguable exception of a value of Nothing…), so even with Option Strict off, compilation fails. The compiler won’t let you try something which can’t ever work.

    Moral of the story: for better type checking, turn Option Strict on.

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

Sidebar

Related Questions

In Visual Studio 2008, it seems that when I tab on a line it
I've got a weird issue that almost seems like a Visual Studio 2008 issue.
I'm trying to use visual studio 2010. But it seems that the .sln file
Is there a way to stop Visual Studio 2008 from checking whether css classes
I had no problem with this in Visual Studio 2008 but it seems that
In visual studio 2010, when publishing a website, it seems that empty folders are
I am using visual studio 2010. It seems that out of nowhere, I can't
Is it possible to enumerate all managed threads in C#? Visual Studio seems to
I just upgraded my operating system to Windows 7. Visual Studio 2008 also seems
Microsoft Visual Studio (2005 and 2008) seems to have fun shuffling the Project IDs

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.