开发者

c# Namespace already contains a definition for inherited class so how to add a constructor

开发者 https://www.devze.com 2023-04-08 15:51 出处:网络
I am carefully treading into WCF attempting to follow tutorials and convert my ASMX project to a new WCF project and I\'ve stumbled upon a mystery about coding of my constructor in WCF.

I am carefully treading into WCF attempting to follow tutorials and convert my ASMX project to a new WCF project and I've stumbled upon a mystery about coding of my constructor in WCF.

My ASMX webservice allowed me to have a constructor (see: same name, no return value):

namespace sdkTrimFileServiceASMX
{
public class FileService : Syste开发者_运维百科m.Web.Services.WebService
{
    Database db;
    string g_EventSource = "CBMI-TrimBroker";
    string g_EventLog = "Application";
    public FileService()
    {
        try
        {
            if (!EventLog.SourceExists(g_EventSource))
                EventLog.CreateEventSource(g_EventSource, g_EventLog);
        }
        catch (InvalidOperationException e)
        {
            e.ToString();
        }
    }

My attempt to convert this to a WCF service app gives this compiler complaint:

The namespace 'sdkTRIMFileServiceWCF' already contains a definition for 'FileService'   

Here is the WCF code (beginning snippet):

namespace sdkTRIMFileServiceWCF
{
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class FileService : IFileService                             // err msg points to this line
{
    Database db;
    string g_EventSource = "CBMI-TrimBroker";
    string g_EventLog = "Application";

    public FileService()
    {
        try
        {
            if (!EventLog.SourceExists(g_EventSource))
                EventLog.CreateEventSource(g_EventSource, g_EventLog);
        }
        catch (InvalidOperationException e)
        {
            e.ToString();
        }
    }


This isn't related to the existence of the constructor. I am fairly sure this is a copy/paste error- perform a search for the word "FileService" in any files in your application and you will find another class or a namespace declaration with that name (in the same namespace).


Some things you could do:

  • do right mouse click > Find references on FileService.
  • Try a full search (ctrl+f) and search for FileService.
  • Check any partial classes for a second constructor.
  • Try clean solution and then rebuild the solution, see if this makes any difference.
  • ...
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号