You should change from IIf() to If(), as the latter uses short-circuiting while the former does not. With the IIf() version, GetMessage() is being called even when the boolean evaluates to true, which might be causing side effects. When using If(), only the correct return value is evaluated:
Return CType(If(Object.Equals(_newValue, _oldValue), msg, GetMessage(msg)), PooMessage)
EDIT: Added sample code for better clarity of If() vs. IIF(), with dotnetfiddle example
Fiddle: https://dotnetfiddle.net/vuMPgK
Code:
Imports System
Imports Microsoft.VisualBasic
Public Module Module1
Public Sub Main()
Dim didItWork as Boolean = False
Dim myTestObject as Test = Nothing
' works, due to IF(). Only the 'true' value is calculated
didItWork = If(myTestObject Is Nothing, False, myTestObject.MyValue)
Console.WriteLine("Did If() work?: " & didItWork.ToString())
' does not work, due to IIF(). Both True and False conditions are calculated regardless of the original test condition.
' it fails because myTestObject is null, so trying to access one of its properties causes an exception.
Try
didItWork = IIF(myTestObject Is Nothing, False, myTestObject.MyValue)
Console.WriteLine("Did IIF() work?: " & didItWork.ToString())
Catch ex as Exception
Console.WriteLIne("Error was thrown from IIF")
End Try
End Sub
End Module
Public Class Test
Public Property MyValue as Boolean = True
End class