How Many Types are loaded for Hello World


Fairy princess

<Updated> 


Consider the following super simple C# code

namespace SmartDeviceProject1
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine(“Hello”);
}
}
}

Can you guess how many managed Type gets loaded to run this? I was doing some profiling the .NET Compact Framework loader (for entirely unrelated reason) and was surprised by the list that got dumped. 87 177 types**, never could’ve guessed that…



  1. System.Object

  2. System.ValueType

  3. System.Enum

  4. System.Void

  5. System.Boolean

  6. System.Char

  7. System.SByte

  8. System.Byte

  9. System.Int16

  10. System.UInt16

  11. System.Int32

  12. System.UInt32

  13. System.Int64

  14. System.UInt64

  15. System.Single

  16. System.Double

  17. System.String

  18. System.Type

  19. System.Reflection.MemberInfo

  20. System.RuntimeType

  21. System.Array

  22. System.IntPtr

  23. System.UIntPtr

  24. System.Text.StringBuilder

  25. System.Delegate

  26. System.MulticastDelegate

  27. System.DateTime

  28. System.Exception

  29. System.MarshalByRefObject

  30. System.AppDomain

  31. System.__ComObject

  32. System.Decimal

  33. System.SZArrayHelper

  34. System.Collections.IEnumerable

  35. System.Collections.IEnumerator

  36. System.Nullable`1

  37. System.SystemException

  38. System.Security.VerificationException

  39. System.Runtime.InteropServices.CurrencyWrapper

  40. System.Runtime.InteropServices.UnknownWrapper

  41. System.Runtime.InteropServices.DispatchWrapper

  42. System.Runtime.InteropServices.ErrorWrapper

  43. System.Runtime.InteropServices.CustomMarshalerHelper

  44. System.Attribute

  45. System.Runtime.InteropServices.InterfaceTypeAttribute

  46. System.Runtime.InteropServices.GuidAttribute

  47. System.Runtime.InteropServices.ComVisibleAttribute

  48. System.Runtime.InteropServices.ComEventInterfaceAttribute

  49. System.Runtime.InteropServices.ComSourceInterfacesAttribute

  50. System.Runtime.InteropServices.LCIDConversionAttribute

  51. System.Runtime.InteropServices.ComDefaultInterfaceAttribute

  52. System.Runtime.InteropServices.DispIdAttribute

  53. System.CorPubObject

  54. System.Char[]

  55. System.Collections.Hashtable

  56. System.Reflection.BindingFlags

  57. System.Reflection.MemberFilter

  58. System.Reflection.Binder

  59. System.Type[]

  60. System.Reflection.TypeAttributes

  61. System.Void*

  62. System.Int32[]

  63. System.IntPtr[]

  64. System.Collections.IDictionary

  65. System.UnhandledExceptionEventHandler

  66. System.AppDomainManager

  67. System.Version

  68. System.Runtime.InteropServices.ComInterfaceType

  69. System.Collections.ICollection

  70. System.Collections.IEqualityComparer

  71. System.AppDomainManagerInitializationOptions

  72. System.ArithmeticException

  73. System.ArgumentException

  74. System.MissingMemberException

  75. System.MemberAccessException

  76. System.AppDomainSetup

  77. System.Runtime.InteropServices.Marshal

  78. System.PInvoke.EE

  79. System.Reflection.AssemblyName

  80. System.Byte[]

  81. System.Globalization.CultureInfo

  82. System.Reflection.Assembly

  83. System.Configuration.Assemblies.AssemblyHashAlgorithm

  84. System.Configuration.Assemblies.AssemblyVersionCompatibility

  85. System.Reflection.AssemblyNameFlags

  86. System.Globalization.CultureTableRecord

  87. System.Globalization.CompareInfo

  88. System.Globalization.TextInfo

  89. System.Globalization.NumberFormatInfo

  90. System.Globalization.DateTimeFormatInfo

  91. System.Globalization.Calendar

  92. System.Globalization.BaseInfoTable

  93. System.Globalization.CultureTable

  94. System.Globalization.CultureTableData

  95. System.Globalization.CultureTableData*

  96. System.UInt16*

  97. System.Globalization.NumberStyles

  98. System.Globalization.DateTimeStyles

  99. System.String[]

  100. System.Globalization.DateTimeFormatFlags

  101. System.Globalization.TokenHashValue

  102. System.Globalization.TokenHashValue[]

  103. System.Byte*

  104. System.Globalization.CultureTableHeader

  105. System.Globalization.CultureTableHeader*

  106. System.Globalization.CultureNameOffsetItem

  107. System.Globalization.CultureNameOffsetItem*

  108. System.Globalization.RegionNameOffsetItem

  109. System.Globalization.RegionNameOffsetItem*

  110. System.Globalization.IDOffsetItem

  111. System.Globalization.IDOffsetItem*

  112. System.TokenType

  113. System.Int32&

  114. System.IO.TextReader

  115. System.IO.TextWriter

  116. System.IFormatProvider

  117. System.Console

  118. System.Char&

  119. System.Char*

  120. System.ArgumentNullException

  121. System.PInvoke.NSLIntl

  122. System.ArgumentOutOfRangeException

  123. System.RuntimeTypeHandle

  124. System.NotSupportedException

  125. System.PlatformNotSupportedException

  126. System.String&

  127. System.TypeLoadException

  128. System.Globalization.EndianessHeader

  129. System.Globalization.EndianessHeader*

  130. System.Globalization.GlobalizationAssembly

  131. System.BCLDebug

  132. System.PInvoke.TableData

  133. System.InvalidProgramException

  134. System.Collections.HashHelpers

  135. System.Globalization.CultureTableItem

  136. System.UInt32&

  137. System.Security.CodeAccessSecurityEngine

  138. System.LocalDataStoreMgr

  139. System.Threading.ExecutionContext

  140. System.LocalDataStore

  141. System.Collections.ArrayList

  142. System.Threading.SynchronizationContext

  143. System.Runtime.Remoting.Messaging.LogicalCallContext

  144. System.Runtime.Remoting.Messaging.IllogicalCallContext

  145. System.Threading.Thread

  146. System.Object[]

  147. System.Collections.Generic.Dictionary`2

  148. System.Runtime.Remoting.Messaging.CallContextRemotingData

  149. System.Runtime.Remoting.Messaging.CallContextSecurityData

  150. System.Collections.Generic.IEqualityComparer`1

  151. System.InvalidOperationException

  152. System.Globalization.CultureTableRecord[]

  153. System.Threading.Monitor

  154. System.Globalization.CultureTableRecord&

  155. System.Object&

  156. System.Threading.Interlocked

  157. System.Runtime.CompilerServices.RuntimeHelpers

  158. System.RuntimeFieldHandle

  159. System.PInvoke.PAL

  160. System.IndexOutOfRangeException

  161. System.IntPtr&

  162. System.Buffer

  163. System.NullReferenceException

  164. System.OutOfMemoryException

  165. System.InvalidCastException

  166. System.OverflowException

  167. System.DivideByZeroException

  168. System.ArrayTypeMismatchException

  169. System.MissingMethodException

  170. System.FormatException

  171. System.RankException

  172. System.Security.SecurityException

  173. System.StackOverflowException

  174. System.Threading.ThreadAbortException

  175. System.Threading.ThreadTerminateException

  176. System.MethodAccessException

  177. SmartDeviceProject1.Program

**This is for the compact framework CLR. Your mileage will vary if you run the same on the desktop CLR.

Comments (11)

  1. JC says:

    Is there a way with the .NET profiler to find out this information along with why a particular type was loaded?

  2. Atul says:

    I know I can use the modules window to know which modules were loaded. what is the best way to find out loaded types? But then added to this will be the fact that they are probably only loaded since they are in some commond assembly. Unless they get JIT compiled, does it really matter?

  3. Steven Nagy says:

    I wonder why System.String isn’t in your list?

    Considering a string is the key functional part of your application…

  4. Daniel Jennings says:

    If System.String really isn’t loaded, it must be using a Char[].

  5. Jon says:

    something so simple has become so complex.

  6. Greg M says:

    Note: It is 312 for the desktop version of Java. The number of classes loaded for the compact (Java ME) version of Java is has not been posted yet.

  7. JC: Try WinDbg with SOS extension as outlined in http://mtaulty.com/communityserver/blogs/mike_taultys_blog/archive/2004/08/03/4671.aspx. Look for the section named "Looking at Managed Memory" which shows usage of dumpheap -stat

  8. Daniel Jennings: You are right. Makes me suspicious. Either I missed a intrumentation point or something else is happening. Let me check more…

  9. I updated the list with more types that gets loaded but I missed because I ran the wrong exe. The current list should be the final one

  10. Preston says:

    I thought the answer would be 42.