Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2006

Tip: Looking for answers? Try searching our database.

Bug in C# compiler

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vivek Thakur - 17 Jul 2006 11:15 GMT
Hi,

I 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
Signature

Vivek Thakur (MCP)
www.vivekthakur.com

Joanna Carter [TeamB] - 17 Jul 2006 11:52 GMT
| But when i compile this code, i get an error saying:
|
[quoted text clipped - 7 lines]
| 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

Signature

Joanna Carter [TeamB]
Consultant Software Engineer

Vivek Thakur - 17 Jul 2006 12:34 GMT
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?
Signature

Vivek Thakur (MCP)
www.vivekthakur.com

> | But when i compile this code, i get an error saying:
> |
[quoted text clipped - 14 lines]
>
> Joanna
Barry Kelly - 17 Jul 2006 13:19 GMT
> 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
[quoted text clipped - 3 lines]
> 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

Signature

http://barrkel.blogspot.com/

Vivek Thakur - 17 Jul 2006 13:34 GMT
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).

Signature

Vivek Thakur (MCP)
www.vivekthakur.com

> > 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
[quoted text clipped - 12 lines]
>
> -- Barry
Barry Kelly - 17 Jul 2006 14:16 GMT
> 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).

ASP.NET applications follow this model.

-- Barry

Signature

http://barrkel.blogspot.com/

Vivek Thakur - 17 Jul 2006 13:42 GMT
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

Signature

Vivek Thakur (MCP)
www.vivekthakur.com

> > 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
[quoted text clipped - 12 lines]
>
> -- Barry
Barry Kelly - 17 Jul 2006 14:17 GMT
> 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

Signature

http://barrkel.blogspot.com/

Vivek Thakur - 17 Jul 2006 14:34 GMT
So basically even when we have DLLs in the /bin directory, the project wont
compile. i still do not understand this.
Signature

Vivek Thakur (MCP)
www.vivekthakur.com

> > Also, one more thing as far as copying the DLLs is concerned:
> >
[quoted text clipped - 7 lines]
>
> -- Barry
Amry - 18 Jul 2006 08:25 GMT
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.

> So basically even when we have DLLs in the /bin directory, the project wont
> compile. i still do not understand this.
[quoted text clipped - 13 lines]
> >
> > -- Barry
Vivek Thakur - 17 Jul 2006 14:37 GMT
i did some googling and found that this is some bug. see a related post:

http://www.dotnet247.com/247reference/msgs/56/284237.aspx
Signature

Vivek Thakur (MCP)
www.vivekthakur.com

> > Also, one more thing as far as copying the DLLs is concerned:
> >
[quoted text clipped - 7 lines]
>
> -- Barry
Markus Ewald - 18 Jul 2006 08:38 GMT
Vivek Thakur schrieb:
> Also, one more thing as far as copying the DLLs is concerned:
>
[quoted text clipped - 6 lines]
>
> 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-
Vivek Thakur - 18 Jul 2006 18:26 GMT
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 ?
Signature

Vivek Thakur (MCP)
www.vivekthakur.com

> Vivek Thakur schrieb:
> > Also, one more thing as far as copying the DLLs is concerned:
[quoted text clipped - 22 lines]
>
> -Markus-

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.