AL icon indicating copy to clipboard operation
AL copied to clipboard

BC22 error AL0196: The call is ambiguous between the method Dictionary

Open xdimidrolx opened this issue 2 years ago • 6 comments

Hi all,

Have the error during the publishing of the app to BC22(OnPrem). No compilation error happens during building the app and or publishing the app to the BC19/BC20/BC21. The issue specifically happens with the BC22.

"The app uses the .net type("System.Collections.Generic.Dictionary``2"; "Dictionary`2")"

Error: An error occured while processing the request.
error AL0196: The call is ambiguous between the method 'Dictionary(DotNet "System.Collections.Generic.IDictionary<System.Object, System.Object>")' defined in DotNet 'System.Collections.Generic.Dictionary<System.Object, System.Object>' by the extension 'extension name (0.0.0.1)' and the method 'Dictionary(DotNet "System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, System.Object>>")' defined in DotNet 'System.Collections.Generic.Dictionary<System.Object, System.Object>' by the extension 'extension name (0.0.0.1)'.

Please advise.

xdimidrolx avatar Sep 04 '23 12:09 xdimidrolx

Please follow the template when creating github issue, so we can investigate faster. https://github.com/microsoft/AL/blob/master/ISSUE_TEMPLATE

nndobrev avatar Sep 08 '23 09:09 nndobrev

Sorry, please find the details, please let me know is anything else is needed.

AL Extension Version: 11.6 Server Version: 22.0.55180.0

The compilation on the server side is complaining directly to the line of the code: DataColumns := DataColumns.Dictionary(DataColumns);

DataColumns variable is .net lib "System.Collections.Generic.Dictionary`2"

xdimidrolx avatar Sep 08 '23 10:09 xdimidrolx

Based on the information provided in the article https://demiliani.com/2023/03/21/dynamics-365-business-central-and-net-6/ , it has come to our attention that Business Central version 22 (BC22) brings about significant changes related to the .NET framework. Consequently, we made adjustments on our end by updating the "al.assemblyProbingPaths" to accommodate .NET6.

However, we encountered an issue during compilation that is consistent with the problem we faced during the publishing process. The error message and details are shown in the following image: image

please advice on this matter.

xdimidrolx avatar Sep 15 '23 08:09 xdimidrolx

Are all of your add-ins dotnet standard 2.0? If not this will not work. You may be importing dictionary from both a dotnet framework dll and a dotnet standard dll. Please ensure that all assembly probing paths are only dotnet standard.

BazookaMusic avatar Sep 18 '23 09:09 BazookaMusic

Hi @BazookaMusic Do you mean controll add-ins? My solution does not have the conntrol add-ins. It mostly manipulates the Dictionalries as variables as .net type("System.Collections.Generic.Dictionary``2"; "Dictionary`2")"

I guess the issue quite easy to repro, by the creating single line of code with the variable. The compiler drops an error right away.

xdimidrolx avatar Sep 18 '23 13:09 xdimidrolx

dotnet.al image

MyTestPage.al `pageextension 50100 CustomerListExt extends "Customer List" { trigger OnOpenPage(); begin Message('App published: Hello world'); end;

local procedure TestDictionary()
var
    TestDictionary: DotNet "Dictionary`2";
begin
    TestDictionary := TestDictionary.Dictionary(TestDictionary);
end;

}`

Compile and publish: - Result error HelloWorld.al(16,42): error AL0196: The call is ambiguous between the method 'Dictionary(DotNet "System.Collections.Generic.IDictionary<System.Object, System.Object>")' defined in DotNet 'System.Collections.Generic.Dictionary<System.Object, System.Object>' by the extension 'TestDictionary by Default publisher (1.0.0.0)' and the method 'Dictionary(DotNet "System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, System.Object>>")' defined in DotNet 'System.Collections.Generic.Dictionary<System.Object, System.Object>' by the extension 'TestDictionary by Default publisher (1.0.0.0)'.

xdimidrolx avatar Sep 20 '23 14:09 xdimidrolx

This was lost in the noise, apologies for this. I can reproduce it and the issue seems to be the overload resolving algorithm. It seems to rank the two overloads as the same, while it should prefer the direct conversion.

BazookaMusic avatar Apr 11 '24 07:04 BazookaMusic

Hi @BazookaMusic

Thanks for the response. Does that mean that dev team will fix it? if it is - when we could expect the fix?

Do you have recomendations on how to workaround that meanwhile?

br, Dmytro

xdimidrolx avatar Apr 16 '24 08:04 xdimidrolx

This compiles:


dotnet
{
    assembly(mscorlib)
    {
        type("System.Collections.Generic.Dictionary`2"; MyDictionary)
        {

        }

        type("System.Collections.Generic.IEnumerable`1"; "GenericIEnumerable1")
        {
        }
    }
}

codeunit 109284 MyCodeunit
{
    trigger OnRun()
    begin

    end;

    local procedure TestDictionary()
    var
        TestDictionary: DotNet MyDictionary;
        ienumDict: DotNet GenericIEnumerable1;
    begin
        ienumDict := TestDictionary;
        TestDictionary := TestDictionary.Dictionary(ienumDict);
    end;

    var
        myInt: Integer;
}

We will look into fixing it so it chooses the overload with least transformations. However, AL does not support C# generics completely, so the first part is an investigation.

BazookaMusic avatar Apr 16 '24 09:04 BazookaMusic

The fix for this issue has been checked in to the master branch. It will be available in the bcinsider.azurecr.io/bcsandbox-master Docker image starting from platform build number 25.0.18639.0 and VS Code Extension Version 14.0.992775.

If you don’t have access to these images you need to become part of the Ready2Go program: aka.ms/readytogo

For more details on code branches and docker images please read: https://blogs.msdn.microsoft.com/nav/2018/05/03/al-developer-previews-multiple-releases-and-github/ https://freddysblog.com/2020/06/25/working-with-artifacts/

JesperSchulz avatar Apr 19 '24 09:04 JesperSchulz