Click here to Skip to main content
15,888,351 members
Articles / Programming Languages / C#
Article

Collision Finder

Rate me:
Please Sign up or sign in to vote.
4.67/5 (10 votes)
12 Jul 2006CPOL1 min read 27.4K   629   15   5
A tool that finds refernced DLL version collisions.

Sample Image

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:

  1. 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.
  2. 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.
  3. 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:

C#
FindCollisions c = new FindCollisions();
bool reply = c.Find(args[0]); /// rgss[0] = your  directory
Console.Write(c.CollisionsOutPut); 
if (reply == false)
   return 1;
else
   return 0;

How to find all the references of the current DLL:

C#
ReferenceCollisionDataSet.DllTableRow dllRow = 
                             _ds.DllTable.NewDllTableRow(); 
// file  = the curent dll/exe path
Assembly asm = Assembly.LoadFile(file);
AssemblyName asmName = asm.GetName(); 
//  the name of the dll/exe
dllRow.Name = asmName.Name;
// the version of the dll
dllRow.Version = asmName.Version.ToString();
_ds.DllTable.Rows.Add(dllRow); 
//run on all the references of the curent Assembly 
foreach (AssemblyName refName in asm.GetReferencedAssemblies())
{ 
  try { 
       //check if this reference is not a system reference 
      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 { } 
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalfinding dll reference in a compact framework application Pin
DJMJBJM2-Feb-10 21:25
DJMJBJM2-Feb-10 21:25 
QuestionContext Switch Deadlock Pin
WirelessBen18-Jul-06 11:33
WirelessBen18-Jul-06 11:33 
This code is exactly what I need, but I'm getting this error when I choose the dll directory (debugging with VS 2005):

ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x1b0c28 to COM context 0x1b0d98 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

I did not see an app.config file. Does it need one?

AnswerRe: Context Switch Deadlock Pin
Nadav_h20-Jul-06 22:32
Nadav_h20-Jul-06 22:32 
GeneralRe: Context Switch Deadlock Pin
honeysip16-Jul-07 0:42
honeysip16-Jul-07 0:42 
GeneralRe: Context Switch Deadlock Pin
maheshjadhav_it19-Jul-07 4:25
maheshjadhav_it19-Jul-07 4:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.