57

Why did MS originally make the decision to maintain these two separate core libs? Maybe they had some scalability issue in mind, but nowadays I never see an application, of any type, that doesn't need both. Does anyone have any inside information on this? It's not really important, but been on my mind for years.

PS. I know what's in the two libs, I know the difference - I'm a big fan of Reflector :) Just wondering what practical use the separation of the two has.

starblue
  • 55,348
  • 14
  • 97
  • 151
user39603
  • 2,235
  • 1
  • 16
  • 13

6 Answers6

72

I work on the CLR/BCL team and just answered your email. Here it is pasted below:

Jared's answer on Stack Overflow is right on. mscorlib.dll is tightly bound to the CLR for the reasons he mentions. Note that mscorlib.dll itself doesn't contain any native code (as Scott suggests), but there are many places where it needs to call directly into the CLR. As such, the CLR and mscorlib must be versioned together.

System.dll on the other hand is not tightly bound to the CLR (it doesn't require any calls into the runtime). We consider System.dll to be at a higher layer than mscorlib.dll. Having these assemblies in two separate layers allows for more flexibility, making it easier to version System.dll separately from the CLR/mscorlib.dll version (if we wanted to do so). We could, in theory, make changes and add functionality to System.dll without revving the CLR/mscorlib version. The separation also makes it easier to manage dependency rules between components in these different layers.

As Scott mentions, it does seem like there's a lot of "optional" stuff in mscorlib. This is mainly for historical reasons and because some things are just needed by other things. For example, there's no technical reason why System.IO.IsolatedStorage needs to be in mscorlib, but that's just where it happened to be added in 1.0, before we really thought about such versioning/layering concerns. Also, List is in mscorlib because other code in mscorlib has a need for a basic list collection.

Long term we'd like to reduce the amount of "optional" stuff in mscorlib as much as possible. Either by pushing stuff out of mscorlib or creating a new, more core, assembly that just contains the bare minimum necessary types (e.g. System.Object, System.Int32, etc.) to make managed code work. This will give us the flexibility to add new innovations to the "optional" stuff, and make it easier to create different .NET Framework SKUs (e.g. the .NET Client Profile, Silverlight, etc.), without having to rev the runtime.

I hope this helps!

Thanks, Justin

  • 6
    How did the team decide to name the assembly mscorlib? I have often wondered about the ms prefix and the 8.3 filename. – Michiel van Oosterhout Dec 04 '11 at 21:44
  • 14
    Checking the version information it is called: "Microsoft Common Language Runtime Classlibrary". But as far as I know it is also an acronym for "Multilanguage Standard Common Object Runtime Library", which was founded during the EMCA standardization of the CLI. – Christoph Meißner Mar 23 '12 at 08:58
41

Mscorlib does contains both native and managed code.

Amongst other things it contains the System.Object implementation, which must always be present in order for everything to work.

It has the distinction of being the only assembly that the CLR requires to be loaded inside every managed process.

Originally, a lot of "optional" stuff (things that technically aren't required to run an app) was put into mscorlib because they were things that were highly likely to be used by everybody. This includes things like HashTable and List.

This gave a perf boost. If everybody is going to want to use something, then it makes sense to put it inside the assembly that everybody has to load. Then you don't have to waste time going and binding a whole bunch of different assemblies.

The stuff in system.dll was basically everything that wasn't "worthy" of being included in mscorlib.

This trend, however, is starting to be reversed. The CLR is making efforts to reduce the size of mscorlib. A lot of stuff was removed for Silverlight for example (to reduce download size).

I think they might be doing more of this kind of stuff for V4 (and later versions) but I'm not sure about the details.

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
Scott Wisniewski
  • 24,561
  • 8
  • 60
  • 89
  • This is a bit of a nit-pick, but as @Justin Van Patten mentions, mscorlib.dll doesn't contain any native code. Instead it has extern methods annotated with `[MethodImpl(MethodImplOptions.InternalCall)]` which call into the CLR. If one browses the SSCLI sources, you can see these CLR methods exported for mscorlib consumption. – codekaizen Apr 07 '11 at 07:09
  • Technically it does contain SOME native node (the msdos stub in the PE header) but generally you are right. I edited the post to reflect that. – Scott Wisniewski Apr 07 '11 at 13:43
16

Expanding on Scott's answer.

Any given version of the CLR is highly tied to a particular version of mscorlib.dll. It is a special DLL in very many ways. The CLR runtime requires certain types/methods be available and implements many methods defined in the actual code base. The complexity of managing this relationship is reduced by having an unbreakable link between a CLR version, and version of mscorlib.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • Didn't know whether I should set Scott's or yours as the accepted answer, sorry. In the end, I decided to choose Scott's, but yours is just as good. – user39603 Jan 01 '09 at 14:55
  • 2
    Scott's is more complete. I just hit on one point he missed. I voted for his. – JaredPar Jan 01 '09 at 15:09
6

Take a good look at any project's References node. You'll never find mscorlib.dll listed there. It is special, any compiler needs it because it contains types that are required to make the language syntax work. System.Array, System.Int32, System.String, System.Exception, etc.

You can write a program that doesn't have a dependency on System.dll (although it would be hard) but you can't write one that doesn't depend on mscorlib.dll

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 4
    Yes you can - simply use `csc` with the `/nostdlib[+|-]` switch – Marc Gravell Dec 31 '08 at 10:51
  • 1
    My understanding is that /nostdlib only impacts the symbols the compiler imports. I beleive that your process, at run time, is going to load mscorlib, no matter what you do. – Scott Wisniewski Dec 31 '08 at 12:04
  • Well, that assumes you load it into MS's .NET impementation... load it into mono, and it probably won't. – Marc Gravell Dec 31 '08 at 15:35
  • I think mono still requires mscorlib at runtime (I could be wrong). Assembly name is a part of clr type identity. System.Object in mscorlib.dll is a different type than System.Obect in foo.dll. A program can't run without Object. You can replace / build a custom mscorlib, but it's still required. – Scott Wisniewski Dec 31 '08 at 23:37
  • /nostdlib was intended to get the compiler to use *another* version of the mscorlib reference assembly. As necessary in Silverlight projects for example. – Hans Passant Feb 10 '16 at 16:47
1

The mentioned native/managed thing sounds plausible, but I'm still not entirely convinced. In any case, MS seems to view mscorlib.dll as the core lib needed for the system, while System.dll contains the core functionality for programmers - which also sounds good.

I've just emailed this same question to the BCL team. If anyone can answer... When (if?) I receive an answer, I'll post it here. Thanks for the answers so far!

user39603
  • 2,235
  • 1
  • 16
  • 13
0

This is just a guess, but mscorlib.dll probably also has some C code that's important to the CLR runtime as well as being a .NET assembly, or some mixed-mode code. System.dll is probably all managed.

Ana Betts
  • 73,868
  • 16
  • 141
  • 209