CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Anyone help with the VB.Net implementation of PTPrincipal?

rated by 0 users
Answered (Verified) This post has 3 verified answers | 4 Replies | 2 Followers

Top 50 Contributor
163 Posts
gajit posted on Mon, Feb 20 2012 1:02 PM

I'm trying to implement the PTPrincipal class in VB.Net, and the direct translation of the C# class produces an error...

Anyone know what the correct syntax should be?

Here's what I get in VB.Net :

Public Shared Sub BeginLogin(username As String, password As String)
            PTIdentity.GetPTIdentity(username, password, Function(o, e)
                                                             If e.[Error] Is Nothing AndAlso e.[Object] IsNot Nothing Then
                                                                 SetPrincipal(e.[Object])
                                                             Else
                                                                 Logout()
                                                             End If
                                                         End Function) '------ doesn't like THIS function aspect.
        End Sub

when I translate THIS code from C#:

    public static void BeginLogin(string username, string password)
    {
      PTIdentity.GetPTIdentity(username, password, (o, e) =>
        {
          if (e.Error == null && e.Object != null)
            SetPrincipal(e.Object);
          else
            Logout();
        });
    }

The design-time error (warning) is:

Function '<anonymous method>' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

I suspect this is the translator implementing the function incorrectly, but I'm not familiar with the syntax.

Thanks,

Graham

 

Answered (Verified) Verified Answer

Top 25 Contributor
422 Posts
Verified by gajit

I don't know a lot about lambdas in VB.NET, but I'm guessing the issue is that the lambda expression is being defined as a function, but the expression doesn't return anything.  So my best suggestion is to replace "Function(o, e)"  to "Sub(o, e)" (and the corresponding "End" tag too).

HTH

- Scott

Top 10 Contributor
9,270 Posts
Verified by gajit

I'm pretty sure the C# code method is void, so then Sub would be the correct translation.

Rocky

Not Ranked
4 Posts
Verified by gajit

VB.Net looks like this:

Public Shared Sub BeginLogin(ByVal username As String, ByVal password As String)
            CustomIdentity.GetIdentity(username, password, Sub(o, e)
                                                               If e.Error Is Nothing AndAlso e.Object IsNot Nothing Then
                                                                   SetPrincipal(e.Object)
                                                               Else
                                                                   Logout()
                                                               End If
                                                           End Sub)
        End Sub

All Replies

Top 25 Contributor
422 Posts
Verified by gajit

I don't know a lot about lambdas in VB.NET, but I'm guessing the issue is that the lambda expression is being defined as a function, but the expression doesn't return anything.  So my best suggestion is to replace "Function(o, e)"  to "Sub(o, e)" (and the corresponding "End" tag too).

HTH

- Scott

Top 50 Contributor
163 Posts
gajit replied on Mon, Feb 20 2012 3:26 PM

Hmmm... a Sub seems to correct the error...   I wonder if there's any impact....

Thanks Scott.

Top 10 Contributor
9,270 Posts
Verified by gajit

I'm pretty sure the C# code method is void, so then Sub would be the correct translation.

Rocky

Not Ranked
4 Posts
Verified by gajit

VB.Net looks like this:

Public Shared Sub BeginLogin(ByVal username As String, ByVal password As String)
            CustomIdentity.GetIdentity(username, password, Sub(o, e)
                                                               If e.Error Is Nothing AndAlso e.Object IsNot Nothing Then
                                                                   SetPrincipal(e.Object)
                                                               Else
                                                                   Logout()
                                                               End If
                                                           End Sub)
        End Sub

Page 1 of 1 (5 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems