.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Reflection question - how to tell which exceptions a method throws

Posted By:      Posted Date: October 10, 2010    Points: 0   Category :.NET Framework

I've found an ExceptionHandlingClauses collection in MethodBody but I'm looking for the exceptions that are *thrown*. You know, when you look at the ReadByte method of FileStream on msdn and you see that the ReadByte method throws two exceptions - the NotSupportedException and the ObjectDisposedException. 

How can I get this info programatically?


View Complete Post

More Related Resource Links

Reflection question - how to tell if a method is defined in an interface?


OK so the Reflection namespace has tools so you can tell if a method has a base definition in a class (MethodInfo.GetBaseDefinition().DeclaringType). This way for instance I can query the ToString method of my favorite class and see that yes, indeed this inherits from System.Object.

I also can detect if a method is an explicit interface implementation, by checking the name of the method (methods representing explicit interface implementation will have the fully qualified name of the interface pre-pended to the value of the Name property) so I'm okay there.

But what about plain ole interface implementations? How do I get this info?

Thanks if you can help!

Question in Get method in C#


I got a recent working code from client.I see errors in the get methods when i compile , below are some place where the error happens.Can any one help me out?


Error 2 'System.Environment.NewLine.get': cannot explicitly call operator or accessor C:\Documents and Settings\shankar\My Documents\Visual Studio 2008\Projects\DKCLwin\DKCLwin\LocalizationAdmin.cs 150 170 DKCLwin

Error 2 'System.Environment.NewLine.get': cannot explicitly call operator or accessor C:\Documents and Settings\shankar\My Documents\Visual Studio 2008\Projects\DKCLwin\DKCLwin\LocalizationAdmin.cs 150 170

Static Method System.Convert.ToDateTime() throws a FormatException on Windows7

Hello, There is a strange bug with the method System.Convert.ToDateTime(). Trying this simple statement Convert.ToDateTime("10/9/2010 17.39"); on a windows vista/xp works and the conversion is done. If you try that on a windows 7 than you get a format exception. Anybody has this problem? https://connect.microsoft.com/VisualStudio/feedback/details/597405/static-method-system-convert-todatetime-throws-a-formatexception-on-windows7#details Best regards. Thank you.

Dependency Properties get/set method question



I recently added a new dependency property to a control of mine and bound its value to my control's ViewModel.  I put custom code in the Get method of the dependency property and saw the return value from that method does not come across to the ViewModel.  After some research, it seems that when the XAML parser attempts to get or set this property's value that it does not use these get/set methods at all.  So to make this DP useful for my scenario, I have to figure out another way to set this value ahead of time, i.e. through code.

My question is, what is the point of these get/set methods for your DP if the XAML parser isn't going to use them?  Is it really all that useful to use these in code?  I would imagine DP's are mostly being used for the purpose of data binding in which case it'd be helpful to be able to define how WPF will get and set the value.  I liken this scenario to a public property with a private backing field, and having WinForms or whatever just directly access the backing field and skipping my property's getter/setter, which would obviously be a bug.

I'd appreciate any insight on this.

Can somebody answer this multiple choice question regarding exceptions ?


You are creating a class library that will be used by several applications. You need to create a custom exception that will be thrown if an application attempts to retrieve product information using an invalid product number.

You need to create the ProductNotFoundException class. From which class should you derive ProductNotFoundException?

A: ApplicationException

B: SystemException

C: Exception

D: ArgumentException


Get method parameter's values using reflection


By writing the following code I can get the method parameters metadata.


        void test(int x, string s)
            StackTrace st = new StackTrace(true);

            foreach (StackFrame sf in st.GetFrames())
                MethodBase mb = sf.GetMethod();
                foreach (ParameterInfo pi in mb.GetParameters())


I need the parameters value (the value that was passed to the method).

Can I get it in C#?


Thanks Gil

Executing method of the Generic class using Reflection.



I have a generic class:

 abstract public class BaseTC<T>:IExecutable where T : Core, new()
    private Type2 testInfo;
    private Type1 settings;
    private T core = null;

and I want to load such class from library the class is located in, and create an instance of it and execute methods later on.

I know how to use non-generic classes, but no idea how to call the same with generics.

Reflection question: PropertyInfo properties seem in an inconsistent state



Noticed something odd here... In class System.Collections.CollectionBase there is a property called InnerList

(see http://msdn.microsoft.com/en-us/library/system.collections.collectionbase.innerlist%28v=VS.90%29.aspx)

From the msdn link you can see that this property is read-only, as there is only a "get" and no "set". In the reflections namespace there is a class called PropertyInfo. When I query the PropertyInfo object corresponding to this InnerList property I get CanRead = true and CanWrite = false (as expected).

BUT when I go to retrieve the get method (with GetGetMethod) I get null. How is this possible, what does this mean?

Thanks in advance,

webinvoke method=Post..throws error "The remote server returned an error: (405) Method Not Allowed."



my service defn

      UriTemplate = "/CreateCustomer/cNo/{cNo}/cName/{cName}",
      Method = "POST")]
    bool InsertCustomer(string cNo, string cName);

