Welcome to MSDN Blogs Sign in | Join | Help

Mscorlib.dll

At least for v2 and earlier, mscorlib.dll is a special case. That causes it and its types to be loaded differently from other assemblies.

Loading Mscorlib.dll Without a Path
It and the execution engine are so closely integrated that it's required that they match each other. So, once a version of the CLR is chosen, the version of mscorlib is also chosen automatically. That means that, when late binding (Assembly.Load(), etc.) for it without a path, the 'official' mscorlib Assembly will always be returned - regardless of the version that was requested. The same thing goes for loading by static reference to it.

This doesn't mean that it's okay to give an incomplete or incorrect reference for it! If/when mscorlib.dll is factored away from the execution engine, it won't be such a special case and bad references will start to fail to load.

Reflecting On Another Mscorlib.dll
It's possible to load another mscorlib.dll if it's loaded by path. But, it's not possible to load its types, due to optimizations done by the CLR's execution engine. (Same goes for ReflectionOnlyLoadFrom() on another mscorlib.dll.) This means that even if you rename the mscorlib.dll that you want to reflect over, it may be loaded, but its types will still be unloadable. So, the options for working around this are:

  • Reflect on the 'official' mscorlib.dll. You could change the version of the CLR that your app loads in order to reflect on the desired mscorlib version.
  • Use the unmanaged metadata API to get the desired info.
  • Create an asmmeta file for the desired mscorlib.dll and parse it at runtime.

 

Published Monday, June 30, 2003 4:14 PM by Suzanne Cook
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# RE: Mscorlib.dll

Could you take a look at my comment here about Assembly.Load? Also, is the source code in the SSCLI for the threading & networking services the same in both the SSCLI and the .NET framework?
Monday, June 30, 2003 5:45 PM by Phil

# RE: Mscorlib.dll

Oops I meant the comment in your post on Assembly.Codebase and Location.
Monday, June 30, 2003 5:46 PM by Phil

# RE: Mscorlib.dll

Sure. Sorry, my responses are sometimes delayed, since I'm busy working on the product, not technical support. If you need a quicker response, you may want to consider talking to Microsoft's official tech support channels. Microsoft's official newsgroups are also good, since some non-MS MVP's may also answer your questions quickly (in addition to the MS people who answer). Anyway, yes, the code for that is basically the same for both (though, of course, it takes time for changes from the CLR to propagate to SSCLI).
Monday, June 30, 2003 9:06 PM by Suzanne

# RE: Mscorlib.dll

Thanks
Monday, June 30, 2003 9:19 PM by Phil

# RE: Mscorlib.dll

Can you give me some pointers (articles, links to examples) about the unmanaged metadata API you mentioned at the end of your article, please? What newsgroups or forums I could ask about these kind of problems? Many thanks Cris
Wednesday, November 12, 2003 7:26 AM by Krisztian Gyuris

# RE: Mscorlib.dll

Try ms-help://MS.MSDNQTR.2003OCT.1033/dnmag00/html/metadata.htm from MSDN, or search for ".NET Unmanaged Metadata API" on the web. For newsgroups, try microsoft.public.dotnet.* (the CLR newsgroup is best for questions about metadata).
Friday, November 14, 2003 2:00 AM by Suzanne

# RE: Mscorlib.dll

Thanks Suzanne!
Wednesday, November 19, 2003 5:00 AM by Krisztian Gyuris

# Binding to .NET Frameworks Assemblies

Friday, February 13, 2004 7:45 PM by Suzanne Cook's .NET CLR Loader Notes

# re: Mscorlib.dll

I am working in vb.net. I am getting an eror "Object reference not set to an instance of an object " which its error source in mscorlib. I am getting this error while working with the farpoint grid which has one of a columns as checkbox .When the statement .value = 1 (which checks the checkbox) it throws this error
plz help me out
Monday, March 01, 2004 1:30 AM by binal dalal

# re: Mscorlib.dll

Binal Dalal, please keep comments here related to the loader. See http://blogs.msdn.com/suzcook/archive/2003/12/05/57253.aspx for general support.
Monday, March 01, 2004 1:48 AM by Suzanne

# re: Mscorlib.dll

i have visual C++ 6 and not exist mscorlib...
Why;
help please
Saturday, May 08, 2004 2:31 AM by Kostas

# re: Mscorlib.dll

It's not there because the CLR is not installed. VS6 is pre-.NET. VS.NET starts with version 7.
Saturday, May 08, 2004 10:25 AM by Suzanne

# re: Mscorlib.dll

I'm still reading through your archives, but what is a asmmeta file? Google returns 0 hits, and I can't find it in MSDN.
Wednesday, May 12, 2004 6:25 PM by Jason G

# re: Mscorlib.dll

Hello!

I have unmanaged C++ code which I want to be managed, and than I want to make web service from that managed code. The best way to do it?

Thanks!
Friday, May 20, 2005 3:26 AM by eddi

# re: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

i got this problem, after downloading the sample code from msdn/
Wednesday, April 19, 2006 7:28 AM by siva

# Serial Communication (Using MSCOMM32)



