zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
449 stars 86 forks source link

new Dictionary<T,T> throwing System.OutOfMemoryException exception #111

Closed se closed 3 years ago

se commented 3 years ago

new Dictionary<string, object>() is throwing exception.

Sample Code

var context = new EvalContext();
context.RegisterType(typeof(MSMRAccountAccessRequest));
context.RegisterType(typeof(MSMRBrowserActionTypes));
context.RegisterType(typeof(MSMRBrowserAction));
context.RegisterType(typeof(Guid));
context.RegisterType(typeof(List<>));
context.RegisterType(typeof(Dictionary<,>));
context.Execute("var values = new Dictionary<string, object>();");

Exception


System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
   at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
   at Z.Expressions.CodeCompiler.CSharp.ExpressionScope.(String , Type& )
   at Z.Expressions.CodeCompiler.CSharp.ExpressionScope.(String , Type& )
   at .(ExpressionScope , SyntaxNode , StringBuilder , Int32& , Boolean )
   at .(ExpressionScope , SyntaxNode , StringBuilder , Int32& , Boolean )
   at .(ExpressionScope , SyntaxNode , Boolean )
   at .(ExpressionScope , SyntaxNode )
   at .(ExpressionScope , SyntaxNode , Expression , Boolean )
   at .(ExpressionScope , SyntaxNode )
   at .(ExpressionScope , SyntaxNode , Expression , Boolean )
   at .(ExpressionScope , SyntaxNode , Expression , Boolean )
   at .(ExpressionScope , SyntaxNode , Expression , Boolean )
   at Z.Expressions.CodeCompiler.CSharp.ExpressionParser.ParseSyntax(ExpressionScope scope, SyntaxNode node, Type resultType)
   at .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , ExpressionScope , String , Boolean , Boolean )
   at .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , Boolean , Boolean , Boolean )
   at Z.Expressions.EvalContext.Execute[TResult](String code, Object parameters)

Trying to apply a workaround but no chance right now. It is an urgent situation for us.

JonathanMagnan commented 3 years ago

Hello @se ,

Sorry for the delay, my developer tried it and everything is working without problem.

Where the issue happens is pretty weird on the GetTypeByName.

Is it possible to provide a runnable project that throw the exception? We will for sure fix it asap if we can reproduce it.

You can send the project in private here: info@zzzprojects.com if needed.

Best Regards,

Jon

JonathanMagnan commented 3 years ago

Hello @se ,

Since our last conversation, we haven't heard from you!

As mentioned in my previous message, Would it be possible to send a private project that throws the exception to info@zzzprojects.com so we can fix the issue?

Looking forward to hearing from you,

Jon

se commented 3 years ago

Sorry. I fixed with a workaround. I'm gonna try to create a new private project and reproduce the issue.