Monday, August 17, 2015

C# to VB.Net Gotcha 1: Interfaces

This doesn't happen if you write your interfaces and classes from scratch, but if you are translating from C#
either manually or using an online tool, you might end up with

 A_Service must implement Function XMLData () As IAService.XmlData(id as String)


Public Class A_Service : Implements IAService

Public Function XMLData (id as String) as String
'implementation here
End Function
'....
End Class

and you are thinking "I did, dammit"

Actually you need to explicitly add teh Implements keyword to each function as well. Unlike the C# versions where the implementation is implied by the fact that the class declaration says Implements. I think was how VB6 interfaces worked?

What you need is:

Public Function XMLData (id as String) as String Implments IAService.XMLData

There was a great posting on Stackoverflow for this:
http://stackoverflow.com/questions/666399/cant-see-must-implement-error

No comments: