使用反射,查找WCF异常类型

//使用System.Reflection,查找System.ServiceModel的异常类型
        public void ConsoleException()
        {
            try
            {
                Assembly asm = Assembly.GetExecutingAssembly();
                foreach (AssemblyName item in asm.GetReferencedAssemblies())
                {
                    if (item.Name != "System.ServiceModel") continue;
                    foreach (Type t in Assembly.Load(item).GetTypes())
                    {
                        if (t.Name.EndsWith("Exception"))
                        {
                            Console.WriteLine(t.Name);
                        }
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine( ex.Message);
            }
        }
   

posted @ 2014-04-22 13:48  teyond  阅读(190)  评论(0编辑  收藏  举报