inline code debug assistance on ReflectionTypeL...

Some day I came across problem where there is a ReflectionTypeLoadException thrown, and it has a very vague error mesage, only it says that "Please see the inner LoaderExceptions property for  more dtails"..

However, it is a collection properties, and you have to use a debugger in order to get a view of what is wrong,, here it is avery simple technique, where you can just try to comcat the exceptions and forms a good report.

Here is part of the code. 


catch (ReflectionTypeLoadException ex)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    if (exSub is FileNotFoundException)
                    {
                        FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                //Display or log the error based on your application.
                Console.WriteLine("Get ReflectionTypeLoadException : {0}", ex.ToString());
                throw;
            }


你可能感兴趣的:(C#)