/*service call*/

 public bool InsertCustomer(string cNo, string cName)
      bool Inserted;
      String connString = ConfigurationManager.ConnectionStrings["connectionstr"].ConnectionString;
      SqlConnection Conn = new SqlConnection(connString);
      SqlCommand Cmd = new SqlCommand();
      Cmd.Connection = Conn;
      Cmd.CommandText = "Insert into Customer Values(cid,cname)";
      Cmd.Parameters.AddWithValue("cid", Convert.ToInt32(cNo));
      Cmd.Parameters.AddWithValue("cname", cName);
      Inserted = Convert.ToBoolean(Cmd.ExecuteNonQuery());
      return Inserted;

/*client code */

  string ServiceUri = "http://localhost:portno/Service.svc/CreateCustomer/" + "cNo" + "/" + TextBox1.Text + "/" + "cName";
      WebRequest addRequest = WebRequest.Create(ServiceUri);
      addRequest.Method = "POST";
      addRequest.ContentType = "application/xml; charset=utf-8";
      addRequest.ContentLength = 0;
      WebResponse addResponse = addRequest.GetRespo

Revised Question XML Value Method Return Multiple Rows


Question earlier asked and answered to run query to collect sql data from xml schema

was able to collect the scheme from node but query did not return data but xml string


I ran this query

select x.col.value ('




cross apply



Question about GroupPrincipal.FindByIdentity(PrincipalContext, String) Method and AD account permiss



I have an ASP.NET application that uses System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity (PrincipalContext, String) method to get a group principal object.  When the code runs under an AD account that has the "Read All Properties" permission for an AD global security group then the corresponding group principal object can be instantiated without problems.  However, this "Read All Properties" permission consists of fifty or so more detailed permissions to read properties like "Name", "Description", "msExchLabeledURI" and so on.  Some of these properties can be locked down for some AD accounts and I found that GroupPrincipal.FindByIdentity method may return a NULL in such cases. Is there a minimum set of group properties an AD account should have the Read permission to so the FindByIdentity method could instantiate the corresponding GroupPrincipal object?

Thanks in advance!


Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

How to get more information about the exceptions that can happen in SharePoint 2010 projects?

In case there is an exception anywhere in the SharePoint 2010 project (most common place an exception would happen is during deployment of your SharePoint project, custom deployment configuration or custom deployment steps), there's a registry key EnableDiagnostics available for you to use.

Some basic MVC question

  1. In regular asp net I can run (debug) the application but I can either "view in browser" that gives me the option to view the application and write code on same time.

In MVC I can't find this option.

  1. What is the basic DATA MODEL for working with SQL DB.

I mean with no any framework (entity framework, Sub sonic, Link to SQL etc')

I look for basic application that works with data but with no fw.

  1. What is the popular DB framework that working with data.
  2.  I am looking on  mvc series


C# Soup To Nuts  (the best series ever)


I watch some of the MVC video, seems that the music store is good but I have to wait to the other part.

Does any one know and recommend   a Microsoft MVC tutorial?





Sys.Net.WebServiceFailedException: The server method '' failed with the following error:



Let's say we have 2 time consuming functions, aaa and aaa1 inside a aspx page.

        public static string aaa(int i)
            return i.ToString();

        public static string aaa1(int i)
            return i.ToString();



        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        <span id="displayspan"></span>
        <br />
        <input type="button" value=

Jscript error: Object does not support property or method


 Hi, i have little knowledge on javascript but i need to use this code get from somewhere for a jquery to work.

I face this "Jscript runtime error: Object does not support property or method" whenever im trying to run this page.

In my experience, im get this error msg 9 out of 10 times i use javascript in my system.

Im using Microsoft Visual web developer 2008, i wonder if this is related to my problem, i not sure there is anything i need to add as reference or update anything.

But anyway, in short, i just couldn't use javascript code when using this development tool because of this sort of error.

Anyway, it happen that last time i tried use the same type of jquery code in another project and it seems to work well without an error.

But now when im try to use it again in this recent project i created, it come out with this error and i have no idea how to solve it even look through google and this forum.

It doesn't really seems like its the code problem itself although im not sure, because any javascript code just couldn't work.

So below is my code that i need to use.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript" src=&quo

Web Site to Web Application Question


I've been building web sites and for my next project I will be creating a web application.  I use a 'BasePage' class in all my projects but, since web applications do not contain the 'App_Code' folder, what is the best place/practice for the 'BasePage' class?



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend