§ March 23, 2006

Dependency Scanner (for .NET 1.1)

download Download Project & Source Code


.NET Dependency Resolver for .NET 1.1

Here's a little tool I wrote a while ago. Right now its only for .NET 1.1, but I'm working on a port for 2.0 (which should look a lot nicer).

When I wrote this, I was dealing with assemblies that had very complex inner-dependencies. Some assemblies were private, others were shared, and I ended up having to have a ton of ildasm.exe's open to the assembly manafest to try to see which assembly had referenced which assembly and had to verify that the assembly version referenced was correct. On top of that I needed to verify that assemblies that were referenced--that had policy files--were being redirected to the correct versions.

Basically all this tool does, is load an assembly, display its version, and lists any referenced assemblies, their versions, and whether or not the reference version resolves to any other version. It doesn't look like much, but its saved me a lot of time and head ache. It also has a copy / paste feature that can copy selected listview data to the clipboard in a nice column formatted manner.

Here's the main bulk of whats going on. Basically what I did, was to load the assembly file, then try to load another assembly based on the partial name from the assembly file that I just loaded. At first glance, it looks as if I'm creating 2 identical assembly objects. The difference is, that if one assembly was version 1.1.2 and there was a policy file for version 1.1.2 to redirect to version 1.2.3, the second assembly load would load version 1.2.3 instead of version 1.1.2. That info would be displayed in the top line of the assembly entry

private void ResolveAssemblyImports(string file) {
    try {
        Assembly asm = Assembly.LoadFile(file);
        Assembly d = Assembly.LoadWithPartialName(asm.FullName);
Then I matched the two assemblies version numbers to see if they matched
        string ver = "", re = "";
        bool nill = d == null;
        if(!nill) {
            re = _r.Match(d.FullName).Groups["version"].Value;
        } else {
            re = "NULL";
        }
        ver = _r.Match(asm.FullName).Groups["version"].Value;
        bool r_1 = false;
        if(ver != re && re != "NULL") {
            Version v_1 = new Version(ver);
            Version v_2 = new Version(re);
            if(v_2 >= v_1) r_1 = true;
        }
        AddItem(asm.GetName().Name, "----", ver, re, "True", nill ? "Failed" : (r_1 ? "True" : "False"));
Then I iterate through the assembly's referenced assemblies and try to do the same thing (match version numbers & see if they resolve to the same version)
        foreach(AssemblyName asmName in asm.GetReferencedAssemblies()) {
            string v1 = _r.Match(asmName.FullName).Groups["version"].Value,
                v2 = v1;
            bool exist = false, res = false;
            Assembly dep;
            try {
                dep = Assembly.LoadWithPartialName(asmName.FullName);
                if(dep != null) {
                    string temp = _r.Match(dep.FullName).Groups["version"].Value;
                    exist = true;
                    if(v2 != temp) {
                        Version v = new Version(v2);
                        Version t = new Version(temp);
                        if(t >= v) res = true;
                    }
                }
            } finally {
                AddItem("    +----", asmName.Name, v1, v2, exist.ToString(), res.ToString());
            }
        }
    } catch {
    }
}


Then I finally print out the results of my findings to the listview.


I had forgotten about this app until today when I couldn't understand why I kept getting an error for a method that had been updated in the assembly I was referencing. I pulled this tool out and saw that it indeed referenced the correct assembly but because another assembly being used referenced an older version of that assembly, the local copy was using the newer version but the older version was in the GAC so my code was using the older assembly that didnt have the current code that I needed (confused... I am and I was there).

Anyway, here's the project / source code for the app.

Update 7/16/2009 I've converted this app over to .NET 3.5 and complied app binaries that can be downloaded here
Posted 20 years, 4 months ago on March 23, 2006
Re: Dependency Scanner (for .NET 1.1)      [ posted April 17, 2006, 10:15 pm ]
Author Comment
TonyLThornton
[ Email     ]
Hows it goin MadHatter,

Just wondering what control you used for the grid...

it kind of looks like an infragistics grid...

perhaps i should download it and have a look.

good little utility


--Tony Thornton
[ Reply in the Forums ]
Re: Dependency Scanner (for .NET 1.1)      [ posted April 18, 2006, 7:06 am ]
Author Comment
Steve
[ Email     ]
Its just the standard listview (with an imagelist and a little background coloring).
[ Reply in the Forums ]

 Comments can be posted in the forums.

© 2003 - 2024 NullFX
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License