本文介绍了内部构造函数“可见”在集会之外。编译错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 我有编译问题。请看下面的代码。 我有一个基于三层的应用程序:一个数据层 (Foo.DataManager),一个业务层(Foo) .Kernel)和一个web 表示层(Foo.WebFiles)。数据层只能通过业务层访问,因此我不希望在表示层中引用 数据层。 在业务层中,我有一个名为CategoryItem的类, 有一个公共构造函数,它应该能够从表示层实例化和一个内部构造函数只能在同一个程序集中实例化。内部的构造函数有一个参数,它引用了一个类,位于数据层的 TransactionHandler。这是 问题开始的地方。当我在 CategoryItem类中添加这样的构造函数然后尝试编译ActionMenu类时,我得到 以下编译错误: 错误CS0012:类型''Foo.DataManager.TransactionHandler''是在未引用的程序集中定义的。你必须添加一个 引用汇编''Foo.WMS.DataManager''。 我真的不明白为什么我会收到这个错误,因为我明白了, 这根本不会有任何问题,因为对Foo.DataManager的 引用的构造函数是INTERNAL,甚至不会是 可用于表示层。这是编译器中的错误还是 我错过了什么?而且,我如何解决这个问题? 正如我之前所说,我真的不希望从 表示层引用到数据层。 顺便说一下,如果我将这个构造函数设置为 PROTECTED或PRIVATE,我仍然会得到相同的编译错误。 我感谢任何帮助。提前谢谢。 最好的问候 马丁 / ***头等舱位于Foo.Datamanager.dll * ******************* / 名称空间Foo.DataManager { 公共类TransactionHandler { 公共TransactionHandler(){ } } } / ***位于Foo.Kernel.dll的第二类,有*************** / / ***对Foo的引用。 Datamanager.dll上面。 *************** / 使用Foo.DataManager; 名称空间Foo.Kernel { 公共类CategoryItem { public CategoryItem(){ } 内部CategoryItem(TransactionHandler交易){ } } } / ***另一个没有引用Foo.Datamanager.dll ******* / / ***的类但想要实例化Foo.Kernel.CategoryItem * ****** / 使用Foo.Kernel; 名称空间Foo.WebFiles { public class ActionMenu:System.Web.UI.Page { private void AddItem(){ CategoryItem category = new CategoryItem(); } } } / ******************* ******************************* ***************** /Hi,I have a compiling problem. Please take a look at the code below.I have an application that is built upon three tiers: one data tier(Foo.DataManager), one business tier (Foo.Kernel) and one webpresentation tier (Foo.WebFiles). The data tier shall only beaccessible thru the business tier so I do NOT want a reference tothe data tier in the presentation tier.In the business tier I have a class with the name CategoryItem thathave one public constructor, that shall be able to instantiate fromthe presentation tier, and one internal constructor that shall onlybe instantiated from within the same assembly. The internalconstructor have an argument with a reference to a class,TransactionHandler, located in the data tier. And here is where theproblems begin. When I add a constructor like this in theCategoryItem class and then try to compile the ActionMenu class I getthe following compiling error:error CS0012: The type ''Foo.DataManager.TransactionHandler'' isdefined in an assembly that is not referenced. You must add areference to assembly ''Foo.WMS.DataManager''.I really do not understand why I get this error, cause as I see it,this shall not be any problem at all because the constructor with areference to the Foo.DataManager is INTERNAL and shall not even bevisible for the presentation tier. Is this a bug in the compiler orhave I missed something here? And, how do I come around this problem?As I said before I realy do NOT want a reference from thepresentation tier to the data tier.By the way, it doesn''t matter if I set this constructor to bePROTECTED or PRIVATE, I still get the same compiling error.I appreciate any help. Thank you in advance.Best regardsMartin/*** First class located in Foo.Datamanager.dll ********************/namespace Foo.DataManager {public class TransactionHandler {public TransactionHandler(){}}}/*** Second class located in Foo.Kernel.dll that has ***************//*** a reference to the Foo.Datamanager.dll above. ***************/using Foo.DataManager;namespace Foo.Kernel {public class CategoryItem {public CategoryItem(){}internal CategoryItem(TransactionHandler transaction) {}}}/*** Another class with NO reference to Foo.Datamanager.dll *******//*** but that wants to instantiate Foo.Kernel.CategoryItem *******/using Foo.Kernel;namespace Foo.WebFiles {public class ActionMenu : System.Web.UI.Page {private void AddItem(){CategoryItem category = new CategoryItem();}}}/************************************************** *****************/推荐答案 这篇关于内部构造函数“可见”在集会之外。编译错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-06 09:24