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

Console error #142

Open
kller1993 opened this issue Feb 10, 2023 · 9 comments
Open

Console error #142

kller1993 opened this issue Feb 10, 2023 · 9 comments
Assignees

Comments

@kller1993
Copy link

kller1993 commented Feb 10, 2023

Unhandled exception. Z.Expressions.Compiler.Shared.EvalException: Oops! No applicable member has been found for the expression. The error occurred for expression "." at position 69 near ".ReadLine(); Console.W".

Apparently the ReadLine from Console.ReadLine isnt a recognized member, unlike the WriteLine.

Edit: Error appeared after creating a loop to register the used members, etc. In this case:

using System;
using System.Data;
using System.Data.Odbc;
using System.Data.SqlTypes;
using System.Xml;
using MySqlConnector;

@JonathanMagnan JonathanMagnan self-assigned this Feb 10, 2023
@JonathanMagnan
Copy link
Member

Hello @name,

Can you provide a runnable project/solution or a Fiddle with the issue you describe? You can send private files here: info@zzzprojects.com

We were not able to reproduce this, and we are not sure how registering those members will affect the Console.ReadLine. Perharp we are doing something different.

Best Regards,

Jonathan

@kller1993
Copy link
Author

using Z.Expressions;
{
int linec = 1;
int linec2 = 1;
string code = "";
string[] cmd = File.ReadAllLines(//Program//);
foreach (string line in cmd)
{
if (!line.Contains("//"))
{
if (line.StartsWith("using"))
{
string dll1 = line.Remove(0, 6);
Type dll = (dll1.Substring(0, dll1.Length - 1)).GetType();
EvalManager.DefaultContext.RegisterType(dll);
EvalManager.DefaultContext.RegisterAssembly(dll.Assembly);
EvalManager.DefaultContext.RegisterExtensionMethod(dll);
EvalManager.DefaultContext.RegisterMember(dll);
}
else
{
Console.WriteLine(Convert.ToString(linec2).PadLeft(10, ' ').PadRight(15, ' ') + Convert.ToString(linec).PadLeft(10, ' ').PadRight(15, ' ') + line);
code = code + line;
linec2++;
}
}
linec++;
}
var t = Eval.Execute(code);
}

Is a testing setup. Am trying to get it running with every possibility added one after another.
In cmd[] currently is written the file of the code to import, later it will be a Console.ReadLine();
And the Console.WriteLine is for controlling the code running.

@JonathanMagnan
Copy link
Member

Hello @kller1993 ,

My developer tried to reproduce the issue with the same code as you but still is not able to reproduce it.

So I believe a runnable project will be required (you can send private files here: info@zzzprojects.com) as we currently miss something to have the same behavior as you.

Best Regards,

Jon

@kller1993
Copy link
Author

Hello @JonathanMagnan ,

I just want to confirm, if you received the Mail with the .rar of the Project.
I included everything, even the lines I use to de/activate parts of code for testing.
I just want to confirm, as the first Mail got blocked, while for the second I still havent got any response.

Best Regards,

kller1993

@JonathanMagnan
Copy link
Member

Hello @kller1993 ,

We indeed got your project. I will answer directly to your email.

For people looking for the issue cause:

In the code, the RegisterAssembly was used for the type string assembly. However, doing it was also registering the assembly System.Private.CoreLib, which contains an Internal.Console. The Console from the Internal.Console was used, which doesn't contains the ReadLine method.

One solution instead to try to register all types is using the AutoAddMissingTypes options: https://eval-expression.net/options#autoaddmissingtypes

@kller1993
Copy link
Author

kller1993 commented Feb 15, 2023

Hello @JonathanMagnan ,

Am wondering, where my mistake is, as Auto doesnt seem to work.

public class TestingArea
{
    public static void Main()
    {
        var context = new EvalContext();
        context.RegisterAutoAddMissingTypeAssembly(typeof(TestingArea).Assembly);
        context.AutoAddMissingTypes = true;
        {
            var load = context.Execute<string>("TestingArea.Loader()");
            var t = context.Execute(load);
            Console.WriteLine("EndTest");
        }
    }
    public static string Loader()
    {
        int linec = 1;
        int linec2 = 1;
        string code = "";
        Console.WriteLine("Path:");
        string path = Console.ReadLine();
        string[] cmd = File.ReadAllLines(path);
        foreach (string line in cmd)
        {
            if (!line.Contains("//"))
            {
                if (!line.StartsWith("using"))
                {
                    //Console.WriteLine(Convert.ToString(linec2).PadLeft(10, ' ').PadRight(15, ' ') + Convert.ToString(linec).PadLeft(10, ' ').PadRight(15, ' ') + line);
                    code = code + line;
                    linec2++;
                }
            }
            linec++;
        }
        return code;
    }
}

It doesnt register at least types.

Edit:
Tried if adding

var context = new EvalContext();
        context.RegisterAutoAddMissingTypeAssembly(typeof(TestingArea).Assembly);
        context.AutoAddMissingTypes = true;

before the imported Code helps, but it only changed to missing the EvalContext type.

@JonathanMagnan
Copy link
Member

Hello @kller1993 ,

The first part to use TestingArea.Loader() work perfectly. Here is an online example very similar to your: https://dotnetfiddle.net/kOqaUM (I changed TestingArea to Program to make it compatible with Fiddle

I suspect what is not working is what is the code that will be returned by the Loader method.

A cause could also be that whenever you specify an assembly in the RegisterAutoAddMissingTypeAssembly, that means that missing types can only be retrieved from this assembly instead of all loaders assembly. That could maybe explain the issue.

If you could provide a full runnable example, that will surely be easier on our side to tell you exactly why this is not working.

Best Regards,

Jon

@JonathanMagnan
Copy link
Member

Hello @kller1993 ,

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

How is everything going?

Let me know if you need further assistance.

Best regards,

Jon

@JonathanMagnan
Copy link
Member

Hello again,

A simple reminder that we are here to assist you.

Don't hesitate to contact us if you need anything.

Best regards,

Jon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants