|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Bug in C# compilerI think there is a bug in VS 2003 as well as VS 2005 C# compiler. Let me explain: I have created 3 projects in my solution: ClassLibrary1, ClassLibrary2 and ClassLibrary3. Now each of these libraries has a single public class in it (classes r named as A, B and C respectively) and the class defined in 2nd library is derived from the class in first library as: ************ //in ClassLibrary1 public class A { //constructor } //in ClassLibrary2 using ClassLibrary1; public class B : A { //public constructor } //in ClassLibrary2 using ClassLibrary2; public class C : A { //public constructor public C() { B b1 = new B(); } } Here, ClassLibrary1 is referenced in project ClassLibrary2 and ClassLibrary2 is referenced in project ClassLibrary3. Also, Class C defined in ClassLibrary3 is using an object of B in it. But when i compile this code, i get an error saying: e:\ClassLibrary3\bin\Debug\ClassLibrary2.dll Referenced class 'ClassLibrary2.B' has base class or interface 'ClassLibrary1.A' defined in an assembly that is not referenced. You must add a reference to assembly 'ClassLibrary1'. According to me, we dont need to reference ClassLibrary1 as it is already being referenced by ClassLibrary2 so this should compile fine. But i may be wrong. I owuld be grateful if someone could shed light on this. Thanks Vivek "Vivek Thakur" <vivekatvivekthakur(donotspam)com> a écrit dans le message de news: F90E6A6E-43FF-4EE8-B477-3F30C644E***@microsoft.com...| But when i compile this code, i get an error saying: According to the compiler, you are wrong and it is right. There is no bug in | | e:\ClassLibrary3\bin\Debug\ClassLibrary2.dll Referenced class | 'ClassLibrary2.B' has base class or interface 'ClassLibrary1.A' defined in an | assembly that is | | not referenced. You must add a reference to assembly 'ClassLibrary1'. | | According to me, we dont need to reference ClassLibrary1 as it is already | being referenced by ClassLibrary2 so this should compile fine. But i may be | wrong. the compiler, references are not inferred, they have to be explicit. Joanna -- Joanna Carter [TeamB] Consultant Software Engineer Thanks Joanna,
But i have a project where this is working. If i do the same thing in visual studio 2005 and instead of class library3 i create a WebService project and add ClassLibrary2's reference, then it works. Please let me know where am i wrong in my example. Why do i need to reference 1st project when i am not using it at all? And why does the same thing works in VS 2005 if the third project is a WebService? Show quote "Joanna Carter [TeamB]" wrote: > "Vivek Thakur" <vivekatvivekthakur(donotspam)com> a écrit dans le message de > news: F90E6A6E-43FF-4EE8-B477-3F30C644E***@microsoft.com... > > | But when i compile this code, i get an error saying: > | > | e:\ClassLibrary3\bin\Debug\ClassLibrary2.dll Referenced class > | 'ClassLibrary2.B' has base class or interface 'ClassLibrary1.A' defined in > an > | assembly that is > | > | not referenced. You must add a reference to assembly 'ClassLibrary1'. > | > | According to me, we dont need to reference ClassLibrary1 as it is already > | being referenced by ClassLibrary2 so this should compile fine. But i may > be > | wrong. > > According to the compiler, you are wrong and it is right. There is no bug in > the compiler, references are not inferred, they have to be explicit. > > Joanna > > -- > Joanna Carter [TeamB] > Consultant Software Engineer > > > Vivek Thakur <vivekatvivekthakur(donotspam)com> wrote:
> But i have a project where this is working. If i do the same thing in visual Webservices use a different model for referencing DLLs, since they are> studio 2005 and instead of class library3 i create a WebService project and > add ClassLibrary2's reference, then it works. > > Please let me know where am i wrong in my example. Why do i need to > reference 1st project when i am not using it at all? And why does the same > thing works in VS 2005 if the third project is a WebService? ASP.NET pages. All assemblies referenced by your WebService get copied to the Bin directory in the website. There is no project file with a "references" list like there is for class libraries. Instead, the ASP.NET compiler will reference all the assemblies in the Bin directory automatically when it's compiling your webservice. -- Barry Thanks Berry,
But do Web projects also use the same model? even if the third project is a website, i see the same results (as when i create a webservice). Show quote "Barry Kelly" wrote: > Vivek Thakur <vivekatvivekthakur(donotspam)com> wrote: > > > But i have a project where this is working. If i do the same thing in visual > > studio 2005 and instead of class library3 i create a WebService project and > > add ClassLibrary2's reference, then it works. > > > > Please let me know where am i wrong in my example. Why do i need to > > reference 1st project when i am not using it at all? And why does the same > > thing works in VS 2005 if the third project is a WebService? > > Webservices use a different model for referencing DLLs, since they are > ASP.NET pages. All assemblies referenced by your WebService get copied > to the Bin directory in the website. There is no project file with a > "references" list like there is for class libraries. Instead, the > ASP.NET compiler will reference all the assemblies in the Bin directory > automatically when it's compiling your webservice. > > -- Barry > > -- > http://barrkel.blogspot.com/ > Vivek Thakur <vivekatvivekthakur(donotspam)com> wrote:
> Thanks Berry, ASP.NET applications follow this model.> > But do Web projects also use the same model? even if the third project is a > website, i see the same results (as when i create a webservice). -- Barry Also, one more thing as far as copying the DLLs is concerned:
In VS 2003, when i compile ClassLibrary3 project, i can see the assemblies from ClassLibrary2 and ClassLibrary1 (too) even when i have not referenced ClassLibrary1. So assemblies are copied in the bin folder of class library 3 but since i get an error the project does not compile. This is confusing me. Let me know yr thgts on this. thanks again Show quote "Barry Kelly" wrote: > Vivek Thakur <vivekatvivekthakur(donotspam)com> wrote: > > > But i have a project where this is working. If i do the same thing in visual > > studio 2005 and instead of class library3 i create a WebService project and > > add ClassLibrary2's reference, then it works. > > > > Please let me know where am i wrong in my example. Why do i need to > > reference 1st project when i am not using it at all? And why does the same > > thing works in VS 2005 if the third project is a WebService? > > Webservices use a different model for referencing DLLs, since they are > ASP.NET pages. All assemblies referenced by your WebService get copied > to the Bin directory in the website. There is no project file with a > "references" list like there is for class libraries. Instead, the > ASP.NET compiler will reference all the assemblies in the Bin directory > automatically when it's compiling your webservice. > > -- Barry > > -- > http://barrkel.blogspot.com/ > Vivek Thakur <vivekatvivekthakur(donotspam)com> wrote:
> Also, one more thing as far as copying the DLLs is concerned: IIRC with VS 2003, there was a project file for ASP.NET applications. > > In VS 2003, when i compile ClassLibrary3 project, i can see the assemblies > from ClassLibrary2 and ClassLibrary1 (too) even when i have not referenced > ClassLibrary1. So assemblies are copied in the bin folder of class library 3 > but since i get an error the project does not compile. I don't recall all the details, it is some years since I used VS 2003. -- Barry So basically even when we have DLLs in the /bin directory, the project wont
compile. i still do not understand this. Show quote "Barry Kelly" wrote: > Vivek Thakur <vivekatvivekthakur(donotspam)com> wrote: > > > Also, one more thing as far as copying the DLLs is concerned: > > > > In VS 2003, when i compile ClassLibrary3 project, i can see the assemblies > > from ClassLibrary2 and ClassLibrary1 (too) even when i have not referenced > > ClassLibrary1. So assemblies are copied in the bin folder of class library 3 > > but since i get an error the project does not compile. > > IIRC with VS 2003, there was a project file for ASP.NET applications. > I don't recall all the details, it is some years since I used VS 2003. > > -- Barry > > -- > http://barrkel.blogspot.com/ > If I am not mistaken, for web projects, every DLL contained in its bin
directory will be automatically referred and loaded, whereas for other types of projects, you must explicitly refer to the DLL you want in order for it to compile. Vivek Thakur (attherate donotspam) wrote: Show quote > So basically even when we have DLLs in the /bin directory, the project wont > compile. i still do not understand this. > -- > Vivek Thakur (MCP) > www.vivekthakur.com > > > "Barry Kelly" wrote: > > > Vivek Thakur <vivekatvivekthakur(donotspam)com> wrote: > > > > > Also, one more thing as far as copying the DLLs is concerned: > > > > > > In VS 2003, when i compile ClassLibrary3 project, i can see the assemblies > > > from ClassLibrary2 and ClassLibrary1 (too) even when i have not referenced > > > ClassLibrary1. So assemblies are copied in the bin folder of class library 3 > > > but since i get an error the project does not compile. > > > > IIRC with VS 2003, there was a project file for ASP.NET applications. > > I don't recall all the details, it is some years since I used VS 2003. > > > > -- Barry > > > > -- > > http://barrkel.blogspot.com/ > > i did some googling and found that this is some bug. see a related post:
http://www.dotnet247.com/247reference/msgs/56/284237.aspx Show quote "Barry Kelly" wrote: > Vivek Thakur <vivekatvivekthakur(donotspam)com> wrote: > > > Also, one more thing as far as copying the DLLs is concerned: > > > > In VS 2003, when i compile ClassLibrary3 project, i can see the assemblies > > from ClassLibrary2 and ClassLibrary1 (too) even when i have not referenced > > ClassLibrary1. So assemblies are copied in the bin folder of class library 3 > > but since i get an error the project does not compile. > > IIRC with VS 2003, there was a project file for ASP.NET applications. > I don't recall all the details, it is some years since I used VS 2003. > > -- Barry > > -- > http://barrkel.blogspot.com/ > Vivek Thakur schrieb:
> Also, one more thing as far as copying the DLLs is concerned: The files are always being copied because they are required to run the > > In VS 2003, when i compile ClassLibrary3 project, i can see the assemblies > from ClassLibrary2 and ClassLibrary1 (too) even when i have not referenced > ClassLibrary1. So assemblies are copied in the bin folder of class library 3 > but since i get an error the project does not compile. > > This is confusing me. Let me know yr thgts on this. > > thanks again > application. For example, if A uses B and B uses C, then all three assemblies will end up int A's bin folder. References don't really have anything to do with files. If B does not use any of the types of C in its public interface (by deriving or expecting them as parameter), then B could be referenced needing another reference to C (even if it is ultimately required in the bin folder) However, if B makes use of the types of C in its public interface, then any assembly that wants to use those methods or classes that are making use of C's public types will need to also reference C in addition to B. -Markus- thanks for the reply..
i know all these answers, but just wanted to confirm whether this is by design or a bug in C# compiler. what forces me to think like this is the fact that a similar problem is there which is a bug. see the post below: http://www.dotnet247.com/247reference/msgs/56/284237.aspx could this bug be the reason or this is completely un related ? Show quote "Markus Ewald" wrote: > Vivek Thakur schrieb: > > Also, one more thing as far as copying the DLLs is concerned: > > > > In VS 2003, when i compile ClassLibrary3 project, i can see the assemblies > > from ClassLibrary2 and ClassLibrary1 (too) even when i have not referenced > > ClassLibrary1. So assemblies are copied in the bin folder of class library 3 > > but since i get an error the project does not compile. > > > > This is confusing me. Let me know yr thgts on this. > > > > thanks again > > > > The files are always being copied because they are required to run the > application. For example, if A uses B and B uses C, then all three > assemblies will end up int A's bin folder. > > References don't really have anything to do with files. If B does not > use any of the types of C in its public interface (by deriving or > expecting them as parameter), then B could be referenced needing another > reference to C (even if it is ultimately required in the bin folder) > > However, if B makes use of the types of C in its public interface, then > any assembly that wants to use those methods or classes that are making > use of C's public types will need to also reference C in addition to B. > > -Markus- > |
|||||||||||||||||||||||