1

I was researching an answer to a question I saw earlier on SO (System.Object not defined in VB.Net) and I discovered something that seems strange. I always thought that the class "Object" which, as everyone knows, resides in the "System" namespace, was defined in the System.DLL assembly or, at the very least, in the System.Core.DLL. However, when I started searching around in the Object Browser, I learned that Object is actually defined in mscorlib.dll. The really strange thing, though, is that this assembly is not referenced anywhere in any project. Just to test this, I created a project and removed ALL references:

enter image description here

Surprisingly (at least to me) doing so did not break anything. I could still write a piece of code like this:

Module Module1
    Sub test()
        Dim x As New Object
    End Sub
End Module

without any compile errors. Can someone out there kindly explain this to me?

Community
  • 1
  • 1
rory.ap
  • 34,009
  • 10
  • 83
  • 174

1 Answers1

4

The c# and vb compilers automatically include it

Originally I said to see C# compiler: /nostdlib option, but as noted in the comments this question implies something that isn't true

mscorlib is always referenced, no way to not, and the reason is stated here in a post by one of the CLR team

mscorlib.dll & System.dll

their post is simple enough to understand, but to sum it up - the CLR and mscorlib are too tightly bound to be separable.

Community
  • 1
  • 1
Jim W
  • 4,866
  • 1
  • 27
  • 43
  • Thanks for this info. I'm willing to accept your answer, but the post you linked to is misleading. According to [MSDN](http://msdn.microsoft.com/en-us/library/79e7wdtc%28v=vs.100%29.aspx) The "/nostdlib" compiler option "removes the automatic reference to the System.dll". As I stated in the question, the Object class is defined in mscorlib.dll. On that MSDN page, there is a note that says "The Mscorlib.dll and Microsoft.VisualBasic.dll assemblies are always referenced.", but I'm still interested to know why. Can you update your answer so it explains why? – rory.ap Nov 01 '13 at 12:47
  • @roryap well this is taken me on an unexpected journey - interesting though! – Jim W Nov 01 '13 at 15:29
  • Perfect. This is definitely interesting and good to know. Thanks for your help. – rory.ap Nov 01 '13 at 16:11