Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Doing things hueristically

Okay, before you read this, you might just like to wind-down a bit by doing some small limbering excercises:

  • First roll your head from side-to-side - ONE,.... TWO,.... (ouch!) .... THREE
  • Next, roll your shoulders from side-to-side - ONE,.... TWO,.... .... THREE
  • Finally, interlock your fingers with your palms facing outward and stretch your arms out in front of you.

Right, that's better, nice-n-relaxed, now for my piece:

The other day I mentioned about a problem that I encountered while trying to consume an assembly which had been compiled using Visual Studio .NET 2003 in an application that I was writing with Visual Studio .NET 2002.

As we all know, assemblies are fully self-describing, which means that information about all Types that are required by the application is included in the assemblies manifest.

Probing

When the application is first run, the .NET runtime goes about the task of building the assembly on the local machine. To do this it reads through the manifest a bit like a factory worker running through a stock picking list...

  • "Lemme see now", - [checks order list]
  • "I'm gonna need one System.Xml, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
  • "I know where that is, it's in the application \Bin\System.Xml folder", scratches head, and looks around...
  • "That's right, we moved 'em over to the application \Bin", scratches head again...
  • "Oh, now I remember, the boss asked us to shift 'em across to C:/WINDOWS/Microsoft.NET/Framework/v1.0.3705/Temporary ASP.NET Files/"... still scratching head...

Anyways, that process continues and the runtime "probes" through several more "known" paths until it decides that it cannot locate that particular assembly. At that point it throws it's hands in the air, raises an exception and cries out:

"File or assembly name System.Xml, or one of its dependencies, was not found."

Visual Studio .NET

If you are using Visual Studio .NET 2002 crank it up and add the System.Xml assembly to the local references of a Project. Done it? Good!

Now right click on that assembly at view its properties. Note the Identity property - System.Xml - and the version - 1.0.3300.0.  Note the version number is different to the version number that we probed for (1.0.5000.0)!

The Runtime and probing again

Notice the 3rd path that our ficticious factory worker took when trying to locate the assembly? He looked in the version folder that the assembly had been built with "v1.0.3705". It's important to note that Assemblies built with VS.NET 2002 will always probe via that path and the Framework does not install version 1.1 copy of the System.Xml assembly into that path. Assemblies built with VS.NET 2003 on the other hand will always probe via the correct, known path. After all, they installed it, they should know where it is, right? And how could version 1 of the framework possibly have known where version 1.1 would install it's files - version 1.1 hadn't even been invented back then!

Binding redirects

Fortunately you can tell the runtime where to look for a particular assembly by placing the redirect details into the configuration file for your application. Here is the redirect information that is required if you tried the ConeOfSilence challenge the other day...

 

    <startup>
        <requiredRuntime imageVersion="v1.0.3705" version="v1.0.3705" />
    </startup>
    
    
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Xml" publicKeyToken="b77a5c561934e089" culture="neutral" />
                <bindingRedirect oldVersion="1.0.5000.0" newVersion="1.0.3300.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System" publicKeyToken="b77a5c561934e089" culture="neutral" />
                <bindingRedirect oldVersion="1.0.5000.0" newVersion="1.0.3300.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>

 

 

The answer to the challenge...

You'll have to probe for that yourself ;-)

Keywords:
Assembly version, Framework, .NET, Not found, dependency, dependencies, binding redirect, probing, developer relaxation

1 Comment

  • As usual, you are far beyond us mere ASP mortals.





    Try as I might, I have not grok'd .Net. I made a concerted effort today to download the MSDN 'Intro to .Net' and watched about half of it. I figure I have about 10-20 more hours worth of MSDN stuff to watch before I &quot;get&quot; it.





    I know I have to get past this wall, but it is tough.

Comments have been disabled for this content.