This project is read-only.

Error Nullable object have to have value

Mar 4, 2014 at 7:32 AM
Edited Mar 4, 2014 at 7:32 AM

i have this code:
                        imapClient.Folders.Inbox.Messages.Download("ALL", Enums.MessageFetchMode.None + Enums.MessageFetchMode.InternalDate, -1)
                        For Each mx In imapClient.Folders.Inbox.Messages
                                Dim soubor As String = path & mx.InternalDate.Value.ToString("yyyyMMdd-HHmmss") & "-" & mx.UId.ToString & ".eml"
                                If Not File.Exists(soubor) Then
                                    Dim eml As String = mx.DownloadRawMessage()
                                    File.WriteAllText(soubor, eml)
                                End If
                            Catch ex As Exception
                                File.AppendAllText("imapArchive.log", Now.ToString("yyyyMMdd-HHmmss ") & ex.Message & vbCrLf)
                                File.AppendAllText("imapArchive.log", ex.StackTrace & vbCrLf)
                            End Try
I get error in line Dim soubor As String ....

Would you be so kind to write me, what is wrong?

Thank you
Mar 4, 2014 at 12:20 PM
Hi Miroslav,

the exception occurs because the Message.InternalDate property doesn't have a value. This is because it is not being fetched at all, as you have made a mistake setting the download mode.

It should be this way:
Enums.MessageFetchMode.None Or Enums.MessageFetchMode.InternalDate
Bit flags are used to identify the fetch mode. so you cannot use the + operator to combine them.

If you want to know more about it and how you can combine the different values, there is a good article on CodeProject: Understand how bitwise operators work (C# and VB.NET examples)


Mar 4, 2014 at 3:09 PM
Hi Pavel,
thanks for explanation.