VB-specific Factory/EntityCollection instantiation problem?

Posts   
 
    
cebus2000
User
Posts: 29
Joined: 11-Jan-2006
# Posted on: 14-Aug-2007 18:57:35   

Using Adapter template, version 2.0, runtime libs are at 2.0.50727, running on SQL2005. No custom templates, just using out-o-the-box functionality.

I have a service that caches a readonly list of reference tables. There's a good number of them, all with the same fields (ID, Value), so I am using a generic approach to deal with all of them. I use Activator.CreateInstance to create the appropriate EntityFactory, feed this to an EntityCollection, and fill the collection. Works like a charm... in C#.

I had to port this code to VB.Net (2005), and now I get some strange behavior. No exceptions get thrown, but when I examine my EntityCollection (before and after calling adapter.FetchEntityCollection), i see that most of the fields contain the following text (in Watch window): "The generic type 'SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore1' was used with the wrong number of generic arguments in assembly 'SD.LLBLGen.Pro.ORMSupportClasses.NET20, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ca73b74ba4e3ff27'.":"SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore1"

The collection ends up with the correct number of items, but each item contains the default or null values for whatever type is in the column (-1, Nothing, etc.)

Also, the results are the same if I generate the adapter code using the C# or VB templates.

Any help on this would be appreciated. Below is the VB code, and the C# code that works.

Problem VB.Net code:


        'get a factory type for a known entity- this is overkill, but
        'i want to make sure there's nothing wrong with the factory
        'creation part of this...
        Dim f As New C_IndustryTypeEntityFactory
        Dim factoryClassFQN As String = f.GetType().AssemblyQualifiedName
        Dim factoryType As Type = Type.GetType(factoryClassFQN)

        If factoryType Is Nothing Then
            Throw New ApplicationException("Failed to resolve code table factory type: " + factoryClassFQN)
        End If

        'instantiate the factory for the EntityCollection we need
        Dim factory As IEntityFactory2 = CType(Activator.CreateInstance(factoryType), IEntityFactory2)

        Dim coll As EntityCollection = New EntityCollection(factory)

        'fill the collection
        Using adp As New DataAccessAdapter()
            adp.FetchEntityCollection(coll, Nothing)
        End Using

Working C# code:


             C_IndustryTypeEntityFactory f = new C_IndustryTypeEntityFactory();
            string factoryClassFQN = f.GetType().AssemblyQualifiedName;


            Type factoryType = Type.GetType(factoryClassFQN);
            if (factoryType == null)
            {
                throw new ApplicationException("Failed to resolve code table factory type: " + factoryClassFQN);
            }


            IEntityFactory2 factory = (IEntityFactory2)Activator.CreateInstance(factoryType);
            EntityCollection coll = new EntityCollection(factory);

            using (DataAccessAdapter adp = new DataAccessAdapter())
            {
                adp.FetchEntityCollection(coll, null);
            }

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 14-Aug-2007 20:40:08   

I wrote a little spike in order to reproduce the error but I couldn't find it, I've attached the code(vbnet and cshparp), mssql05 dbbackup and .lgp.

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 14-Aug-2007 21:20:08   

ok, I've reduce the attachment size, hope this one work, disappointed if not, please send me your email address.

You can also download it from here: http://72.51.33.164/goose/spike3.rar

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Aug-2007 10:27:52   

Using Adapter template, version 2.0, runtime libs are at 2.0.50727

Could you please post the runtime library build/version number. ref: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7725

(edit) Make sure the VB application is referencing the correct version of the generated Adapter projects (VB), as well as the same version of the runtime libraries used by the C# application.

cebus2000
User
Posts: 29
Joined: 11-Jan-2006
# Posted on: 15-Aug-2007 14:04:10   

I was mistaken, the runtime libs version is 2.0.0.61023.

I tried regenerating the Adapter code in VB, but got the same problem. This is only happening from a VB 'client' app, regardless of the language the DBGeneric/Specific assemblies are generated in.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Aug-2007 14:40:23   

I was mistaken, the runtime libs version is 2.0.0.61023

That's a very old version, would you please try to download and use the latest available version. This could have been an old bug that has been solved.

cebus2000
User
Posts: 29
Joined: 11-Jan-2006
# Posted on: 16-Aug-2007 12:50:06   

I updated to the latest full release (July 6 2007), regenerated the Adapter code (in VB), but still get the same issue- no exceptions, but I get something like this if I watch my EntityCollection: _ AllowEdit {"The generic type 'SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore1' was used with the wrong number of generic arguments in assembly 'SD.LLBLGen.Pro.ORMSupportClasses.NET20, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ca73b74ba4e3ff27'.":"SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore1"} _

I also noticed that if I change the code to create a factory directly (not using Activator.CreateInstance), I get the same behavior. For example, this also won't work:


Dim coll as EntityCollection = new EntityCollection(new C_IndustryTypeFactory())

But of course, this works:


Dim coll As EntityCollection(Of C_IndustryTypeEntity) = New EntityCollection(Of C_IndustryTypeEntity)(New C_IndustryTypeEntityFactory())

But I can't use the generic version without writing a huge switch statement to handle all the different reference tables this service is to support.

cebus2000
User
Posts: 29
Joined: 11-Jan-2006
# Posted on: 16-Aug-2007 13:08:41   

I found an odd workaround, which might or might not point to a problem with non-generic EntityCollection code?

if i change the code to use EntityCollection(Of EntityBase2) instead of a plain EntityCollection, it works. For example, this works:


        'instantiate the factory for the EntityCollection we need
        Dim factory As IEntityFactory2 = CType(Activator.CreateInstance(factoryType), IEntityFactory2)

        Dim coll As EntityCollection(Of EntityBase2) = New EntityCollection(Of EntityBase2)(factory)
     'fill the collection
        Using adp As New DataAccessAdapter()
            adp.FetchEntityCollection(coll, Nothing)
        End Using

      'now the EntityCollection has data in it, everything is fine

So, some difference in EntityCollection and EntityCollection(Of EntityBase2) ??

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Aug-2007 15:19:39   

The generic type 'SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1' was used with the wrong number of generic arguments

I guess it was expecting a generic entity collection which needs a type to be passed.

I think your re-solution is a correct one, otherwise you may try the following for non generic collection.

Dim coll As EntityCollectionNonGeneric = New EntityCollectionNonGeneric(factory)
cebus2000
User
Posts: 29
Joined: 11-Jan-2006
# Posted on: 16-Aug-2007 16:40:21   

OK, I'll give that a try, I haven't used EntityCollectionNonGeneric yet.

Thanks!

cebus2000
User
Posts: 29
Joined: 11-Jan-2006
# Posted on: 16-Aug-2007 23:18:51   

Well, I was able to get it to work in VB using EntityCollectionNonGeneric. I had been projecting the EntityCollection into a collection of my custom type, and that also failed, but I was able to work around it by just looping through the collection and populating my custom List.

But I'm still curious why this only happens when I'm using VB.Net.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 18-Aug-2007 12:06:56   

cebus2000 wrote:

Well, I was able to get it to work in VB using EntityCollectionNonGeneric. I had been projecting the EntityCollection into a collection of my custom type, and that also failed, but I was able to work around it by just looping through the collection and populating my custom List.

But I'm still curious why this only happens when I'm using VB.Net.

Probably the compiler. It sometimes makes mistakes, although the .net 2.0 one is pretty good compared to the horrible .net 1.x compiler which couldn't even find the right overloads sometimes... disappointed

Frans Bouma | Lead developer LLBLGen Pro