[英]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.