Henry
Henry

Reputation: 33

VB.NET: Null reference with an Interface

I have a null reference warning. Dummy code as follows:

 Dim poo As IEnumPooTypes
 Toilet.GetPooInBowl(poo)

The variable 'Poo' says it may result in an object reference not set error but I cannot use the 'New' keyword with an instance. How do I make the warning go away?

Upvotes: 0

Views: 489

Answers (2)

Neil
Neil

Reputation: 55402

VB.NET only gives you ByVal (which is an in parameter) and ByRef (which is an inout parameter). But I think you want to use poo as an out parameter. In this case you need to annotate the declaration with <System.Runtime.InteropServices.Out( )> ByRef (you can if course import System.Runtime.InteropServices and write <Out()> ByRef).

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 190943

You can't instantiate an interface if IEnumPooTypes is an interface. The I is implying that it is an interface. You need a concrete implementation of IEnumPooTypes.

Upvotes: 2

Related Questions