
[英]C# MSBuild Conditionally Compile Project to not Include Partial Class referencing Nuget
[英]C# Compile fails when referencing method in partial class
建立C#专案时,我目前收到CS1061错误。 此错误仅发生在我的代码中非常特定的位置。
错误CS1061描述: '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?).
我有两个文件, main.cs
和partial.cs
。 partial.cs
是一个局部类的main.cs
。 main.cs
内部包含两个类,即main
类和helper
类。
当helper
类实例化main
类并调用partial.cs
文件中定义的main
类的方法时,将引发该错误。
据我了解,这应该不是问题。 main
类分为两个文件,但在编译时将部分类组合在一起。
这个问题似乎非常相似,但是他的解决方案对我不起作用。 这两个文件都包含在项目中。 单独文件中的ASP.NET C#部分类不起作用CS1061
有任何想法吗?
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
}
}
}
编辑:似乎它并不特定于在助手类中被调用的方法。 在构建期间,在另一个类中引发了另一个错误。 此类的设置方法与上一类相同,但没有额外的帮助程序类。 当部分类的主要部分调用另一个文件中的部分类中声明的方法时,此方法将失败。
我发现了问题。 该错误实际上是在另一个具有此类链接的项目中。 具有链接的项目不包含指向部分类的链接,因此这些方法不可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.