Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor Wasm Eval: System.InvalidOperationException: Operation is not valid due to the current state of the object. #836

Closed
groogiam opened this issue Aug 13, 2024 · 8 comments
Assignees
Labels

Comments

@groogiam
Copy link

Here is what to include in your request to make sure we implement a solution as quickly as possible.

1. Description

Dynamic objects created by the library throw the following exception when accessing their properties in Blazor Wasm

2. Exception

If you are seeing an exception, include the full exception details (message and stack trace).

Exception message: Unhandled exception rendering component: Operation is not valid due to the current state of the object.
Stack trace: crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: 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 System.Reflection.Emit.RuntimeGenericTypeParameterBuilder.GetGenericParameterConstraints()
   at Microsoft.CSharp.RuntimeBinder.SymbolTable.AddAggregateToSymbolTable(NamespaceOrAggregateSymbol parent, Type type)
   at Microsoft.CSharp.RuntimeBinder.SymbolTable.LoadSymbolsFromType(Type type)
   at Microsoft.CSharp.RuntimeBinder.SymbolTable.GetCTypeFromType(Type type)
   at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.GetArgumentType(ICSharpBinder p, CSharpArgumentInfo argInfo, Expression param, DynamicMetaObject arg, Int32 index)
   at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.CreateArgumentArray(ICSharpBinder payload, Expression[] parameters, DynamicMetaObject[] args)
   at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.BindCore(ICSharpBinder payload, Expression[] parameters, DynamicMetaObject[] args, DynamicMetaObject& deferredBinding)
   at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.Bind(ICSharpBinder payload, Expression[] parameters, DynamicMetaObject[] args, DynamicMetaObject& deferredBinding)
   at Microsoft.CSharp.RuntimeBinder.BinderHelper.Bind(ICSharpBinder action, RuntimeBinder binder, DynamicMetaObject[] args, IEnumerable`1 arginfos, DynamicMetaObject onBindingError)
   at Microsoft.CSharp.RuntimeBinder.CSharpGetMemberBinder.FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
   at System.Dynamic.DynamicObject.MetaDynamic.<>c.<BindGetMember>b__2_0(MetaDynamic this, GetMemberBinder b, DynamicMetaObject e)
   at System.Dynamic.DynamicObject.MetaDynamic.CallMethodWithResult[GetMemberBinder](MethodInfo method, GetMemberBinder binder, Expression[] args, Fallback`1 fallback, Fallback`1 fallbackInvoke)
   at System.Dynamic.DynamicObject.MetaDynamic.CallMethodWithResult[GetMemberBinder](MethodInfo method, GetMemberBinder binder, Expression[] args, Fallback`1 fallback)
   at System.Dynamic.DynamicObject.MetaDynamic.BindGetMember(GetMemberBinder binder)
   at System.Dynamic.GetMemberBinder.Bind(DynamicMetaObject target, DynamicMetaObject[] args)
   at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel)
   at System.Runtime.CompilerServices.CallSiteBinder.BindCore[Func`3](CallSite`1 site, Object[] args)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[Object,Object](CallSite site, Object arg0)
   at WasmDynamicLinq.Pages.Home.OnInitialized() in D:\source\WasmDynamicLinq\Pages\Home.razor.cs:line 49
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

3. Fiddle or Project

Run the home page to reproduce.
WasmDynamicLinq.zip

@StefH
Copy link
Collaborator

StefH commented Aug 13, 2024

I did not check your example yet. Will do that at end of week.


Probably your issue is another issue as described here?

https://dynamic-linq.net/advanced-blazor-webassembly

@groogiam
Copy link
Author

I had looked at this article prior to submitting the issue. This happens in debug mode and when I have the <BlazorWebAssemblyEnableLinking>false</BlazorWebAssemblyEnableLinking> property set in the project file. From my limited knowledge it did not seem like the same issue. I appreciate your helping looking into this. Thanks.

@StefH StefH self-assigned this Aug 15, 2024
@StefH StefH added the bug label Aug 15, 2024
@StefH
Copy link
Collaborator

StefH commented Aug 15, 2024

I did not find the real issue yet, as a workaround you can use:

var allOrderItemsDynamic = orders.AsQueryable()
            .Select("new (OrderId as Id, OrderItems.Where(w => true) as Children, null as Empty)")
            .ToDynamicList<DynamicClass>();

        foreach (var element in allOrderItemsDynamic)
        {
            object elementAsObj = element;

            var idReflection = elementAsObj.GetType().GetProperty("Id")!.GetValue(elementAsObj);
            Console.WriteLine("idReflection = " + idReflection);

            Console.WriteLine("dynamic = " + element["Id"]);
        }

@StefH
Copy link
Collaborator

StefH commented Aug 17, 2024

#838

@StefH
Copy link
Collaborator

StefH commented Aug 17, 2024

@groogiam

Can you try preview version System.Linq.Dynamic.Core.1.4.5-preview-01?
it's available at : https://www.myget.org/F/system-linq-dynamic-core/api/v3/index.json

@groogiam
Copy link
Author

@StefH I'm not seeing version 1.4.5 in that feed.

image

@StefH
Copy link
Collaborator

StefH commented Aug 18, 2024

Did you check the preview checkbox in VS?

Screenshot_2024-08-18-18-20-47-625_org.mozilla.firefox.jpg

@groogiam
Copy link
Author

groogiam commented Aug 19, 2024

Doh! I was not paying attention and did not have the box checked. Sorry about that. I tested the updated library on my sample and can confirm the property evaluations now work without exceptions. Thanks.

@StefH StefH closed this as completed Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants