Introduction
The Collision Finder application is intended to help a development team to find colliding references to external DLLs.
Background
During the development of our system, we encountered a problem regarding referencing different versions of external DLLs. The problem gets worse when there is second stage reference from an external DLL to another one, which has a wrong version.
In order to solve this problem, I developed an application that helps the development team to find collisions during integration (rather than at run time).
Using the code
There are three projects:
- Console application: Returns a value of 1 if there is any collision, and 0 otherwise. The colliding DLLs will be printed out to the console.
- Windows application: This application helps the developer to analyze the external references by showing all the relations between the DLLs that are being used in a specific folder.
- Class library: The code beneath�.
Find
: This method uses an input parameter of string
type that represents the path to the folder to analyze, and returns true
/false
according to the existence of a collision.
CollisionOutPut
: get
property, returns a string with all the collisions that were found.
Data
: returns a dataset of the analyzed data.
How to execute from a console application:
FindCollisions c = new FindCollisions();
bool reply = c.Find(args[0]);
Console.Write(c.CollisionsOutPut);
if (reply == false)
return 1;
else
return 0;
How to find all the references of the current DLL:
ReferenceCollisionDataSet.DllTableRow dllRow =
_ds.DllTable.NewDllTableRow();
Assembly asm = Assembly.LoadFile(file);
AssemblyName asmName = asm.GetName();
dllRow.Name = asmName.Name;
dllRow.Version = asmName.Version.ToString();
_ds.DllTable.Rows.Add(dllRow);
foreach (AssemblyName refName in asm.GetReferencedAssemblies())
{
try {
if (IsNotSystemRef(refName))
{
ReferenceCollisionDataSet.ReferenceTableRow refRow =
_ds.ReferenceTable.NewReferenceTableRow();
refRow.Dll_Name = asmName.Name;
refRow.Reference_Name = refName.Name;
refRow.Version = refName.Version.ToString();
_ds.ReferenceTable.Rows.Add(refRow);
}
catch { }
}