ISSUE #7006

    The Named argument %1 was not resolved and corresponds to the following expression %2

    Description

    Both VB6 and VB.Net have support for Named parameters, which allow parameters to be especified by name and in any order, regardless of method signature. In C# versions 1 through 3.5 this feature is not supported. In most cases VBUC can resolve this issue by matching named parameters to method signatures and ensuring parameters are sent in the right overload / order. However, in certain cases where the VBUC cannot resolve references to methods with named parameters then this EWI is emitted.

    Recommendations

    For C# migrations the VBUC generally creates a series of method overloads that mimic the behavior of named parameters. This is normal behavior as it is the best approximation of optional named parameters in C#. Workarounds for this EWI include reordering parameters and using the Type.Missing reference for optional parameters that should be omitted. In cases where the reference could not be resolved this is particularly important. Since, this EWI is related to the VBUC not being able to find mapped references, ensuring that the machine doing the migration has access to all dependent assemblies and COM objects is essential. Repeating the migration once this has been correct can reduce or eliminate the occurrence of these EWIs

    Reference documentation for sample code:

    Sample VB6

    PublicSub OptionalParamsSub(Optional strHeader AsString = "Hello,", Optional strMessage AsString = "Empty Message", Optional strEnd AsString)

    MsgBox(strHeader & vbCrLf & strMessage & vbCrLf & strEnd)

    EndSub

     

    PublicSub ShowMessage(ByVal strMessage AsString)

    OptionalParamsSub(strMessage:=strMessage, strEnd:="The end")

    EndSub

     

    PublicFunction LoginIntoMAPI(ByVal strProfile AsString, ByVal strPassword)

    OnErrorGoTo error_olemsg

    LoginIntoMAPI = CreateObject("MAPI.Session")

     

    IfNot LoginIntoMAPI IsNothingThen

    If strProfile <> ""And strPassword <> ""Then

    'Known reference

    LoginIntoMAPI.Logon(showDialog:=False, profileName:=strProfile, profilePassword:=strPassword, newSession:=False)

    'Unknown Reference

    LoginIntoMAPI2.Logon(showDialog:=False, profileName:=strProfile, profilePassword:=strPassword, newSession:=False)

    Else

    Err.Raise(1273, "Cannot logon to email system: no profile name or password")

    EndIf

    EndIf

    ExitFunction

     

    error_olemsg:

    LoginIntoMAPI = Nothing

    EndFunction

    Target VB.NET

    PublicSub OptionalParamsSub(OptionalByRef strHeader AsString = "Hello,", OptionalByRef strMessage AsString = "Empty Message", OptionalByRef strEnd AsString = "")

    MessageBox.Show(strHeader & Strings.Chr(13) & Strings.Chr(10) & strMessage & Strings.Chr(13) & Strings.Chr(10) & strEnd, Application.ProductName)

    EndSub

     

    PublicSub ShowMessage(ByRef strMessage AsString)

    OptionalParamsSub( , strMessage, "The end")

    EndSub

     

    PublicFunction LoginIntoMAPI(ByRef strProfile AsString, ByRef strPassword AsString) As MAPI.Session

    Dim result As MAPI.Session = Nothing

    Dim LoginIntoMAPI2 AsObject

    Try

    result = New MAPI.Session

    IfNot (result IsNothing) Then

    If strProfile <> ""And strPassword <> ""Then

    'Known reference

    result.Logon(strProfile, strPassword, False, False)

    'Unknown Reference

    'UPGRADE_TODO: (1067) Member Logon is not defined in type Variant.

    LoginIntoMAPI2.Logon(showDialog:=False, profileName:=strProfile, profilePassword:=strPassword, newSession:=False)

    Else

    ThrowNew System.Exception("1273, Cannot logon to email system: no profile name or password")

    EndIf

    EndIf

    Return result

    Catch

     

    Return result

    EndTry

    EndFunction

    Expected VB.NET

    PublicSub OptionalParamsSub(OptionalByRef strHeader AsString = "Hello,", OptionalByRef strMessage AsString = "Empty Message", OptionalByRef strEnd AsString = "")

    MessageBox.Show(strHeader & Strings.Chr(13) & Strings.Chr(10) & strMessage & Strings.Chr(13) & Strings.Chr(10) & strEnd, Application.ProductName)

    EndSub

     

    PublicSub ShowMessage(ByRef strMessage AsString)

    OptionalParamsSub( , strMessage, "The end")

    EndSub

     

    PublicFunction LoginIntoMAPI(ByRef strProfile AsString, ByRef strPassword AsString) As MAPI.Session

    Dim result As MAPI.Session = Nothing

    Dim LoginIntoMAPI2 AsObject

    Try

    result = New MAPI.Session

     

    IfNot (result IsNothing) Then

    If strProfile <> ""And strPassword <> ""Then

    'Known reference

    result.Logon(strProfile, strPassword, False, False)

    'Unknown Reference

    'UPGRADE_TODO: (1067) Member Logon is not defined in type Variant.

    LoginIntoMAPI2.Logon(showDialog:=False, profileName:=strProfile, profilePassword:=strPassword, newSession:=False)

    Else

    ThrowNew System.Exception("1273, Cannot logon to email system: no profile name or password")

    EndIf

    EndIf

    Return result

    Catch

     

    Return result

    EndTry

    EndFunction

    Target C#

    staticpublicvoid OptionalParamsSub( string strHeader, string strMessage, string strEnd)

    {

    MessageBox.Show(strHeader + "\r\n" + strMessage + "\r\n" + strEnd, Application.ProductName);

    }

     

    staticpublicvoid OptionalParamsSub( string strHeader, string strMessage)

    {

    OptionalParamsSub(strHeader, strMessage, "");

    }

     

    staticpublicvoid OptionalParamsSub( string strHeader)

    {

    OptionalParamsSub(strHeader, "Empty Message", "");

    }

     

    staticpublicvoid OptionalParamsSub()

    {

    OptionalParamsSub("Hello,", "Empty Message", "");

    }

     

    staticpublicvoid ShowMessage( string strMessage)

    {

    OptionalParamsSub("Hello,", strMessage, "The end");

    }

    staticpublic MAPI.Session LoginIntoMAPI( string strProfile, string strPassword)

    {

    MAPI.Session result = null;

    object LoginIntoMAPI2 = null;

    try

    {

     

    result = new MAPI.Session();

    if (result != null)

    {

    if (strProfile != "" && strPassword != "")

    {

    //Known reference

    result.Logon(strProfile, strPassword, false, false, Type.Missing, Type.Missing, Type.Missing);

    //Unknown Reference

    //UPGRADE_TODO: (7006) The Named argument newSession was not resolved and corresponds to the following expression False

    //UPGRADE_TODO: (7006) The Named argument profilePassword was not resolved and corresponds to the following expression strPassword

    //UPGRADE_TODO: (7006) The Named argument profileName was not resolved and corresponds to the following expression strProfile

    //UPGRADE_TODO: (7006) The Named argument showDialog was not resolved and corresponds to the following expression False

    //UPGRADE_TODO: (1067) Member Logon is not defined in type Variant.

    LoginIntoMAPI2.Logon(false, strProfile, strPassword, false);

    } else

    {

    thrownew System.Exception("1273, Cannot logon to email system: no profile name or password");

    }

    }

    return result;

    }

    catch

    {

    return result;

    }

    }

    Expected C#

    staticpublic MAPI.Session LoginIntoMAPI( string strProfile, string strPassword)

    {

    MAPI.Session result = null;

    object LoginIntoMAPI2 = null;

    try

    {

    result = new MAPI.Session();

    if (result != null)

    {

    if (strProfile != "" && strPassword != "")

    {

    //Known reference

    result.Logon(strProfile, strPassword, false, false, Type.Missing, Type.Missing, Type.Missing);

    //Unknown Reference

    LoginIntoMAPI2.Logon(strProfile, strPassword, false, false, Type.Missing, Type.Missing, Type.Missing);

    } else

    {

    thrownew System.Exception("1273, Cannot logon to email system: no profile name or password");

    }

    }

    return result;

    }

    catch

    {

    return result;

    }

    }


    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration