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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:09:03+00:00 2026-05-11T17:09:03+00:00

Why does constructor ORDER matter in VB.Net? I am building a .Net type library

  • 0

Why does constructor ORDER matter in VB.Net? I am building a .Net type library which is meant to wrap an underlying COM library completely so that the consumers of the API can pretend to use a nice .Net library with .Net collections and whatnot instead of a COM library.

Currently most of my classes are just 1 to 1 wrappers built using Reflection and CodeDOM. These classes have an internal constructor which takes the underlying COM type as a parameter. The CodeDOM builds this as the first constructor to the class. Using these classes from C# proves to be no problem. All I need is a reference to the .Net library and all works good.

The problems appear when I try using these classes from a VB.Net project. If the first constructor has a COM type as an argument, the VB.Net project requires the COM interop assembly as a reference. If the first constructor has no arguments or has only managed types all works good. My class library is written in C#.

The following works:

public class ObjectID
{
    public ObjectID(int type, int id)
    {
        this.Type = type;
        this.ID = id;
    }

    internal ObjectID(COMLib.ObjectID id) : this(id.Type, id.ID) { }

    public int ID { get; set; }
    public int Type { get; set; }

    internal COMLib.ObjectID ToCOM()
    {
        COMLib.ObjectID id = new COMLib.ObjectID();
        id.ID = this.ID;
        id.Type = this.Type;
        return id;
    }
}

The following requires a reference to the COMLib.Interop assembly:

public class ObjectID
{
    internal ObjectID(COMLib.ObjectID id) : this(id.Type, id.ID) { }

    public ObjectID(int type, int id)
    {
        this.Type = type;
        this.ID = id;
    }

    public int ID { get; set; }
    public int Type { get; set; }

    internal COMLib.ObjectID ToCOM()
    {
        COMLib.ObjectID id = new COMLib.ObjectID();
        id.ID = this.ID;
        id.Type = this.Type;
        return id;
    }
}

Now I can solve this by creating a dummy private constructor to these classes as the first constructor but I’m more curious about what causes this? Why does the order of the constructor declarations matter in VB.Net?

Update

This sounded so insane that I started doubting it myself. Managed to replicate it with 3 projects.

C# Class library: Wrapped

namespace Wrapped
{
    public class Class1
    {
    }
}

C# Class library: Wrapper

namespace Wrapper
{
    public class Class1
    {
        internal Class1(Wrapped.Class1 c) { }
        public Class1() { }
    }
}

VB.Net Console app: Referer

Module Module1
    Sub Main()
        Dim w As New Wrapper.Class1
    End Sub
End Module

Wrapper refers to Wrapped
Referer refers to Wrapper
Referer does NOT refer to Wrapped

Dim w As New Wrapper.Class1

Produces an error

Reference required to assembly 'Wrapped, Version=1.0.0.0,
                                         Culture=neutral,
                                         PublicKeyToken=null'
containing the type 'Wrapped.Class1'.
Add one to your project.

Swapping the order of constructors takes care of the error.

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=442224

Update after playing around some more

Causes error:          No error:

     Vb-ReferTest          Vb-RefererTest
          |                      |                     Fixes error in Vb-
          V                      V                      RefererTest even
      Cs-Wrapper            Cs-Wrapper   Vb-Wrapper <-  if the Vb-Wrapper
          |                       \         /          and the RefererTest
          V                        V       V             have no direct
   Cs-WrappedLibrary           Cs-WrappedLibrary          relationship
  • 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-11T17:09:04+00:00Added an answer on May 11, 2026 at 5:09 pm

    If correct (I can’t easily verify), that is fasinating. The order shouldn’t matter, AFAIK. If you are sure about it, then perhaps log as a bug on connect (with sample code).

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Programatically or just manually? Since the repository works over HTTP… May 12, 2026 at 11:07 am
  • Editorial Team
    Editorial Team added an answer Drupal's documentation is all directly from the source code. You… May 12, 2026 at 11:07 am
  • Editorial Team
    Editorial Team added an answer That isn't HTML. It is a combination of obsolete propriety… May 12, 2026 at 11:07 am

Related Questions

I'm writing code to do Xml serialization. With below function. public static string SerializeToXml(object
I want to reset an object. Can I do it in the following way?
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
The title pretty much says it all. When I'm doing some reflection through my

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.