![](/img/trans.png)
[英]Visual C# Express 2010 Importing a project from Visual Studio
[英]Referring a type defined in other project in Visual Studio 2010/C#
我有一個通過子類化 Type 的 Fixed Point 類型(請參閱這篇文章)。 我可以將這個項目命名為 a.dll。
namespace System
{
public class FixedPointDataType : Type
{
public Boolean Signed { get; set; }
public int Width { get; set; }
public int IntegerWidth { get; set; }
public FixedPointDataType(Boolean signed = false, int width = 16, int integerWidth = 8)
{
Signed = signed;
Width = width;
IntegerWidth = integerWidth;
}
...
我有另一個項目 b.dll,它使用 a.dll 中的System.FixedPointDataType
。 在項目b中引用a.dll后,當我嘗試編譯項目b中的文件abc.cs時,出現此錯誤。
Error 2 'System.FixedPointDataType' is inaccessible due to its protection level
abc.cs
可能有什么問題?
我需要添加public
並使用命名空間給出全名 - System.FixedPointDataType
。 即使在修改后我也得到了錯誤,但是當我重建整個解決方案時,錯誤被刪除了。 感謝您的評論和回答。
您的 class 未聲明為public
; 或者是在您更改帖子並重建項目之前。
但我支持前面的評論,即您不應該將Type
子類化或將成員添加到命名空間System
。
如果這兩個項目在同一個解決方案中,請確保添加對項目的引用,而不僅僅是 DLL,即項目的 output。 如果您不添加對項目的引用,VS 將不知道構建解決方案的順序,並且您可能引用了過時的版本。
您的另一篇文章沒有告訴我們您為 FixedPoint class 使用的命名空間。
我建議您需要一個 Using 語句或完全限定類型名稱。
編輯:哦,我的時機不好!
如果您上面描述的代碼是准確的(確保您沒有從 class 中丟失“public”?),也許這是您使用 System 命名空間的問題,雖然我沒有證據,可能是個特例。
看看如果你改變命名空間會發生什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.