BC42107: Property '<propertyname>' doesn't return a value on all code paths

Property '<propertyname>' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

A property Get procedure has at least one possible path through its code that does not return a value.

You can return a value from a property Get procedure in any of the following ways:

  • Assign the value to the property name and then perform an Exit Property statement.

  • Assign the value to the property name and then perform the End Get statement.

  • Include the value in a Return Statement.

If control passes to Exit Property or End Get and you have not assigned any value to the property name, the Get procedure returns the default value of the property's data type. For more information, see "Behavior" in Function Statement.

By default, this message is a warning. For more information on hiding warnings or treating warnings as errors, see Configuring Warnings in Visual Basic.

Error ID: BC42107

To correct this error

  • Check your control flow logic and make sure you assign a value before every statement that causes a return.

    It's easier to guarantee that every return from the procedure returns a value if you always use the Return statement. If you do this, the last statement before End Get should be a Return statement.

See also