Abstract Class giving error

E

erin.sebastian

Hello Everyone,
This is my first attempt at coding using an abstract class and i am
getting an error i can't figure out. Here is the back ground.

I have a project that contains an abstract class, it's namespace is
CIG.Intranet.Commons.User and it has 2 methods in it
public abstract getPropertiesHash (string userName) and
public abstract getPropertiesXml (string userName) adn the class name
is called
CPUser.cs

I have a project that contains 2 implementation classes, their
namespace is
CIG.Intranet.SharePoint.User this project references the abstact class
and inherits from it and they both contain the methods
public override Hashtable getPropertiesHash(string userName) and
public override XmlNode getPropertiesXml(string userName) the class
names are
Sharepoint2003User.cs and
Sharepoint2001User.cs and the headers are as follows

public class SharePoint2001User : CPUser
public class SharePoint2003User : CPUser

I have a project that contains a test form, this project references
both the abstract and implementation class and has code to actually
test these classes. the code is as follows

CPUser user;
user = new SharePoint2003User();

Console.WriteLine(user.getPropertiesXml("cigdev\\sharepoint"));

If i have just the first 2 lines in this class and run it everything is
fine, once i add the line that uses the method i get a
MissingMethodException and it says it can't find the getPropertiesXml
method, if i try and use the getPropertiesHash method i also get the
MissingMethodException... i should also note that my intellisence shows
both of these methods.

I tried creating a very simple test app and followed the same procedure
i did as above and it worked fine... i have no idea how to fix this or
what is wrong. can anybody PLEASE help me??

Thanks so much in advance!!!!!
 
K

Kevin Spencer

How about:

SharePoint2003User user;
user = new SharePoint2003User();

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
J

James Curran

Hard to say given the lack of real code in your message. I've tried to
piece together what you're described, and come up with this, which works as
expected:

public abstract class CPUser
{
public abstract Hashtable getPropertiesHash (string userName);
public abstract XmlNode getPropertiesXml (string userName) ;
}

public class SharePoint2001User : CPUser
{
public override Hashtable getPropertiesHash(string userName)
{
Console.WriteLine("SharePoint2001User.getPropertiesHash({0})", userName);
return new Hashtable();
}
public override XmlNode getPropertiesXml(string userName)
{
Console.WriteLine("SharePoint2001User.getPropertiesXml({0})", userName);
return new XmlDocument();
}
}

public class SharePoint2003User : CPUser
{
public override Hashtable getPropertiesHash(string userName)
{
Console.WriteLine("SharePoint2003User.getPropertiesHash({0})", userName);
return new Hashtable();
}
public override XmlNode getPropertiesXml(string userName)
{
Console.WriteLine("SharePoint2003User.getPropertiesXml({0})", userName);
return new XmlDocument();
}
}

public class MyClass
{
public static void Main()
{

CPUser user;
user = new SharePoint2003User();

Console.WriteLine(user.getPropertiesXml("cigdev\\sharepoint"));
}
}
 
E

erin.sebastian

Hey Kevin,
Thanks so much for your reply, i have tried this approach as well and
it also throws the same error. Are there other reasons to why it would
give this error other than that there is a missing method? I don't know
what to do because i've tried recreating my test project many times and
i've tried scaling down the abstract and implementation projects to
bare bones and i still get this error.
Thanks
 
B

Bill Butler

Hey Kevin,
Thanks so much for your reply, i have tried this approach as well and
it also throws the same error. Are there other reasons to why it would
give this error other than that there is a missing method? I don't know
what to do because i've tried recreating my test project many times and
i've tried scaling down the abstract and implementation projects to
bare bones and i still get this error.
Thanks

Post the Barebones implementation to the group and we will find the problem faster.
It should REALLY be barebones though.

Bill
 
E

erin.sebastian

ok here goes.
A few things to note. The abstract class -CIG.Intranet.Commons.User is
in it's own project. The implementation class
CIG.Intranet.Sharepoint.User is in it's own project and the test
project is in it's own project. I have tried adding the projects under
one solution and also just having a reference to the dll and both ways
i still get the same error.

Thanks


The abstract class -

using System;
using System.Xml;
using System.Collections;

namespace CIG.Intranet.Commons.User
{
/// <summary>
/// Summary description for CPUser.
/// </summary>
public abstract class CPUser
{
public CPUser()
{
//
// TODO: Add constructor logic here
//
}

public abstract Hashtable getPropertiesHash(string userName);
public abstract XmlNode getPropertiesXml(string userName);
}
}


The implementation class (SharePoint2003User) - the one i use in my
example

using System;
using CIG.Intranet.Commons.User;
using System.Xml;
using System.IO;
using System.Collections;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint.Portal.Topology;
using Microsoft.SharePoint.Portal.UserProfiles;

