Assembly Viewer and Assembly Conflict Viewer in ASP.NET

Everyone knows about Assembly. But, very few know about ILDASM tool, which is present in .NET Framework. ILDASM is nothing but Intermediate Language Disassembler. It is used to exploit any .NET dll or exe. By using this tool, we can see manifest, resources.....This tool is available in C:\WINNT\Microsoft.NET\Framework\v1.1.4322\. We can access this from VS.NET 2003 Command Prompt(present in VS Tools). Just drag any exe or dll onto that tool, to view its attributes. But, that tool won't show any conflicts that occur in referenced assemblies.
 
So, I created this Web application which will show Assembly attributes and Conflicts.
 
A conflict may occur if the referenced assembly is not present or a problem in culture or version.
 
So, if an assembly has to be loaded successfully means, all referenced assemblies must be present with specified culture and version.
 
This application will show all referenced assemblies of an Assembly. It will also show conflicts present in referenced assemblies. We can even see attributes of the referenced assembly.
 
I created this application in VS 2003 using C#.
 
First, create a web application in VS 2003 and name it as AssemblyViewer. Next, design UI as shown in the below figure:
 
 
I placed a File control, to select an assembly. We can add a file control, by adding this to HTML:
  1. <input id="fileuploader" style="Z-INDEX: 101; LEFT: 48px; POSITION: absolute; TOP: 56px" type="file" runat="server" NAME="fileuploader"
And add  this attribute to form tag:
encType="multipart/form-data"
 
Next, to show Button in DataGrid, add this DataGrid tag in HTML view:
  1. <Columns>  
  2.    <asp:TemplateColumn>  
  3.       <ItemTemplate>  
  4.          <asp:Button ID="button22" Runat="server" Text="View Details" Width="70"  
  5.          CommandName="ShowDetails"></asp:Button>  
  6.       </ItemTemplate>  
  7.    </asp:TemplateColumn>  
  8. </Columns> 
Next place remaining labels and listbox controls on the page.
 
Next, goto Page_load event and add this code there:
  1. ListBox1.Items.Clear();  
  2. Label4.Text=string.Empty; 
This will clear all previous errors attributes of Selected Assembly(selected from Grid).
 
Next goto Click event of View Details and add this:
  1. try  
  2. {  
  3.           //To Get Selected Assembly Path...  
  4.           string FileExt=fileuploader.PostedFile.FileName.Substring(fileuploader.PostedFile.FileName.LastIndexOf(".")+1);  
  5.           //To Check for Extension .dll...  
  6.           if(FileExt.ToLower()!="dll")  
  7.           {  
  8.                    Literal1.Text="<b>"+"Select a Valid File Format with Extension .dll"+"</b>";  
  9.                    return;  
  10.           }  
  11.           //To Store Selected assembly Name and Path...  
  12.           string selectedfile=fileuploader.PostedFile.FileName.ToString();  
  13.           string filepath    =Path.GetDirectoryName(selectedfile);  
  14.           Assembly assembly = Assembly.LoadFrom(selectedfile);  
  15.           Label2.Text =Path.GetFileName(fileuploader.PostedFile.FileName);  
  16.           assemblypath.Text =assembly.Location;  
  17.           StreamWriter writer;  
  18.           writer= new StreamWriter("c:\\assemblies.xml",false);  
  19.           writer.Write("<?xml version=\"1.0\"?>");  
  20.           writer.Write("<assemblies>");  
  21.           //To Get Attributes of each Referenced Assembly...  
  22.           foreach (AssemblyName  assemblynames in assembly.GetReferencedAssemblies())  
  23.           {  
  24.                    //To Save Attributes of each Referenced Assembly in a Temporary XML file...  
  25.                    string[] assemblies = assemblynames.FullName.ToString().Split(',');  
  26.                    writer.Write("<assembly>");     
  27.                    string assemblyname =assemblies[0];  
  28.                    string version =assemblies[1].ToString().Substring(assemblies[1].ToString().LastIndexOf('=')+1);  
  29.                    string culture =assemblies[2].ToString().Substring(assemblies[1].ToString().LastIndexOf('=')+1);  
  30.                    string publickeytoken =assemblies[3].ToString().Substring(assemblies[3].ToString().LastIndexOf('=')+1);  
  31.                     writer.Write("<assemblyname>"+assemblyname+"</assemblyname>");  
  32.                     writer.Write("<version>"+version+"</version>");  
  33.                     writer.Write("<culture>"+culture+"</culture>");  
  34.                     writer.Write("<publickeytoken>"+publickeytoken+"</publickeytoken>");  
  35.                     writer.Write("</assembly>");  
  36.           }  
  37.           writer.Flush();  
  38.           writer.Close();  
  39.           File.Copy("c:\\assemblies.xml","c:\\temp1.xml",true);  
  40.           StreamWriter writer1=File.AppendText("c:\\temp1.xml");  
  41.           writer1.Write("</assemblies>");  
  42.           writer1.Close();  
  43.           //To Show  Attributes of each Referenced Assemblies in DataGrid...  
  44.           DataSet ds=new DataSet();  
  45.           ds.ReadXml("c:\\temp1.xml");  
  46.           DataGrid1.DataSource=ds;  
  47.           DataGrid1.DataBind();  
  48.           File.Delete("c:\\assemblies.xml");  
  49.           File.Delete("c:\\temp1.xml");  
  50. }  
  51. catch(Exception ex)  
  52. {  
  53.           //To catch Exception, if the file is not in Valid Format...  
  54.           Literal1.Text="<b>"+"The format of the file is invalid."+"</b>";  

This will get attributes of each referenced assembly and save them in the XML file. Then, we are showing that data in DataGrid.
 
Next, go to the Click event of Show Conflicts  and add this code as shown in the below figure:
 
 
This will see for any conflicts in version or file missing for Selected Assembly(selected from file control), and will display error list and markers for that conflict assemblies in DataGrid.
 
Finally, go to DataGrid  DataGrid1_ItemCommand event and add this code as shown below:
 
 
This will show attributes of Selected Assembly(selected from Grid).
 
Final screen will be like this:
 
 
 
 
This screen will show conflicts as red marks and descriptions.
 
This application will show error messages if a referenced assembly is missing or any mismatch in the version. We can extend this, to show cultural conflicts also.
 
This application assumes selected assembly and its referenced assemblies are in the same folder.
 
By using this application, we can see assembly attributes and conflicts.
 
I  am attaching the code for reference.
 
I hope this will be useful for all.


Similar Articles