开发者

Class library reference problem

I am building a class library and using its default namespace as "System". There suppose I am creating a generic data structure say PriorityQueue and putting it under System.Collections.Generic namespace.

Now when I am referencing that library from another project, I can't see PriorityQueue under "System.Collections.Generic" namespace anymore. Though the library is referenced in that project I can not access开发者_JS百科 any of the classes in it.

My question was mscorlib and System.dll share similar namespaces, but still classes from both the assembly is accessible, but why can't mine? If I put a public class under System.Collections.Generic namespace in my class library and refer that library in a project and use a statement like "using System.Collections.Generic", still why I can't access my class there?

This was an experimentation I did, I know using System namespace is not encouraged in custom class library, but I want to know the reason behind why I can't access my class in this special case?

Please someone shed some light on it.

PS: Last time I asked similar question but put it wrongly, so people got misunderstood and I didn't get my answer. This time I am trying to put it correctly as far as I can. Sorry for the misunderstanding.


The problem appears to arise when you use a "Project Reference" rather than an "Assembly Reference".

Use an "assembly Reference".

This is such a bad idea that I am reluctant to delve into the underlying reasons.

Update

I am guessing that when you use a project reference (from your System namespace project), the issue arises as the build does not know that it should resolve the dependency from your referenced project, but instead it attempts to resolve it from one of the assemblies that is already referenced i.e. System.dll. It obviously does not exist in System.dll. If you add a direct reference to a built version of your dll, the build will be able to resolve it.


I just tested out some code, and I can extend the System namespace in my own project and then call the new classes from some other project in the same solution. I don't know why are you not able to do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