VB.NET Interface conversion problem

Posts   
 
    
jovball
User
Posts: 435
Joined: 23-Jan-2005
# Posted on: 03-May-2011 19:59:14   

This question is somewhat outside the lines of this forum but I think this is the best audience. I am trying to convert a (working) C# interface/implementation to the equivalent in VB.NET. I've used the various converters that are out there and looked at MSDN but I can't get this to compile in VB.NET.

C# Interface (IFetchData) EntityCollection<T> FetchCollection2<T>() where T : EntityBase2;

C# Implementation (FetchData.cs) public EntityCollection<T> FetchCollection2<T>() where T : EntityBase2

VB.NET Interface (IFetchData) Function FetchCollection2(Of T As EntityBase2)() As EntityCollection(Of T)

VB.NET Implementation (FetchData.vb) Public Function FetchCollection2(Of T As EntityBase2)() As EntityCollection(Of T) _ Implements IFetchData.FetchCollection2

The C# implementation code will compile using the VB.NET interface or the C# interface. The VB.NET implementation does not compile.

The compile error is Class 'FetchData' must implement 'Function FetchCollection2(Of T As SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2)() As DB2.DAL.HelperClasses.EntityCollection(Of T)' for interface 'CSharp.Interface.IFetchData'.

What am I missing here?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 03-May-2011 21:47:58   

Sorry , my VB.Net is hazy at best... do you need something like

Public Function FetchCollection2(Of T As EntityBase2)() As EntityCollection(Of T) _ Implements IFetchData.FetchCollection2(Of T As EntityBase2)... ?

Matt

jovball
User
Posts: 435
Joined: 23-Jan-2005
# Posted on: 04-May-2011 19:22:30   

Matt:

Sorry, that isn't correct either. I just don't see what part of my syntax is wrong.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-May-2011 19:34:46   
Public Function FetchCollection2(Of T As EntityBase2)() As EntityCollection(Of T) _ Implements IFetchData.FetchCollection2
End Function

This should be ok, please double check the signatures matche.

jovball
User
Posts: 435
Joined: 23-Jan-2005
# Posted on: 04-May-2011 21:18:06   

Waala:

That is the same as my original example above. It does not compile.

VB.NET Interface (IFetchData)

Function FetchCollection2(Of T As EntityBase2)() As EntityCollection(Of T)

VB.NET Implementation (FetchData.vb)

Public Function FetchCollection2(Of T As EntityBase2)() As EntityCollection(Of T) Implements IFetchData.FetchCollection2
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 05-May-2011 09:15:44   

Public Function FetchCollection2(Of T As EntityBase2)() As EntityCollection(Of T) _ Implements IFetchData.FetchCollection2(Of T)

Frans Bouma | Lead developer LLBLGen Pro
jovball
User
Posts: 435
Joined: 23-Jan-2005
# Posted on: 05-May-2011 17:40:51   

Still no. How can this be so hard?

I spent the last four years in C# and am now on a VB.NET project. Most code conversions are simple for me to think through but this one has completely fooled me.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 05-May-2011 22:09:19   

Sorry, I have had these problems myself as well sometimes, so I can't help further.... It's always a struggle these kind of migrations. Perhaps you can ask on a VB.NET specific forum?

Frans Bouma | Lead developer LLBLGen Pro
MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 05-May-2011 22:11:04   

This compiles for me


Public Class Class1
    Implements IFetchData

    Public Function FetchCollection2(Of T As EntityBase2)() As EntityCollection(Of T) Implements IFetchData.FetchCollection2
        Return Nothing
    End Function
End Class

Public Interface IFetchData
    Function FetchCollection2(Of T As EntityBase2)() As EntityCollection(Of T)
End Interface

Note the Implements IFetchData on a seperate line under the Class declaration...

Matt

jovball
User
Posts: 435
Joined: 23-Jan-2005
# Posted on: 05-May-2011 23:18:17   

Matt:

Very interesting discovery here. If I have the interface and the implementation in the same project, it will compile. Different projects will not even though I have a reference to the interface project.

Go figure.

Thanks guys, I'll work on this on my own some more and perhaps hit a VB.NET forum or Stack Overflow with this question. If I solve the issue, I'll post the answer.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-May-2011 07:03:38   

jovball wrote:

Very interesting discovery here. If I have the interface and the implementation in the same project, it will compile. Different projects will not even though I have a reference to the interface project.

Hehe, weird indeed.

jovball wrote:

Thanks guys, I'll work on this on my own some more and perhaps hit a VB.NET forum or Stack Overflow with this question. If I solve the issue, I'll post the answer.

Yes, please let us know when you figure this out.

David Elizondo | LLBLGen Support Team
Scaramanga
User
Posts: 57
Joined: 24-Mar-2011
# Posted on: 10-May-2011 10:53:10   

@jovball

Does it work ok if you define your interface in a seperate class (it's own .vb file) and then do the Implements in the class that does the actual fetching ?

I found that works better in VB, partical classes and multiple class definitions within one .vb file with complex interface definitions can be problematic, thats why I seperate stuff into physical individual classes where possible now.

It should work but it doesn't always....if I had a dollar for everytime I've said that over the years I'd be flying about in my own private jet by now stuck_out_tongue_winking_eye .