1

I have created an empty web application project in visual studio 2010 and have addd the following model class:

namespace MessageTest
{
    public class Message
    {
        private String msg;

        public Message(String m)
        {
            this.msg = m;
        }

        public String getMessage()
        {
            return this.msg;
        }

        public void setMessage(String m)
        {
            this.msg = m;
        }

        public bool isEmpty()
        {
            return (this.msg.Length == 0);
        }
    }
}

A very simple model class.....but I keep getting the following error when trying to build:

Missing partial modifier on declaration of type 'MessageTest.Message'; another partial declaration of this type exists c:\users\d\documents\visual studio 2010\Projects\MessageTest\MessageTest\Message.cs

EDIT: Here is where I use the Class:

namespace MessageTest
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            Message m = new Message(UserMessage.Text);

            if (m.isEmpty())
            {
                //alert user
            }
            else
            {
                //submit data
                SubmitData(m);
            }


        }

        private void SubmitData(Message msg)
        {
            //submit the data to database    
            var dataContext = new DataClasses1DataContext();


        }
    }
}

EDIT:

My .dbml has a table in it called Messages:

Messages
ID (PK) int(10) auto_inc
Message varchar (100)

Could this be the issue?

tomfanning
  • 9,552
  • 4
  • 50
  • 78
user559142
  • 12,279
  • 49
  • 116
  • 179
  • 5
    Seems like you have another type with the same name **Message** that exists in the solution. Search for `Message` in the whole solution. – oleksii Dec 16 '11 at 11:25
  • I tried changing the class name to something else and it still gave the same error – user559142 Dec 16 '11 at 11:28
  • Have you searche you whole project? Can you post the code where you try to create an instance of this message? – CSharpened Dec 16 '11 at 11:30
  • From the error description I can say that there is another copy of same project is included. Exclude and remove that copy from the current project. – KV Prajapati Dec 16 '11 at 11:37
  • Are you using WCF? And did you use the SvcUtil.exe tools? – Keerigan Jun 12 '12 at 13:50

4 Answers4

2
namespace MessageTest
{
    public class Message
    {

Change to

namespace MessageTest
{
    public partial class Message
    {

Missing partial modifier on declaration of type 'MessageTest.Message'

Stewart_R
  • 13,764
  • 11
  • 60
  • 106
iCon
  • 29
  • 2
0

I've had a similar issue in my project. I've added partial in

public partial class Form1 : Form

and it solved my issue.

Roman
  • 1,727
  • 1
  • 20
  • 28
0

I don't know if my answer apply to your problem exactly or not.

When I develop website or web application, I sometime go through unexpected error that sometime surely can't be solved by merely checking your code each time.

So I follow the following pattern before looking code again -

  1. Since all compiled websites goes in Temporary ASP.NET directory, so delete all files and folders from there. On my system for .NET Framework 4.0, the path is - C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files It is because there exist pre-compiled different copies of same classes in different folders and they sometime conflict issues.

  2. Delete Visual Studio 2010 folder in My Documents.

** Last for your case, change file name and rebuild it. It will create new compiled file and will mostly solve the problem.

Vikram Singh Saini
  • 1,749
  • 3
  • 22
  • 42
0

I couldn't able to reproduce this issue. Try creating a new project in a non-default location(say D: drive) and check out. Hope it may solve the issue.

Mohan Kumar
  • 6,008
  • 6
  • 28
  • 36