-
-
Notifications
You must be signed in to change notification settings - Fork 228
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
Running into a ParseException in a WebGL build #767
Comments
@ReginaldBull |
I don't know how to provide a fiddle example for a problem that exists within a WebGL (wasm) compiled project. |
Can you provide the part from your own code (including the entities / dtos) and the Dynamic LINQ Expression you are trying to parse? |
Basically it all boils down to this: public class CustomTypeProvider : DefaultDynamicLinqCustomTypeProvider
{
private readonly HashSet<Type> _types;
public CustomTypeProvider(Type[] types)
{
_types = new HashSet<Type>(types ?? new Type[]
{
})
{
typeof(Choice),
typeof(ProductConfiguration),
typeof(IEnumerable<>)
};
}
public override HashSet<Type> GetCustomTypes() => _types;
}
public class ProductConfiguration{
public string Code {get; private set;}
public IEnumerable<IChoice> Choices {get; private set;}=new List<IChoice>();
}
public interface IChoice {
string Reference{get}
}
public class Choice : IChoice{
public string Reference {get; private set;}
}
string expression = "input.Choices.FirstOrDefault(p => p.Reference == \"MyReference\")";
Type[] customTypes = new []{
typeof(Choice),
typeof(ProductConfiguration),
typeof(IEnumerable<>)
};
ParameterExpression[] parameterExpressions = new []{
Expression.Parameter(typeof(ProductConfiguration), "input")
};
ParsingConfig config = new ParsingConfig
{
CustomTypeProvider = new CustomTypeProvider(customTypes),
IsCaseSensitive = false
};
EpxressionParser parser = new ExpressionParser(parameterExpressions, expression, new object[]{}, config);
Expression exp = parser.Parse<Choice>(expression, parameterExpression, customTypes);
ProductConfiguration productConfiguration = CreateValidProductConfiguration();
object[] input = new object[]{
productConfiguration
};
var result = exp(input); As mentioned, running it locally it works. The problem shows up when using that approach inside a Unity3D WebGL build. |
Can you make a simple and small |
I created a minimal project for reproduction: https://github.com/ReginaldBull/LinqDynamicCoreUnity3D |
@ReginaldBull |
Hello, |
@ReginaldBull Can you maybe use the extension method instead of directly using And try to write the query you want to execute first as normal LINQ query, and from that, create a the dynamic. Example: using System.Linq.Dynamic.Core;
using ConsoleApp1;
string expression = "Choices.FirstOrDefault(p => p.Reference == \"MyReference\")";
Type[] customTypes = new[]
{
typeof(Choice),
typeof(ProductConfiguration),
typeof(IEnumerable<>)
};
var config = new ParsingConfig
{
CustomTypeProvider = new CustomTypeProvider(customTypes),
IsCaseSensitive = false
};
var productConfiguration = new ProductConfiguration("code");
var input = new[]
{
productConfiguration
};
var result = input.Select(i => i.Choices.FirstOrDefault(c => c.Reference == "MyReference")).ToArray();
var resultQ = input.AsQueryable().Select(config, expression).ToDynamicArray(); |
Thank you. Today I tried with the extension method. |
One additional finding. I tried again and debugged a bit in deep and found this exception occuring:
|
1. Description
I'm using the library in a Untiy3D project. The project is build for WebGL. Running the application encounters an error as soon the execution comes to parse an expression. Inside the Unity-Editor the execution is running smoothly without any problems.
The expression itself is executing on a list of objects and returns an element where a predicate is met.
2. Exception
I'm passing my classes as custom types to the parser.
I will be happy giving more information if needed.
The text was updated successfully, but these errors were encountered: