1

Curious if I've messed up some Visual Studo settings that should be flagging this, or if I'm misunderstanding something entirely.

I have a funcion A which has 2 very basic interfaces as parameters:

  1. oConfiguration as IConfiguration
  2. oEventLogHandler as IEventLogHandler

Function B has a single parameter:

  1. oEventLogHandler as IEventLogHandler

Function A calls Function B, passing oConfiguration as an argument. I don't seem to get any compiler errors or warnings in Visual Studio but of course I get the runtime error:

Unable to cast object of type 'ConfigurationImplementationA' to type 'IEventLogHandler'.

Jack
  • 237
  • 1
  • 4
  • 14

1 Answers1

2

Turn on Option Strict.

It's off by default to support legacy VB6 code. Otherwise, it's just pain and suffering to leave it off, so don't.

See also : What do Option Strict and Option Explicit do?

J...
  • 30,968
  • 6
  • 66
  • 143