1 Replies - 162 Views - Last Post: 16 March 2019 - 04:10 PM Rate Topic: -----

#1 grabbetje   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 22-February 17

The object reference is not set to an instance of an object?

Posted 16 March 2019 - 03:31 PM

Hello, I try to upload Blob image files to azure and then to retrieve a list of Blobs stored in the container in vb winforms. The uploading runs perfect, but the items stored do not show up in the item list and im unable to download the Blobfile from Azure. The container is set to read and write and list in Azure so that should not be the problem. As soon as i click the download button this error shows up: the object reference is not set to an instance of an object

The vb debugger gives this warning. Does this have anything to do with it?
Warning Found conflicts between different versions of "Newtonsoft.Json" that could not be resolved.
These reference conflicts are listed in the build log when log verbosity is set to detailed. WinCloudAsyncAwait


Here is the code. Can somebody help me with this as im totally stuck at this moment. Help is more then welcome.


Imports System.Configuration
Imports System.Threading


Public Class Form1
    Private cts As CancellationTokenSource
    Private cancelToken As CancellationToken
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ToolStripStatusLabel1.Text = ""
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
        cts = New CancellationTokenSource()
        cancelToken = cts.Token
        cancelToken.ThrowIfCancellationRequested()


        ListImagesAsync().ConfigureAwait(True)
    End Sub


    Private Async Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click


        Try
            ToolStripStatusLabel1.Text = "Uploading"
            Await Task.Delay(txtDelay.Text)


            Dim AZBlob As New AzureBlob(ConfigurationManager.AppSettings("StorageConnectionString"), "images")
            Await AZBlob.UploadAsync(PictureBox1.ImageLocation, cancelToken)
            MessageBox.Show("upload success")
            ToolStripStatusLabel1.Text = ""
            PictureBox1.Image = Nothing
        Catch exCancel As OperationCanceledException
            Dim message As String = "upload canceled at Form"
            MessageBox.Show(message)
            ToolStripStatusLabel1.Text = message
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            ToolStripStatusLabel1.Text = ex.Message
        End Try
    End Sub


    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
        cts.Cancel()
    End Sub


    Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
        Dim fd As New OpenFileDialog()
        Dim dResult As DialogResult = fd.ShowDialog()
        If dResult = DialogResult.OK Then
            Dim path As String = fd.FileName
            PictureBox1.LoadAsync(path)
        End If


    End Sub


    Private Async Function ListImagesAsync() As Task
        Try
            ToolStripStatusLabel1.Text = "Retrieve Image collection"
            Await Task.Delay(txtDelay.Text)


            Dim AZBlob As New AzureBlob(ConfigurationManager.AppSettings("StorageConnectionString"), "images")
            Dim result As List(Of String) = Await AZBlob.ListFilesAsync(cancelToken)
            For Each imgName As String In result
                ListBox1.Items.Add(imgName)


            Next
            ToolStripStatusLabel1.Text = ""
        Catch exCancel As OperationCanceledException
            Dim message As String = "ListImages canceled at Form"
            MessageBox.Show(message)
            ToolStripStatusLabel1.Text = message
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            ToolStripStatusLabel1.Text = ex.Message
        End Try
    End Function


    Private Sub BtnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
        ListImagesAsync().ConfigureAwait(False)
    End Sub


    Private Async Sub btnRet_Click(sender As Object, e As EventArgs) Handles btnRet.Click
        Try
            ToolStripStatusLabel1.Text = "Download Image"
            Await Task.Delay(txtDelay.Text)
            Dim imgName As String = ListBox1.SelectedItem.ToString()
            Dim AZBlob As New AzureBlob(ConfigurationManager.AppSettings("StorageConnectionString"), "images")
            Await AZBlob.DownloadAsync(imgName, cancelToken)
            Dim fs As IO.FileStream = IO.File.OpenRead(My.Application.Info.DirectoryPath & "\" & imgName)


            PictureBox1.Image = Image.FromStream(fs)


            ToolStripStatusLabel1.Text = ""
        Catch exCancel As OperationCanceledException
            Dim message As String = "download canceled at Form"
            MessageBox.Show(message)
            ToolStripStatusLabel1.Text = message
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            ToolStripStatusLabel1.Text = ex.Message


        End Try




    End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: The object reference is not set to an instance of an object?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14924
  • View blog
  • Posts: 59,575
  • Joined: 12-June 08

Re: The object reference is not set to an instance of an object?

Posted 16 March 2019 - 04:10 PM

Which function is your 'download'?

Put a break point on line 93, and step through your download code. Find out which object hasn't been initialized.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1