I am a programmer of vb6 . now i am using VB.Net . i am trying to communicate the machine on serial port using vb.net. But i am facing a Error "Exception from HRESULT: 0x800A1F45". Remember i am using MSCOMM32 for serial communication. as we did in vb6.0

File Include as Refenece
(1)Interop.MSCommLib
(2)mscorlib

Plz Help me as soon as posible
Regards
Saqib
Saturday, June 10, 2006 1:46 AM by Saqib

# Mscorlib

I had faced this type of exception
And i have no idea for what reason this will propogate..
Please do reply me,
--------------------------------------------
Exception #1 Source: mscorlib
Invalid length for a Base-64 char array.
at System.Convert.FromBase64String(String s)
at System.Web.UI.LosFormatter.Deserialize(String input)
at System.Web.UI.Page.LoadPageStateFromPersistenceMedium()
--------------------------------------------

Wednesday, June 28, 2006 12:28 PM by Vachan

# re: Mscorlib.dll

What exactly is mscorlib all about? Is this the base building block for the primary namespaces in .Net?

Can I open it and view it's code?
Wednesday, August 02, 2006 4:03 AM by Andy

# re: Mscorlib.dll

I am havin visual studio1.1. Can i use System.Collections.Generic Namespace??
Thursday, September 14, 2006 4:04 AM by Mscorlib is not available

# re: Mscorlib.dll

i am using .NET 2003 ,i install to my computer crystal report 10 and then all my reports in the project return to crystal report 10.

And when i create a setup project All files dependency is mscorlib

WHAT CAN I DO TO SOLVE THIS PROBLEM

Wednesday, October 11, 2006 2:22 AM by KORAY

# re: Mscorlib.dll

hai,

  While using the Crystal Report XI in ASP.NET there is an Error  Not Enough Memory for operation.

Wednesday, December 27, 2006 10:05 AM by Venkatesh.K

# Binding to .NET Frameworks Assemblies

By "Frameworks assemblies," I mean the assemblies that ship with the CLR. But, I'm not counting mscorlib.dll

Thursday, April 12, 2007 7:11 PM by Suzanne Cook's .NET CLR Notes

# re: Mscorlib.dll

I'm getting this error:

Description:  Input string was not in correct format

Source:  mscorlib

Can you tell me what this might be about

Tuesday, May 22, 2007 8:30 AM by Mel

# re: Mscorlib.dll

Hi

 I am using Vb.net. whenever i call the ***.dll i got the following error

mscorlib:Could not find file 'C:\Output\debug.ddd'.

and also

Exception has been thrown by the target of an invocation.

Tuesday, July 10, 2007 9:05 AM by Rams

# Hos does exe calls Hosting API

I want to know that when we double click a .net exe, how does the Hosting API gets called for loading the CLR in the process.

Thanks and Regards

Saurabh Jain

itsaurabh@yahoo.com

Wednesday, March 12, 2008 6:38 AM by Saurabh Jain

# re: Mscorlib.dll

mscorlib is working on application at developmnent but not working after publish in the same machine.

Please give me a suitable solution for the same.

Thanks & regards

Ramesh H. Sahoo

Friday, March 14, 2008 5:44 AM by Ramesh H. Sahoo

# Mscorlib.dll

I see that mscorlib is integrated closely with CLR. That must be why errors thrown by mscorlib are so hard to trace.

One such error that we face at our client's site is the infamous 'Handle is invalid error'. Give below is stack trace.

mscorlib

The handle is invalid.

at System.IO.__Error.WinIOError(Int32 errorCode, String str)

at System.IO.FileStream.ReadCore(Byte[] buffer, Int32 offset, Int32 count)

at System.IO.FileStream.Read(Byte[] array, Int32 offset, Int32 count)

at System.Xml.XmlStreamReader.Read(Byte[] data, Int32 offset, Int32 length)

at System.Xml.XmlScanner.Read()

at System.Xml.XmlScanner.ScanName()

at System.Xml.XmlScanner.ScanMarkup()

at System.Xml.XmlScanner.ScanToken(Int32 expected)

at System.Xml.XmlTextReader.SetElementValues()

at System.Xml.XmlTextReader.ParseElement()

at System.Xml.XmlTextReader.Read()

at System.Xml.XmlValidatingReader.ReadNoCollectTextToken()

at System.Xml.XmlValidatingReader.Read()

at System.Xml.XmlLoader.LoadCurrentNode()

at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)

at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)

at System.Xml.XmlDocument.Load(XmlReader reader)

at System.Xml.XmlDocument.Load(String filename)

This happens occasionally while reading an xml document and seems to have no particular cause since at other times the same code executes successfully.

Monday, May 26, 2008 6:21 AM by Milano

# re: Mscorlib.dll

The following error message results after an attempt to save a VB 2005 form--"Could not load type 'System.Byte' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' because the format is invalid. error message."

Can you tell me what is causing this error?  (The software is on the hard drive and the application is stored on the server.)  And, I want to know how to correct this problem.

Friday, June 06, 2008 2:28 PM by Paul Smith

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker