locked
c# code converted to vb.net causing an issue - advise please RRS feed

  • Question

  • User968218215 posted

    Hi, 

    I am looking to extend the default number of records I can download to a vb.net store app from Azure using mobile services.

    I found this below blog that has the code for exactly what I want but when I convert the C# to vb.net, I get an error.

    http://www.kevinashley.com/2013/02/retrieving-more-data-from-azure-mobile-services-using-paging/

    The error in the below vb.net code is at the line - 'table As MobileServiceTableQuery(Of T)' - gives me this error

    'Microsoft.WindowsAzure.MobileServices.MobileServiceTableQuery(Of T)' is not accessible in this context because it is 'Friend'.

    Can anyone advise me of what the issue is here.

    Thanks for all help.

     
    <System.Runtime.CompilerServices.Extension> _
        Public Shared Async Function LoadAllAsync(Of T)(table As MobileServiceTableQuery(Of T), Optional bufferSize As Integer = 1000) As Task(Of List(Of T))
            Dim query = table.IncludeTotalCount()
            Dim results = Await query.ToEnumerableAsync()
            Dim count As Long = DirectCast(results, ITotalCountProvider).TotalCount
            If results IsNot Nothing AndAlso count > 0 Then
                Dim updates = New List(Of T)()
                While updates.Count < count
    
                    Dim [next] = Await query.Skip(updates.Count).Take(bufferSize).ToListAsync()
                    updates.AddRange([next])
                End While
                Return updates
            End If
    
            Return Nothing
        End Function

    </div> </div> </div>

    Thursday, September 25, 2014 5:12 AM

Answers

  • User475983607 posted

    By chance, are you trying to pass anything to the extension method?  If so, what?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 25, 2014 10:15 AM

All replies

  • User-1806150748 posted

    This is explained briefly in MSDN - http://social.msdn.microsoft.com/Forums/windowsapps/en-US/dd8b9b9b-ea1c-4705-9284-c965f6624e7b/store-app-vbnet-code-throwing-an-error-with-azure?forum=winappswithcsharp


    They suggested to create C# class library instead of converting to VB.net and then add reference to that project and use required method.

    Thursday, September 25, 2014 5:39 AM
  • User968218215 posted

    hi arindamnayak,

    Yes the advise was to try a vb.net forum but use the c# workaround if this cant be done.  But it seems very cumbersome to me as a solution to have c# classes in a vb.net project rather than the converted vb.net code if someone is familiar with the issue.  Surely if it works in c#, it works in vb.net?

    I have also tried the advise but am getting an error with mobileservices as a namespace in the referencec# class.  I am hoping that someone can recognise the issue with the vb.net code as I reckon that would be the simplest solution.

    Thanks for your help.

    Thursday, September 25, 2014 5:52 AM
  • User475983607 posted

    The example uses an extension method.  Extension methods must be enclosed within a Module and a method within a module can can not be Shared.   Where are you seeing the error?  

    http://msdn.microsoft.com/en-us/library/bb384936.aspx

    http://msdn.microsoft.com/en-us/library/bb384992(v=vs.90).aspx

    Thursday, September 25, 2014 8:46 AM
  • User968218215 posted

    Hi mgebhard,

    Thanks for your help.  I moved the code into a module class and removed the 'share' but I still have the below error on the part - MobileServiceTableQuery(Of T).

    'Microsoft.WindowsAzure.MobileServices.MobileServiceTableQuery(Of T)' is not accessible in this context because it is 'Friend'.

    Is there something I am missing to do with vb.net and friend?

    Thanks

    Imports Microsoft.WindowsAzure.MobileServices
    
    Module Module1
    
        <System.Runtime.CompilerServices.Extension> _
        Public Async Function LoadAllAsync(Of T)(table As MobileServiceTableQuery(Of T), Optional bufferSize As Integer = 1000) As Task(Of List(Of T))
            Dim query = table.IncludeTotalCount()
            Dim results = Await query.ToEnumerableAsync()
            Dim count As Long = DirectCast(results, ITotalCountProvider).TotalCount
            If results IsNot Nothing AndAlso count > 0 Then
                Dim updates = New List(Of T)()
                While updates.Count < count
    
                    Dim [next] = Await query.Skip(updates.Count).Take(bufferSize).ToListAsync()
                    updates.AddRange([next])
                End While
                Return updates
            End If
    
            Return Nothing
        End Function
    
    
    
    End Module

    Thursday, September 25, 2014 9:14 AM
  • User475983607 posted

    How are you calling the extension method and where is the error generated? At run time?

    Thursday, September 25, 2014 9:53 AM
  • User968218215 posted

    Hi,

    I am getting the error when I try to build the application in VS 2013.

    I will be calling the method from a different class - using code from the guys blog - which I'm fairly sure will work fine once the extension method itself is working.

    Thanks for your help.

    Thursday, September 25, 2014 10:01 AM
  • User475983607 posted

    By chance, are you trying to pass anything to the extension method?  If so, what?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 25, 2014 10:15 AM
  • User968218215 posted

    Brilliant!  I was so stuck on the method that I never thought the tablequery might have changed. 

     Dim azureDB2 As MobileServiceClient = App.azureDB1
    Dim tableK As IMobileServiceTable(Of c_ClientsAgresso) = azureDB2.GetTable(Of c_ClientsAgresso)() 
    Dim updatedReports = Await tableK.LoadAllAsync()

    So at some point MS must have updated from MobileServiceTableQuery to IMobileServiceTable.  Changing to IMobileServiceTable in the extension method got it working.

    Thanks for all your help...would never have got it without your help!

    Thursday, September 25, 2014 10:57 AM