microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
746 stars 244 forks source link

Copying a read-only List with GetRange() crashes the client with casting error #6697

Open dzzzb opened 3 years ago

dzzzb commented 3 years ago

I found https://github.com/microsoft/AL/issues/6696 while just trying to get a list of enum Names() and chop off the 1st one representing the blank values. Now I'm trying to be clever and work around that by taking a GetRange() of the Names() list and omit the 1st name that way. I shouldn't have tried to be clever! I just get a different, worse error/crash.

Shouldn't it be OK to take a read-only 'view' List of a read-only list, so long as we don't then try to mutate the 'view' copy (and see #6696 for that)?

If not, can this be diagnosed at compile-time, as I also request for #6696?

the code:

pageextension 66666 Test extends "Customer List"
{
    trigger OnOpenPage()
    var
        Names, Range : List of [Text];
    begin
        Names := Enum::"Customer Blocked".Names();
        Range := Names.GetRange(2, Names.Count() - 1);
    end;
}

result: image

the error from Event Viewer:

Server instance: bc17cu1
Tenant ID: 
Environment Name: 
Environment Type: 
User: [me]
Type: System.InvalidCastException
Message: Unable to cast object of type 'System.Collections.ObjectModel.ReadOnlyCollection`1[Microsoft.Dynamics.Nav.Runtime.NavText]' to type 'System.Collections.Generic.List`1[Microsoft.Dynamics.Nav.Runtime.NavText]'.
StackTrace:
     at Microsoft.Dynamics.Nav.Runtime.TrappableOperationExecutor.ExecuteFactory[T](Func`1 factory, Func`2 mapNativeException)
     at Microsoft.Dynamics.Nav.BusinessApplication.PageExtension66666.OnOpenPage_Scope.OnRun()
     at Microsoft.Dynamics.Nav.Runtime.NavMethodScope.Run()
     at Microsoft.Dynamics.Nav.BusinessApplication.PageExtension66666.OnOpenPage()
     at Microsoft.Dynamics.Nav.Types.LinqExtensions.ForEach[TSource](IEnumerable`1 source, Action`1 action)
     at Microsoft.Dynamics.Nav.Runtime.NavForm.RaiseOnOpenPage()
     at Microsoft.Dynamics.Nav.Runtime.NavForm.OpenForm()
     at Microsoft.Dynamics.Nav.Service.NSFormBatchOpen.<>c__DisplayClass15_1.<HandleRegistrateDataAccess>b__0(NsDataAccess dataAccess)
     at Microsoft.Dynamics.Nav.Service.NsFormDataAccess.RunWithFormDataAccess(ITreeObject parent, NavForm form, Action`1 action)
     at Microsoft.Dynamics.Nav.Service.NsDataAccess.RunWithDataAccess(ITreeObject parent, NavRecordState state, Boolean instantiateNewForm, Guid parentFormHandle, String parentControlName, Boolean& instantiatedForm, Action`1 action)
     at Microsoft.Dynamics.Nav.Service.NsDataAccess.RunWithDataAccess(ITreeObject parent, NavRecordState state, Action`1 action)
     at Microsoft.Dynamics.Nav.Service.NSFormBatchOpen.HandleRegistrateDataAccess(FormOpenResponse openResponse, List`1 registeredForms)
     at Microsoft.Dynamics.Nav.Service.NSFormBatchOpen.Open(NavSession session)
     at Microsoft.Dynamics.Nav.Service.NSService.OpenForm(OpenFormRequest form)
     at SyncInvokeOpenForm(Object , Object[] , Object[] )
     at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
     at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.RunInTransactionCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
     at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
     at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.TransientErrorRetryCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
     at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
     at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.ErrorMappingCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
Source: Microsoft.Dynamics.Nav.Ncl
HResult: -2147467262
StackTrace:
     at Microsoft.Dynamics.Nav.Runtime.TrappableOperationExecutor.ExecuteFactory[T](Func`1 factory, Func`2 mapNativeException)
     at Microsoft.Dynamics.Nav.BusinessApplication.PageExtension66666.OnOpenPage_Scope.OnRun()
     at Microsoft.Dynamics.Nav.Runtime.NavMethodScope.Run()
     at Microsoft.Dynamics.Nav.BusinessApplication.PageExtension66666.OnOpenPage()
     at Microsoft.Dynamics.Nav.Types.LinqExtensions.ForEach[TSource](IEnumerable`1 source, Action`1 action)
     at Microsoft.Dynamics.Nav.Runtime.NavForm.RaiseOnOpenPage()
     at Microsoft.Dynamics.Nav.Runtime.NavForm.OpenForm()
     at Microsoft.Dynamics.Nav.Service.NSFormBatchOpen.<>c__DisplayClass15_1.<HandleRegistrateDataAccess>b__0(NsDataAccess dataAccess)
     at Microsoft.Dynamics.Nav.Service.NsFormDataAccess.RunWithFormDataAccess(ITreeObject parent, NavForm form, Action`1 action)
     at Microsoft.Dynamics.Nav.Service.NsDataAccess.RunWithDataAccess(ITreeObject parent, NavRecordState state, Boolean instantiateNewForm, Guid parentFormHandle, String parentControlName, Boolean& instantiatedForm, Action`1 action)
     at Microsoft.Dynamics.Nav.Service.NsDataAccess.RunWithDataAccess(ITreeObject parent, NavRecordState state, Action`1 action)
     at Microsoft.Dynamics.Nav.Service.NSFormBatchOpen.HandleRegistrateDataAccess(FormOpenResponse openResponse, List`1 registeredForms)
     at Microsoft.Dynamics.Nav.Service.NSFormBatchOpen.Open(NavSession session)
     at Microsoft.Dynamics.Nav.Service.NSService.OpenForm(OpenFormRequest form)
     at SyncInvokeOpenForm(Object , Object[] , Object[] )
     at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
     at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.RunInTransactionCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
     at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
     at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.TransientErrorRetryCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
     at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
     at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.ErrorMappingCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
nndobrev commented 3 years ago

@db-bc Thank you for being so active lately, we really appreciate the provided feedback. This definitely needs to be investigated.

dzzzb commented 3 years ago

@nndobrev You're very welcome. It's great to have a place where these things can be reported, so I do as much as I can. Thanks to you all over there for all the work on AL!

NKarolak commented 3 years ago

@nndobrev If you really love hunting bugs, what about proceeding with the oldest ones? Just a tiny example: https://github.com/microsoft/AL/issues/created_by/nkarolak ;-)