Suzanne Cook's .NET CLR Notes

Common Language Runtime Developer

  • Suzanne Cook's .NET CLR Notes

    Debugging Assembly Loading Failures

    • 108 Comments
    So...you're seeing a FileNotFoundException, FileLoadException, BadImageFormatException or you suspect an assembly loading failure? Try the steps below to start your debugging process. First, get the Message property from the exception. If the exception...
  • Suzanne Cook's .NET CLR Notes

    App.config Examples

    • 25 Comments
    Below are three examples of useful application configuration files . Forces the v1.0 CLR to be run. If the v1.0 CLR is not installed, the app will fail to run. <?xml version ="1.0"?> <configuration> <startup> <requiredRuntime...
  • Suzanne Cook's .NET CLR Notes

    Choosing a Binding Context

    • 41 Comments
    There are three 'contexts' for assembly binding: Load context In general, if the assembly was found by probing in the GAC, a host assembly store (if hosted), or the ApplicationBase / PrivateBinPaths of the AppDomain, the assembly will be loaded...
  • Suzanne Cook's .NET CLR Notes

    App.Config Files

    • 37 Comments
    By default, the application configuration file of the default appdomain (and other appdomains for v1.1 and later) is in the process exe’s directory and named the same as the process exe + ".config". This is true even if that exe is unmanaged. Also, note...
  • Suzanne Cook's .NET CLR Notes

    Executing Code in Another AppDomain

    • 46 Comments
    The easiest way to run code in another appdomain is to execute an assembly entrypoint using AppDomain.ExecuteAssembly() or (starting in v2.0) AppDomain.ExecuteAssemblyByName(). If you want to execute a method other than an assembly entrypoint, call...
  • Suzanne Cook's .NET CLR Notes

    Mscorlib.dll

    • 28 Comments
    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...
  • Suzanne Cook's .NET CLR Notes

    Assembly Display Names

    • 32 Comments
    An assembly display name should include the assembly simple name, version, culture and public key token. The assembly simple name is usually the file name of the assembly without the extension (“.dll” or “.exe”). For example, the assembly display name...
  • Suzanne Cook's .NET CLR Notes

    When to Change File/Assembly Versions

    • 28 Comments
    First of all, file versions and assembly versions need not coincide with each other. I recommend that file versions change with each build. But, don’t change assembly versions with each build just so that you can tell the difference between two versions...
  • Suzanne Cook's .NET CLR Notes

    Unloading an Assembly

    • 30 Comments
    There's no way to unload an individual assembly without unloading all of the appdomains containing it. (See here for why not.) This can by done by calling AppDomain.Unload() for each AppDomain that has it loaded. (You could also use UnloadDomain() on...
  • Suzanne Cook's .NET CLR Notes

    Where to Find Technical Support

    • 14 Comments
    Microsoft's official support website is http://support.microsoft.com/ . It has all kinds of resources like product FAQs, downloads, searchable KB articles, newsgroup pointers, and ways to reach people to help with your individual needs or feedback. ...
  • Suzanne Cook's .NET CLR Notes

    LoadFile vs. LoadFrom

    • 12 Comments
    Be careful - these aren't the same thing. LoadFrom() goes through Fusion and can be redirected to another assembly at a different path but with that same identity if one is already loaded in the LoadFrom context. LoadFile() doesn't bind through...
  • Suzanne Cook's .NET CLR Notes

    ReflectionTypeLoadException

    • 11 Comments
    If a type can't be loaded for some reason during a call to Module.GetTypes(), ReflectionTypeLoadException will be thrown. Assembly.GetTypes() also throws this because it calls Module.GetTypes(). The Message for this exception is "One or more exceptions...
  • Suzanne Cook's .NET CLR Notes

    Assembly Identity

    • 16 Comments
    There are two types of assembly identity that the loader deals with: bind-time and after bind-time. The identity is used to determine whether we will consider a certain assembly to be the same thing as an assembly reference or another assembly. Assembly...
  • Suzanne Cook's .NET CLR Notes

    Avoid DevPath

    • 16 Comments
    I hesitate to talk about this because I don't want people who don't know about it to think, "Hey, what's this DevPath thing? I need that." But, maybe if I don't explain how to use it, it will be too much effort for people who don't already know how. ...
  • Suzanne Cook's .NET CLR Notes

    Avoid Partial Binds

    • 13 Comments
    A partial bind is when only part of the assembly display name is given when loading an assembly. Assembly.LoadWithPartialName() also uses partial binding. First, it calls Assembly.Load(). But, if that fails to find the assembly, it will return the...
  • Suzanne Cook's .NET CLR Notes

    Debugging a MissingMethodException, MissingFieldException, TypeLoadException

    • 14 Comments
    Say you've just installed some assemblies from a third party and now you're seeing a MissingMethodException, MissingFieldException, or TypeLoadException (during the run of an application using those assemblies). Below are the common causes. Loading...
  • Suzanne Cook's .NET CLR Notes

    Assembly.CodeBase vs. Assembly.Location

    • 7 Comments
    The CodeBase is a URL to the place where the file was found, while the Location is the path from where it was actually loaded. For example, if the assembly was downloaded from the internet, its CodeBase may start with "http://", but its Location may start...
  • Suzanne Cook's .NET CLR Notes

    Debugging an InvalidCastException

    • 11 Comments
    First, obviously, find the two types for which the cast failed and verify that they are the same type or otherwise castable. Next, if the type was just deserialized, also verify that its assembly successfully loaded in the target appdomain. If everything...
  • Suzanne Cook's .NET CLR Notes

    AppDomain.Load()

    • 8 Comments
    AppDomain.Load() is only meant to be called on AppDomain.CurrentDomain. (It's meant for interop callers only. They need a non-static method, and Assembly.Load() is static.) If you call it on a different AppDomain, if the assembly successfully loads in...
  • Suzanne Cook's .NET CLR Notes

    Channel 9 Interview

    • 19 Comments
    Charles Torre and Robert Scoble (behind the camera) dropped by my office to chat with me about the loader for MSDN's Channel 9: part I and part II . Also, check out the PDC video I was in for Channel 9: http://channel9.msdn.com/ShowPost.aspx?PostID=79591
  • Suzanne Cook's .NET CLR Notes

    New Assembly, Old .NET (and Vice-Versa)

    • 17 Comments
    I typically recommend that you build and test your assemblies against the same version of .NET that you will be running them against. That way, you'll have correct references and avoid surprises from behavior differences between builds. Older assembly...
  • Suzanne Cook's .NET CLR Notes

    Switching to the Load Context

    • 14 Comments
    So, after checking out the binding context options , you've decided to switch your app to use the Load context. Now, you just need to figure out how to do it. Maybe it will be as simple as using Assembly.Load( assemblyDisplayName ) instead of Load...
  • Suzanne Cook's .NET CLR Notes

    Load(AssemblyName)

    • 7 Comments
    Calling Load(AssemblyName) is not necessarily the same as calling Load(String). If the AssemblyName.CodeBase is not set, then they do do the same thing. So, if you've set the AssemblyName.Name, CultureInfo, public key token / public key and/or Version...
  • Suzanne Cook's .NET CLR Notes

    Versioning/Deploying Unmanaged Files

    • 4 Comments
    An unmanaged dll can be wrapped in a managed assembly by adding it as a file of a multi-module assembly. Then, it can be deployed and versioned in the same way as managed assemblies. (So, that assembly could contain nothing but metadata and unmanaged...
  • Suzanne Cook's .NET CLR Notes

    Determining Whether a File Is an Assembly

    • 10 Comments
    A file is an assembly if and only if it's managed and it contains an Assembly entry in its CLR metadata. Determining by hand A fast way to determine whether a file is an assembly is to run ildasm.exe on it. If it immediately gives an error saying...
Page 1 of 2 (30 items) 12