Jump to content
Tuts 4 You
Sign in to follow this  
sirp

.NET Exceptions (all of them) + Source

Rate this topic

Recommended Posts

sirp

.NET Exceptions (all of them)

The surce code for generating the list of .NET exceptions that I posted earlier. Here it is finally. This just outputs an XML structure to the console. You can redirect the output to a file then use an XSLT transform on it (or do whatever else you want with it).


using System;using System.Collections.Generic;using System.Text;using System.Reflection;using System.Collections;using System.Text.RegularExpressions;using System.Design;using System.Xml;using System.IO;namespace ExceptionList{ class Program { static void Main(string[] args) { ReflectionSearch(".*exception$"); Console.ReadKey(); } static public void ReflectionSearch(string strPattern) { Assembly thisAssembly = Assembly.GetExecutingAssembly(); AssemblyName[] assemblyNames = thisAssembly.GetReferencedAssemblies(); // Force the load of various assemblies LoadAssemblies(); Regex regex = new Regex(@"^(?<path>.*)\.(?<exc>.*?)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture); foreach (var assemblyName in assemblyNames) { // iterate over all of the modules referenced by this assembly Assembly assembly = Assembly.Load(assemblyName); foreach (Module module in assembly.GetModules()) { SortedList<string, string> moduleList = new SortedList<string, string>(); foreach (Type t in module.GetTypes()) { // if there is a class of type Exception in this module // add it to the sorted list if (t.IsSubclassOf(typeof(Exception))) { // the funky key is so that the output will be sorted // the way a human would want it to be moduleList.Add(t.Namespace + ".1" + t.Name, t.FullName); } } // as long as we found some exceptions in this module if (moduleList.Count > 0) { string lastPath = ""; Console.WriteLine(string.Format("<module name=\"{0}\">", module.Name)); // get the XML file containing the XML comments for the .NET objects // As far as I can tell, the 2.0 framework comes with these files // but the 3.0 and 3.5 framework does not. I'm sure the XML files // exist, but I don't have them string xmlFileName = string.Format( @"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\en\{0}.xml", module.Name.Substring(0, module.Name.Length - 4)); XmlDocument xd = null; if (File.Exists(xmlFileName)) { xd = new XmlDocument(); xd.Load(xmlFileName); } // iterate over each exception in this module foreach (string excName in moduleList.Values) { Match match = regex.Match(excName); if (match.Success) { string path = match.Groups["path"].Value; // keep track of when we're switching to a new module if (path != lastPath) { if (!string.IsNullOrEmpty(lastPath)) { Console.WriteLine("</namespace>"); } lastPath = path; Console.WriteLine(string.Format("<namespace name=\"{0}\">", path)); } // get the full class name including the namespace string fullClassName = string.Format("{0}.{1}", path, match.Groups["exc"].Value); Console.WriteLine(string.Format("<exception name=\"{0}\">", fullClassName)); // output the MSDN reference link Console.WriteLine(string.Format( "<a href=\"http://msdn.microsoft.com/en-us/library/{0}.aspx\">{1}</a>", fullClassName.ToLower(), match.Groups["exc"].Value)); // if there is XML documentation for this exception // and there is a summary node, write it out if (xd != null) { XmlNode xnd = xd.SelectSingleNode(string.Format("//member[@name='T:{0}']/summary", fullClassName)); if (xnd != null) { Console.WriteLine(string.Format("<summary>{0}</summary>", xnd.InnerText.Trim())); } } Console.WriteLine("</exception>"); } else { Console.WriteLine("Whoops...\t" + excName); } } Console.WriteLine("</module>"); } // end if } // end foreach } // end foreach } private static void LoadAssemblies() { new System.AddIn.Hosting.InvalidPipelineStoreException(); new System.Configuration.Provider.ProviderException(); new System.Configuration.Install.InstallException(); new System.Data.DataException(); new System.Drawing.Color(); new System.Drawing.Design.UITypeEditor(); new System.DirectoryServices.DirectoryEntry(); new System.Management.ConnectionOptions(); new System.Messaging.AccessControlList(); new System.Runtime.Remoting.RemotingException(); new System.Runtime.Serialization.Formatters.Soap.SoapFormatter(); new System.Security.HostProtectionException(); new System.ServiceProcess.TimeoutException(); new System.Web.HttpCompileException(); new System.Windows.Forms.Form(); new System.Windows.Forms.Design.AnchorEditor(); new System.Xml.XmlDocument(); } }}

You’ll need to add the following references:

System.AddIn

System.Xonfiguration

System.Configuration.Install

System.Core

System.Data

System.Design

System.DirectoryService

System.Drawing

System.Management

System.Messaging

System.RunTimeRemoting

System.Security

System.ServiceProcess

System.Web

System.Windows.Forms

System.Xml

System.Xml.Linq

credz to Mike Vallotton

i found the fr 3.0 and 3.5 xml comment files at

C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5

and

C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\en

this is where the vs object browser querys the data.

BLOG

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...