0

I have an app that works fine when being debugged locally. But it has a strange issue when deployed as a Cloud Service to Azure. I have two Silverlight grid controls on the page which display a red x and give the error, "Unable to load data. Please check your network connection and try loading again."

Several other queries are running on this page and correctly pull data from other tables in the database. The queries that run correctly are tied to label or text box controls.

The queries that fail, return an HTTP Status code 500 (Internal error). If I try and pass the query to a constructor as an IVisualCollection, and I wrap the call in a Try block, the Inner Exception is "Object reference not set to an instance of an object." So, a Null Reference Exception. Checking for null before the constructor call and popping up a message box if the query was null as a means of debugging yielded nothing.

Try
    'Check for nulls
    If (Me.qQuoteByFirm Is Nothing) Then
        Me.ShowMessageBox("qQuoteByFirm", "Error", MessageBoxOption.Ok)
    End If
    If (Me.qQuoteByFirm.Screen Is Nothing) Then
        Me.ShowMessageBox("Screen", "Error", MessageBoxOption.Ok)
    End If
    If (New ModalWindowHelper(Me.qQuoteByFirm, "mwAddQuote", "Quote") Is Nothing) Then
        Me.ShowMessageBox("Modal", "Error", MessageBoxOption.Ok)
    End If

    'Create helper
    Me.HelperAddQuote = New ModalWindowHelper(Me.qQuoteByFirm, "mwAddQuote", "Quote")
Catch ex As Exception
    Dim err As String = ""
    For Each item In ex.Data
        err = err & item.ToString()
    Next
    err = err & ex.InnerException.ToString() & vbCrLf & _
          ex.Message.ToString() & vbCrLf & _
          ex.StackTrace

    Me.ShowMessageBox(err, "Error", MessageBoxOption.Ok)
End Try

Public Sub New(ByVal visualCollection As IVisualCollection, _
               ByVal dialogName As String, _
               Optional entityName As String = "")
    _collection = visualCollection
    _dialogName = dialogName
    _entityName = If(entityName <> "", entityName, _collection.Details.GetModel.ElementType.Name)
    _screen = _collection.Screen
End Sub

The actual construction of the queries does not seem to matter. I've tried several variations along with requesting the entire table. Same result. However, this only occurs on two specific tables. Grid controls displaying other tables on other screens work properly.

Here's the weird part. If I comment out the call to the constructor, I can gain access to the gird control and add data to it even through the red box remains. If I refresh the grid control, the data disappears as if it wasn't saved or isn't there. But inspecting the table in SQL Azure Management Portal shows that the data was properly populated in the table.

The app and the database are clearly connected and able to communicate fine. So why when reading from these two tables (but not writing to) are my grid controls throwing exceptions? Why does this only happen when deployed? What other techniques can I use to get more information?

embedded.kyle
  • 10,976
  • 5
  • 37
  • 56
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Jun 17 '14 at 18:42
  • @JohnSaunders Good post but I've already tried explicitly checking for nulls. I never get a message box. I always get the exception. Though the `Data` and `StackTrace` properties seem to be empty. I've updated with code. I create these helpers all over. Only two are causing an issue and only when deployed. In addition, running the query in the Management Portal also completes fine. – embedded.kyle Jun 17 '14 at 20:38
  • There's really only one reason for a `NullReferenceException`. Something is `null`, and you're trying to dereference it. – John Saunders Jun 17 '14 at 22:27
  • I haven't deployed to Azure, but I've wrestled with the dreaded red X. Aside from potential incorrect threading, it's almost always connection or permissions related. Since you say the grids actually save data to the Azure instance, the connection _should_ be okay, but you mention these are Silverlight grids (I assume not LS default grids)...don't you have to manually setup databinding for custom controls...is there a bad connection reference there? Secondly, does Azure require explicit table-level permissions? – mdisibio Jun 18 '14 at 17:21
  • @mdisibio No, they're the default LS grids so databinding should be taken care of automatically. Azure SQL permissions operate on a `SCHEMA` wide basis and I only have a single SQL login, user, and schema at this point. If I can operate on one table, which I can, I should be able to operate on them all. I have three levels of user permissions on the LS level and none of them work. – embedded.kyle Jun 18 '14 at 17:40

0 Answers0