I am using the following code in a Button_Click event:
If OwordDoc IsNot Nothing Then
System.Windows.MessageBox.Show("A document is already open.", MessageBoxButton.OK, MessageBoxImage.Information)
Return
End IF
I am getting the following runtime error no matter which MessageBoxButton enumeration I use.
(InvalidEnumArgumentException: 'The value of argument 'button' (64) is invalid for Enum type 'MessageBoxButton'.)
I'm not using any other MessageBox elsewhere. Although this is a first time wpf project, this seems so fundamental, what am I doing wrong?
I have checked through previous StackOverflow Q/A and feel I am almost married to Microsoft Copilot!
If you had read the relevant documentation, as you should have before posting a question, then you'd know that there is no overload of
MessageBox.Showwith three parameters of those types. If you'd simply paid attention to Intellisense when typing the code then you'd know too. You need to provide twoStrings- the title and the message - followed by aMessageBoxButtonand then aMessageBoxImage. In your code, theMessageBoxButtonvalue is being converted to aStringand theMessageBoxImagevalue is being converted to aMessageBoxButtonvalue. As the error message clearly states, that conversion is not valid.This is a perfect example of why you should ALWAYS have
Option Strict On. If you had done then implicit conversions like that would not be allowed and your code would not compile. TurnOption Strict Onin the project properties and fix any late binding or implicit conversion errors that result. You should also turn itOnin the VB options, so it will beOnby default for all future projects.