using CIG.Intranet.SharePoint.Commons;

namespace CIG.Intranet.SharePoint.User
{
/// <summary>
/// Summary description for SharePoint2003User.
/// </summary>
public class SharePoint2003User : CPUser
{
public SharePoint2003User() : base()
{
//
// TODO: Add constructor logic here
//
}

public override Hashtable getPropertiesHash(string userName)
{
return null;
}
public override XmlNode getPropertiesXml(string userName)
{
return null;
}
}
}

the implementation class (SharePoint2001User) - i am using 2003 in my
example but i put this here just in case..

using System;
using System.Xml;
using System.Collections;
using CIG.Intranet.Commons.User;
using CIG.Intranet.SharePoint.Commons;

namespace CIG.Intranet.SharePoint.User
{
/// <summary>
/// Summary description for SharePoint2001User.
/// </summary>
public class SharePoint2001User : CPUser
{
public SharePoint2001User() : base()
{
//
// TODO: Add constructor logic here
//
}

public override Hashtable getPropertiesHash(string userName)
{
return null;
}

public override XmlNode getPropertiesXml(string userName)
{
return null;
}


}
}


My test project -

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CIG.Intranet.SharePoint.User;
using CIG.Intranet.Commons.User;

namespace testUser
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 16);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Press Me!!!!";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(112, 61);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "TEST";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
try
{
Application.Run(new Form1());
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}

private void button1_Click(object sender, System.EventArgs e)
{
SharePoint2003User user;
user = new SharePoint2003User();
Console.WriteLine(user.getPropertiesXml("cigdev\\sharepoint"));
}
}
}
 
J

James Curran

If I put all this code into one file, it runs fine. I'm gonna guess
that you actually have it in multiple assemblies, and further guess that you
have an older version of one of them that's being loaded at runtime instead
of the new version.



ok here goes.
A few things to note. The abstract class -CIG.Intranet.Commons.User is
in it's own project. The implementation class
CIG.Intranet.Sharepoint.User is in it's own project and the test
project is in it's own project. I have tried adding the projects under
one solution and also just having a reference to the dll and both ways
i still get the same error.

Thanks


The abstract class -

using System;
using System.Xml;
using System.Collections;

namespace CIG.Intranet.Commons.User
{
/// <summary>
/// Summary description for CPUser.
/// </summary>
public abstract class CPUser
{
public CPUser()
{
//
// TODO: Add constructor logic here
//
}

public abstract Hashtable getPropertiesHash(string userName);
public abstract XmlNode getPropertiesXml(string userName);
}
}


The implementation class (SharePoint2003User) - the one i use in my
example

using System;
using CIG.Intranet.Commons.User;
using System.Xml;
using System.IO;
using System.Collections;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint.Portal.Topology;
using Microsoft.SharePoint.Portal.UserProfiles;

using CIG.Intranet.SharePoint.Commons;

namespace CIG.Intranet.SharePoint.User
{
/// <summary>
/// Summary description for SharePoint2003User.
/// </summary>
public class SharePoint2003User : CPUser
{
public SharePoint2003User() : base()
{
//
// TODO: Add constructor logic here
//
}

public override Hashtable getPropertiesHash(string userName)
{
return null;
}
public override XmlNode getPropertiesXml(string userName)
{
return null;
}
}
}

the implementation class (SharePoint2001User) - i am using 2003 in my
example but i put this here just in case..

using System;
using System.Xml;
using System.Collections;
using CIG.Intranet.Commons.User;
using CIG.Intranet.SharePoint.Commons;

namespace CIG.Intranet.SharePoint.User
{
/// <summary>
/// Summary description for SharePoint2001User.
/// </summary>
public class SharePoint2001User : CPUser
{
public SharePoint2001User() : base()
{
//
// TODO: Add constructor logic here
//
}

public override Hashtable getPropertiesHash(string userName)
{
return null;
}

public override XmlNode getPropertiesXml(string userName)
{
return null;
}


}
}


My test project -

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CIG.Intranet.SharePoint.User;
using CIG.Intranet.Commons.User;

namespace testUser
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 16);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Press Me!!!!";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(112, 61);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "TEST";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
try
{
Application.Run(new Form1());
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}

private void button1_Click(object sender, System.EventArgs e)
{
SharePoint2003User user;
user = new SharePoint2003User();
Console.WriteLine(user.getPropertiesXml("cigdev\\sharepoint"));
}
}
}
 
E

erin.sebastian

Your Guess is correct James.... I just realized that another programmer
had been using a common file in one of the projects and had dragged the
dll into the GAC. This caused all the ruckus, thanks for ALL OF YOUR
HELP!!! i really appreciate it!
Erin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top