Question

I am currently getting a CS1061 error when building my C# project. This error only occurs in a very specific spot in my code.

Error CS1061 description: 'type' does not contain a definition for 'member' and no extension method 'name' accepting a first argument of type 'type' could be found (are you missing a using directive or an assembly reference?).

I have two files, a main.cs and a partial.cs. partial.cs is a partial class of main.cs. main.cs contains two classes inside of it, the main class and the helper class.

The error gets thrown when the helper class instantiates the main class and makes a call to a method of the main class that is defined in the partial.cs file.

From my understanding, this should not be an issue. The main class is split up over the two files, but during compile time the partial classes are combined.

This question seems to be very similar, but his resolution doesn't work for me. Both files are included in the project. ASP.NET C# partial class in separate files not working CS1061

Any ideas?

main.cs

namespace Price.WS
{
    public partial class Main : BaseWebService
    {
        public Main()
        {
            //CODEGEN: This call is required by the ASP.NET Web Services Designer
            InitializeComponent();
        }

        private DataSet _TestMethod()
        {
            //Stuff     
        }          
    }

    public class Helper: IExchangeable
    {
        public void Test()
        {             
            using (Main main = new Main())
            {
                main.TestMethod();  //This is where the error gets thrown. The compiler doesn't see TestMethod() as a method of main
            }
        }
    } 
}

Partial.cs:

namespace Price.WS
{
    public partial class Main : BaseWebService
    {        
        [WebMethod()]
        public DataSet TestMethod()
        {
            //Stuff
            return _TestMethod();   
            //Stuff
        }          
    }      
}

Edit: It seems that it is not specific to methods being called in helper classes. There is another error being thrown during the build in a separate class. This class is set up in the same way as the last, except it doesn't have the extra helper class. This one fails when the main part of the partial class calls a method declared in the partial class in another file.

Était-ce utile?

La solution

I have discovered the issue. The error is actually in another project that has a link to this class. The project that has the link doesn't contain links to the partial classes, thus the methods were not available.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top