oleg-shilo / cs-script

C# scripting platform
http://www.cs-script.net
MIT License
1.62k stars 235 forks source link

Double Entry Point Definition #260

Closed husk3r closed 2 years ago

husk3r commented 2 years ago

Hi there,

I'm currently trying to upgrade a bigger CS Script environment from 3.28.x to 4.2.0.0. At the moment I'm debugging a scenario where two public static int Main(string[] args) signatures are available at the same time.

Let's say is test.cs:

//css_nuget CS-Script
//css_import script
using System;
public class My
{
    public static void Main(string[] args)
    {
        Script.MyFunction();
    }
}

And script.cs:

using System;
using System.Linq;
using System.Collections.Generic;
using static dbg; // to use 'print' instead of 'dbg.print'
using CSScriptLib;

public class Script
{
    public static void MyFunction()
    {
        (string message, int version) setup_say_hello()
        {
            return ("Hello from C#", 9);
        }

        var info = setup_say_hello();

        print(info.message, info.version);

        print(Environment.GetEnvironmentVariables()
                            .Cast<object>());
    }
    public static void Main(string[] args)
    {
        MyFunction();
    }
}

When I start cscs test.cs the script fails with:

error CS0017: Program has more than one entry point defined

In addition, I started a debug session with ccs -vs test.cs. And here some strange things showed up. The script.cs file and its main function got not renamed by CS Script. I started a small debugging step and found some issues.

The main function got renamed after importedFile.ProcessFile(); in ScriptParser.cs, but the wrong file is included in project:

diff --git a/src/cscs/ScriptParser.cs b/src/cscs/ScriptParser.cs
index 8ff8465..7698abb 100644
--- a/src/cscs/ScriptParser.cs
+++ b/src/cscs/ScriptParser.cs
@@ -247,7 +247,6 @@ namespace CSScriptLib

                         this.fileParsers.Add(importedFile);
                         this.fileParsers.Sort(fileComparer);
-                        importedFile.fileNameImported = importedFile.fileName;

                         foreach (string namespaceName in importedFile.ReferencedNamespaces)
                             PushNamespace(namespaceName);

Here I'm not sure if my patch is correct but at least it worked in my case ;-)

Regards, Florian

oleg-shilo commented 2 years ago

Indeed it is a defect. Thank you. Fixed. Will be available in the very next release.

husk3r commented 2 years ago

Thanks a lot for fixing this issue!