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 2007

Tip: Looking for answers? Try searching our database.

Strange Compile Problem With Generics

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brett - 30 Jul 2007 16:14 GMT
I've tried to debug this every way I can think of, but I can't figure out
this strange compile problem I am having.  Any help is greatly appreciated.

I have a generic collection class that inherits from
System.Collections.ObjectModel.Collection(Of T) called
MatrixGenericCollectionBase (Matrix is the name of our project).  Despite
it's name it is actually an instantiable class that is used widely in our
application to hold objects of many types.  There is some additional
functionality in the class but for the most part it is just a normal
implementation of a generic collection, not a ton of additional code.

In one instance I need a type specific collection because I need to add a
function at the collection level that is specific for that type.  In this
case I have created a new class that inherits from
MatrixGenericCollectionBase(Of TypeX) and named the new collection class
TypeXCollection.  The only code this class contains is the new function,
which basically just loops through the collection and looks for specific
members based on some parameters passed in.

This compiles and runs fine when I compile through Visual Studio on my local
machine.  It also compiles fine when I run my nAnt build scripts on my local
machine.  It compiles fine when compiled in the VS IDE on the build server.
BUT, it fails when the nAnt build script is run on the build server.  The
compile error I receive is "error BC30311: Value of type 'T' cannot be
converted to 'Matrix.TypeX'".  This error is received on a line of code that
is iterating through the collection in a for each statement.

I have mapped a drive to the code on the build server and run the nAnt
scripts locally against the build server code and it compiles fine.  I have
copied the command line call to vbc that is shown in the output window of
Visual Studio when I compile in release mode and run it from a command line
and it fails with the same error.  That's right, the same thing that is
succeeding for Visual Studio on the same box is failing for me.  I've now
even gone as far as uninstalling and reinstalling the .Net 2.0 framework.

I'm frustrated and ready to go back to the old non-generic base collection
just to be able to compile on my build server.  If you have any ideas, please
help.
Brett - 30 Jul 2007 17:32 GMT
Just to share some extra weirdness...

I tried running msbuild on the build server against the project file
expecting to get a clean compile the same as I do through VS 2005.  Wrong!  
It gave me the same error I described below.  Why in the world would the
MSBuild results be different than the results I get through the IDE?  Doesn't
the IDE just call MSBuild?

Can someone at least confirm for me that I am not crazy and that the code
situation I described *should* compile?
Peter Duniho - 30 Jul 2007 17:48 GMT
> Just to share some extra weirdness...
>
[quoted text clipped - 3 lines]
> MSBuild results be different than the results I get through the IDE?  Doesn't
> the IDE just call MSBuild?

I don't have any specific knowledge regarding that question, but given
the behavior I'd say perhaps it doesn't.

Alternatively, maybe there are some compiler switches that are
different.  That's the first thing I'd look at.

> Can someone at least confirm for me that I am not crazy and that the code
> situation I described *should* compile?

I'm not sure anyone can do that until you actually post a
complete-but-concise sample of code that reliably reproduces the problem.

Pete
Brett - 30 Jul 2007 19:12 GMT
Comments below:

> > Just to share some extra weirdness...
> >
[quoted text clipped - 9 lines]
> Alternatively, maybe there are some compiler switches that are
> different.  That's the first thing I'd look at.

It was the first thing I looked at too, that is why I copied the vbc call
and all parameters from the output window of VS 2005 and pasted it into a
command prompt window.  Either VS 2005 isn't showing me all of the parameters
it is setting or something else is causing the difference.  Either way if
someone can tell me how to figure out how to run the vb compiler exactly the
same way VS 2005 is I'd be mighty grateful.

> > Can someone at least confirm for me that I am not crazy and that the code
> > situation I described *should* compile?
>
> I'm not sure anyone can do that until you actually post a
> complete-but-concise sample of code that reliably reproduces the problem.

I'm afraid to spend too much time paring the code down to a useable sample
because I'm not sure if anyone will be able to reproduce the problem.  Right
now I can only recreate the problem on one box, it just happens to be our
build server.  But maybe if I can reproduce it on the build server someone
else will be able to reproduce it too; I'll see what I can put together
quickly.
Patrice - 30 Jul 2007 17:56 GMT
'Matrix.TypeX' inherits from ?

It could be quite easy to forget that your collection inherits from its
parent but it doesn't mean that the type you are using to store your
elements inherits from the type you used for elements when inheriting from
your base collection - hopefully you'll better understand than me what I'm
trying to say ;-)

---
Patrice

> Just to share some extra weirdness...
>
[quoted text clipped - 7 lines]
> Can someone at least confirm for me that I am not crazy and that the code
> situation I described *should* compile?
Brett - 30 Jul 2007 19:16 GMT
Thanks for the suggestion Patrice but the generic type parameters for the
collection I'm inheriting from and the type of the members I am putting into
the collection match.  

I even tried swithching it to declare the type specific collection as a
generic collection with a constraint for the specific type I want to hold and
then passing the type parameter through to the class I'm inheriting from and
I still got the same compile error in the same situations.

> 'Matrix.TypeX' inherits from ?
>
[quoted text clipped - 18 lines]
> > Can someone at least confirm for me that I am not crazy and that the code
> > situation I described *should* compile?
Brett - 30 Jul 2007 19:32 GMT
Well I'm no closer to knowing what causes it to compile sometimes and
sometimes not, but I've narrowed down what it is choking on.  It appears to
be specifically related to the enumerator.  If I change the code that is
throwing an error to use a for loop with an index instead of a for each loop
it works fine.

> I've tried to debug this every way I can think of, but I can't figure out
> this strange compile problem I am having.  Any help is greatly appreciated.
[quoted text clipped - 34 lines]
> just to be able to compile on my build server.  If you have any ideas, please
> help.
Brett - 30 Jul 2007 19:56 GMT
The MatrixGenericCollectionBase object was inheriting
System.Collections.ObjectModel.Collection(Of T) and was also implementing
IDictionary since it is sort of hybrid dictionary/collection [dumb I know,
cleaning up code one step at a time].  Apparently since both of those
implement IEnumerable it seems like there was some sort of clash.  I still
can't explain why it worked in some environments and not in others but at
least I know how to start to fix it.

> Well I'm no closer to knowing what causes it to compile sometimes and
> sometimes not, but I've narrowed down what it is choking on.  It appears to
[quoted text clipped - 40 lines]
> > just to be able to compile on my build server.  If you have any ideas, please
> > help.

Rate this thread:







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.