profile
viewpoint

husk3r/cs-script 0

C# scripting platform

husk3r/uncrustify 0

Code beautifier

issue commentoleg-shilo/cs-script

Double Entry Point Definition

Thanks a lot for fixing this issue!

husk3r

comment created time in 6 days

issue openedoleg-shilo/cs-script

Double Entry Point Definition

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: C# 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:

First, I think the parser which is looking for the Main method is not working:

diff --git a/src/cscs/csparser.cs b/src/cscs/csparser.cs
index 3f17a61..a7d7c59 100644
--- a/src/cscs/csparser.cs
+++ b/src/cscs/csparser.cs
@@ -701,7 +701,7 @@ namespace csscript
                 }
                 while (declarationStart != -1 && renamingPos == -1);
 
-                pos = FindStatement("Main", pos + 1);
+                pos = FindStatement("Main", pos);
             }
             if (renamingPos != -1)
                 renamingPositions.Add(new RenamingInfo(renamingPos, renamingPos + "Main".Length, "i_Main"));

Same here

diff --git a/src/CSScriptLib/src/CSScriptLib/csparser.cs b/src/CSScriptLib/src/CSScriptLib/csparser.cs
index cbcaba5..8f5d4ac 100644
--- a/src/CSScriptLib/src/CSScriptLib/csparser.cs
+++ b/src/CSScriptLib/src/CSScriptLib/csparser.cs
@@ -630,7 +630,7 @@ namespace CSScriptLib
                 }
                 while (declarationStart != -1 && renamingPos == -1);
 
-                pos = FindStatement("Main", pos + 1);
+                pos = FindStatement("Main", pos);
             }
             if (renamingPos != -1)
                 renamingPositions.Add(new RenamingInfo(renamingPos, renamingPos + "Main".Length, "i_Main"));

The main function got renamed after that, but the wrong file is included in project:

diff --git a/src/cscs/ScriptParser.cs b/src/cscs/ScriptParser.cs
index 8ff8465..f6ddb52 100644
--- a/src/cscs/ScriptParser.cs
+++ b/src/cscs/ScriptParser.cs
@@ -247,7 +247,7 @@ namespace CSScriptLib
 
                         this.fileParsers.Add(importedFile);
                         this.fileParsers.Sort(fileComparer);
-                        importedFile.fileNameImported = importedFile.fileName;
+                        //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

created time in 11 days

more