Error in situation when parameter of a function has the same name as field in the record inside the function

Andrey Minakov 1 Reputation point
2020-10-27T22:28:11.16+00:00

I have a construction like this in my PQ function in Excel:

= (t)=> List.Generate(()=>[t = t], ...)

When I call the function, I have the error below. And I remember that in general making such constructions:

= (t)=> [t=t]

is a way to troubles, regardless of whether it is PBD or Excel.

But it is perfectly legal from the PQ Specification point of view.

I don't place the info in the error in the PBi forum, because they have too strict rules of posting errors. Hopefully, somebody from the team will pick up the info I provided here ...

So, the error message (and I pressed Throw Error in PQ editor as well):

Unexpected error: Operation is not valid due to the current state of the object.
Details:
Microsoft.Mashup.Evaluator.Interface.ErrorException: Operation is not valid due to the current state of the object. ---> Microsoft.Mashup.Evaluator.Interface.ErrorException: Operation is not valid due to the current state of the object. ---> Microsoft.Mashup.Evaluator.Interface.ErrorException: Operation is not valid due to the current state of the object. ---> Microsoft.Mashup.Evaluator.Interface.ErrorException: Operation is not valid due to the current state of the object. ---> Microsoft.Mashup.Evaluator.Interface.ErrorException: Operation is not valid due to the current state of the object. ---> System.InvalidOperationException: Operation is not valid due to the current state of the object. ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Microsoft.Mashup.Engine1.Language.Compiler.ToFunction(IFunctionExpression expression)
at Microsoft.Mashup.Engine1.Runtime.CollapseNestedFunctionsVisitor.VisitFunction(IFunctionExpression node)
at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitExpression(IExpression expression)
at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitListElements(IExpression[] list)
at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitInvocation(IInvocationExpression invocation)
at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitExpression(IExpression expression)
at Microsoft.Mashup.Engine.Ast.LogicalAstVisitor21.VisitInitializer(VariableInitializer member) at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitListElements(VariableInitializer[] list) at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitListElements(IList1 list)
at Microsoft.Mashup.Engine.Ast.LogicalAstVisitor21.VisitRecord(IRecordExpression record, TBinding binding, IList1 bindings)
at Microsoft.Mashup.Engine1.Runtime.CollapseNestedFunctionsVisitor.VisitRecord(IRecordExpression node)
at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitExpression(IExpression expression)
at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitFieldAccess(IFieldAccessExpression fieldAccess)
at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitExpression(IExpression expression)
at Microsoft.Mashup.Engine.Ast.LogicalAstVisitor21.VisitFunction(IFunctionExpression function, IList1 bindings)
at Microsoft.Mashup.Engine1.Runtime.CollapseNestedFunctionsVisitor.VisitFunction(IFunctionExpression node)
at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitExpression(IExpression expression)
at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitInvocation(IInvocationExpression invocation)
at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitExpression(IExpression expression)
at Microsoft.Mashup.Engine.Ast.LogicalAstVisitor21.VisitFunction(IFunctionExpression function, IList1 bindings)
at Microsoft.Mashup.Engine1.Runtime.CollapseNestedFunctionsVisitor.VisitFunction(IFunctionExpression node)
at Microsoft.Mashup.Engine.Ast.AstVisitor2.VisitExpression(IExpression expression)
at Microsoft.Mashup.Engine1.Language.Query.NormalizationVisitor.Normalize(IExpression node, TypeValue[] parameterTypes, Boolean normalizeInvocation)
at Microsoft.Mashup.Engine1.Language.Query.QueryExpressionBuilder.TryToQueryExpression(TypeValue type, IFunctionExpression functionExpression, QueryExpression& queryExpression)
at Microsoft.Mashup.Engine1.Language.Query.AddColumnsQuery.CreateQueryExpressions(FunctionValue columnGeneratorFunction, RecordTypeValue rowType)
at Microsoft.Mashup.Engine1.Language.Query.ProjectColumnsQuery.TryAddColumns(ColumnsConstructor columnGenerator, Query& query, ColumnSelection& newColumnProjection)
at Microsoft.Mashup.Engine1.Language.Query.ProjectColumnsQuery.AddColumns(ColumnsConstructor columnGenerator)
at Microsoft.Mashup.Engine1.Language.Query.QueryTableValue.AddColumns(ColumnsConstructor columnGenerator)
at Microsoft.Mashup.Engine1.Runtime.RelatedTablesTableValue.AddColumns(ColumnsConstructor columnsConstructor)
at Microsoft.Mashup.Engine1.Runtime.TableValue.AddColumns(ListValue columnNames, FunctionValue columnGenerator, Value columnTypes)
at Microsoft.Mashup.Engine1.Runtime.NativeFunctionValue45.Invoke(Value arg0, Value arg1, Value arg2, Value arg3) at Microsoft.Mashup.Engine1.Runtime.FunctionValue.Invoke(Value[] args) at Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0) at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(Int32 index) at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(Int32 index) at Microsoft.Mashup.Engine1.Language.RuntimeFunctionValueN.Invoke(Value[] args) at Microsoft.Mashup.Engine1.Language.FunctionInvocationInstruction2.Execute(MembersFrameN& frame) at Microsoft.Mashup.Engine1.Language.RuntimeFunctionValueN.Invoke(Value[] args) at Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame) at Microsoft.Mashup.Engine1.Language.FunctionInvocationInstruction2.Execute(MembersFrame1& frame) at Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame) at Microsoft.Mashup.Engine1.Language.InstructionInvocationInstruction2.Execute(MembersFrame1& frame) at Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame) at Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0) at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(Int32 index) at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(Int32 index) at Microsoft.Mashup.Engine1.Language.FunctionInvocationInstruction2.Execute(MembersFrame1& frame) at Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame) at Microsoft.Mashup.Engine1.Language.InstructionInvocationInstruction2.Execute(MembersFrame1& frame) at Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame) at Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0) at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(Int32 index) at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(Int32 index) at Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0) at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(Int32 index) at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(Int32 index) at Microsoft.Mashup.Engine1.Runtime.Library.Linker.BindFunctionValue.TypedInvoke(RecordValue environment, Value section, TextValue name) at Microsoft.Mashup.Engine1.Runtime.NativeFunctionValue34.Invoke(Value arg0, Value arg1, Value arg2)
at Microsoft.Mashup.Engine1.Language.MembersFunctionValue0.Invoke()
at Microsoft.Mashup.Engine1.Language.ListInstruction.RuntimeListValue.Force(Int32 index)
at Microsoft.Mashup.Engine1.Language.ListInstruction.RuntimeListValue.get_Item(Int32 index)
at Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0)
at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(Int32 index)
at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(Int32 index)
at Microsoft.Mashup.Engine1.Language.FunctionInvocationInstruction2.Execute(MembersFrame1& frame)
at Microsoft.Mashup.Engine1.Language.Instruction.ExecuteCondition(MembersFrame1& frame)
at Microsoft.Mashup.Engine1.Language.DebugInstruction.ExecuteCondition(MembersFrame1& frame)
at Microsoft.Mashup.Engine1.Language.IfInstruction.Execute(MembersFrame1& frame)
at Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame)
at Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0)
at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(Int32 index)
at Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(Int32 index)
at Microsoft.Mashup.Engine1.Language.MembersFunctionValue0.Invoke()
at Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.BeginGetResult(DocumentEvaluationParameters parameters, Action1 callback) --- End of inner exception stack trace --- at Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.BeginGetResult(DocumentEvaluationParameters parameters, Action1 callback)
at Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.BeginGetResult(DocumentEvaluationParameters parameters, Action1 callback) at Microsoft.Mashup.Evaluator.Interface.IDocumentEvaluatorExtensions.GetResult[T](IDocumentEvaluator1 evaluator, DocumentEvaluationParameters parameters)
at Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetResult[T](IMessageChannel channel, BeginGetResultMessage message, Action1 action) at Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetPreviewValueSource(IMessageChannel channel, BeginGetPreviewValueSourceMessage message) at Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.ChannelMessenger.OnMessageWithUnknownChannel(IMessageChannel baseChannel, MessageWithUnknownChannel messageWithUnknownChannel) at Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.EvaluationHost.Run() at Microsoft.Mashup.Container.EvaluationContainerMain.Run(Object args) at Microsoft.Mashup.Evaluator.SafeThread2.<>c__DisplayClass9_0.<CreateAction>b__0(Object o) at Microsoft.Mashup.Container.EvaluationContainerMain.SafeRun(String[] args) at Microsoft.Mashup.Container.BootstrapAppDomainManager.Execute(String[] argv) --- End of inner exception stack trace --- at Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.<>c__DisplayClass3_0.<BeginGetResult>b__0(EvaluationResult21 result)
--- End of inner exception stack trace ---
at Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.<>c__DisplayClass3_0.<BeginGetResult>b__0(EvaluationResult21 result) at Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.BeginGetResult(DocumentEvaluationParameters parameters, Action1 callback)
at Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.BeginGetResult(DocumentEvaluationParameters parameters, Action1 callback) at Microsoft.Mashup.Evaluator.Interface.IDocumentEvaluatorExtensions.GetResult[T](IDocumentEvaluator1 evaluator, DocumentEvaluationParameters parameters)
at Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetResult[T](IMessageChannel channel, BeginGetResultMessage message, Action1 action) at Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetPreviewValueSource(IMessageChannel channel, BeginGetPreviewValueSourceMessage message) at Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.ChannelMessenger.OnMessageWithUnknownChannel(IMessageChannel baseChannel, MessageWithUnknownChannel messageWithUnknownChannel) at Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message) at Microsoft.Mashup.Evaluator.EvaluationHost.Run() at Microsoft.Mashup.Container.EvaluationContainerMain.Run(Object args) at Microsoft.Mashup.Evaluator.SafeThread2.<>c__DisplayClass9_0.<CreateAction>b__0(Object o) at Microsoft.Mashup.Container.EvaluationContainerMain.SafeRun(String[] args) at Microsoft.Mashup.Container.BootstrapAppDomainManager.Execute(String[] argv) --- End of inner exception stack trace --- at Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.<>c__DisplayClass9_1.<OnBeginGetPreviewValueSource>b__1() at Microsoft.Mashup.Evaluator.RemotePreviewValueSource.<>c__DisplayClass0_0.<RunStub>b__0() at Microsoft.Mashup.Evaluator.EvaluationHost.ReportExceptions(IHostTrace trace, IEngineHost engineHost, IMessageChannel channel, Action action) --- End of inner exception stack trace --- at Microsoft.Mashup.Evaluator.EvaluationHost.<>c__DisplayClass11_0.<TryReportException>b__1() at Microsoft.Mashup.Common.SafeExceptions.IgnoreSafeExceptions(IEngineHost host, IHostTrace trace, Action action) at Microsoft.Mashup.Evaluator.EvaluationHost.TryReportException(IHostTrace trace, IEngineHost engineHost, IMessageChannel channel, Exception exception) at Microsoft.Mashup.Evaluator.EvaluationHost.ReportExceptions(IHostTrace trace, IEngineHost engineHost, IMessageChannel channel, Action action) at Microsoft.Mashup.Evaluator.RemotePreviewValueSource.RunStub(IEngineHost engineHost, IMessageChannel channel, Func1 getPreviewValueSource)
at Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.<>c__DisplayClass12_11.<OnBeginGetResult>b__0() at Microsoft.Mashup.Evaluator.EvaluationHost.ReportExceptions(IHostTrace trace, IEngineHost engineHost, IMessageChannel channel, Action action) at Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetResult[T](IMessageChannel channel, BeginGetResultMessage message, Action1 action)
at Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetPreviewValueSource(IMessageChannel channel, BeginGetPreviewValueSourceMessage message)
at Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.ChannelMessenger.OnMessageWithUnknownChannel(IMessageChannel baseChannel, MessageWithUnknownChannel messageWithUnknownChannel)
at Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.EvaluationHost.Run()
at Microsoft.Mashup.Container.EvaluationContainerMain.Run(Object args)
at Microsoft.Mashup.Evaluator.SafeThread2.<>c__DisplayClass9_0.<CreateAction>b__0(Object o)
at Microsoft.Mashup.Container.EvaluationContainerMain.SafeRun(String[] args)
at Microsoft.Mashup.Container.BootstrapAppDomainManager.Execute(String[] argv)
--- End of inner exception stack trace ---
at Microsoft.Mashup.Evaluator.EvaluationHost.OnException(IEngineHost engineHost, IMessageChannel channel, ExceptionMessage message)
at Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(IMessageChannel channel, Message message)
at Microsoft.Mashup.Evaluator.Interface.IMessageChannelExtensions.WaitFor[T](IMessageChannel channel)
at Microsoft.Mashup.Evaluator.RemotePreviewValueSource.PreviewValueSource.WaitFor(Func1 condition, Boolean disposing) at Microsoft.Mashup.Evaluator.RemotePreviewValueSource.PreviewValueSource.get_TableSource() at Microsoft.Mashup.Evaluator.Interface.TracingPreviewValueSource.get_TableSource() at Microsoft.Mashup.Host.Document.Analysis.PackageDocumentAnalysisInfo.PackagePartitionAnalysisInfo.SetPreviewValue(EvaluationResult21 result, Func1 getStaleSince, Func1 getSampled)

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,066 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Jake Bolton 1 Reputation point
    2020-11-13T02:21:36.413+00:00

    function has the same name as field in the record inside the function

    Can you post sample code that is triggering the error? I tried re-creating the inner function that you're explaining, but I cannot get an error.

    let
        namedArg = (t) => [t = 10],
        namedArg2 = (t) => [t = t],
    
        arg1 = [t = "cat"],
        res0 = namedArg( arg1 ),
        // returns: [ t = 10 ]
    
        res1 = namedArg( "arg" ),
        // returns: [ t = 10 ]
    
        res2 = namedArg( [t = 9999] ),
        // returns: [ t = 10 ]
    
        arg2 = [t = "cat"],
        res3 = namedArg2( "dog" ),
        // returns: [ t = "dog" ]
    
        res4 = namedArg2( [t = 9999] ),
        // returns: [ t = [ t = 9999] ]
    
        Results =[
            fn1 = namedArg,
            fn2 = namedArg2,
            arg1 = arg1,
            arg2 = arg2,
            res0 = res0,
            res1 = res0,
            res2 = res2,
            res3 = res3
        ]
    in
        Results
    
    0 comments No comments

  2. Andrey Minakov 1 Reputation point
    2020-12-07T18:11:26.377+00:00

    Hi Jake! Please see my answer to Echren.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.