Last post Sep 18, 2006 05:25 AM by Jasson_King
Sep 11, 2006 07:45 PM|abhigad|LINK
[ERROR: Object does not contain the definition for method /property]
I got this error while developing three tire ASP.NETbase web application.
Suppose you have a class library in the same solution as your web app. Name the class library as ReferMe and rename the class in it as Getit [as shown below]
public class Getit
public string Name()
return "this is a test";
// END CODE
Build this class project [class library].
Now add this library in your web project [using add reference /project]. Import this library in a code behind file for a webpage say default.aspx.cs [as shown below]
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
Getit g = new Getit();
This code will work and default.aspx will display the "string this is test" in browser.
Now add another page to the same web project as Getit.aspx. and change the code behind file Getit.aspx.cs [as shown below]
public partial class Getit : System.Web.UI.Page
When you run the default.aspx [view it in browser] - following error message will popup
Getit does not contain the definition for Name [i.e. g.Name() will not work].
If you comment out following lines in default.aspx.cs i.e. code behind for the default.aspx
Default.aspx will build successfully. This is weird but true. What is happening is that the public partial class Getit defination is conflicting with ReferMe.Getit class library. Change any one of them i.e. Getit.aspx to say Getit1.aspx or class Getit in
ReferMe namespace to Getit1 resolve the said error.
So be careful in naming your webpages and classes in class library projects.
Sep 11, 2006 10:53 PM|Jasson_King|LINK
You get the error message becuse you have two classes with the same name.If you change one of them,you will get the right result.
Generally speaking,you should define a different namespace and define your classes in the namespace.If the namespace is different,even though the class name is same,there is name conflict.
Sep 14, 2006 12:40 PM|abhigad|LINK
Well the confusing thing is that it’s not only in different namespace but also in different project [dll]. As explained in my example, one class is in C# class library project, which is compiled and build separately.
Then it is added to the web project. Since we have a class [a webpage with same name and hence code behind file with partial class] in our web project - this conflict. I am wondering what will happen if some one is using a third party dll, and by accident
or chance has same class name in original web project. I guess reflection is the only way out.
Anyway, it took us a while to figure this out. In ASP 2.0 everything gets compiled into one dll hence this problem
Sep 15, 2006 02:49 PM|cykophysh|LINK
Sep 15, 2006 02:58 PM|cykophysh|LINK
Sep 18, 2006 05:25 AM|Jasson_King|LINK