DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 30 Jul 2007 08:14:01 -0700,    posted on: microsoft.public.dotnet.framework        back       

Thread Index
  1    Brett
          2    Brett
                 3    Peter Duniho
                 4    Patrice http://www.chez.com/scribe/
                        5    Brett
                 6    Brett
          7    Brett
          8    Brett


Strange Compile Problem With Generics   
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.
Date:Mon, 30 Jul 2007 08:14:01 -0700   Author:  

RE: Strange Compile Problem With Generics   
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?
Date:Mon, 30 Jul 2007 09:32:08 -0700   Author:  

Re: Strange Compile Problem With Generics   
Brett wrote:

> 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?


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
Date:Mon, 30 Jul 2007 09:48:41 -0700   Author:  

Re: Strange Compile Problem With Generics   
'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

"Brett"  a crit dans le message de news: 
CC759F28-1D39-49BA-B986-535D41193B78@microsoft.com...

> 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?
>
> 
Date:Mon, 30 Jul 2007 18:56:42 +0200   Author:  

Re: Strange Compile Problem With Generics   
Comments below:

"Peter Duniho" wrote:


> Brett wrote:
> > 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?
> 
> 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.


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.
Date:Mon, 30 Jul 2007 11:12:03 -0700   Author:  

Re: Strange Compile Problem With Generics   
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.

"Patrice" wrote:


> '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
> 
> "Brett"  a écrit dans le message de news: 
> CC759F28-1D39-49BA-B986-535D41193B78@microsoft.com...
> > 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?
> >
> > 
> 
> 
> 
Date:Mon, 30 Jul 2007 11:16:00 -0700   Author:  

RE: Strange Compile Problem With Generics   
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.


"Brett" wrote:


> 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.
Date:Mon, 30 Jul 2007 11:32:02 -0700   Author:  

RE: Strange Compile Problem With Generics   
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.

"Brett" wrote:


> 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.
> 
> 
> "Brett" wrote:
> 
> > 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.
Date:Mon, 30 Jul 2007 11:56:02 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us