Unfortunately csscript.CSSEnvironment.ScriptFile is not as reliable as I wanted it to be. The reason is that it was designed to server a very specific purposes during the script compilation (first run) and during script hosting. And this mechanism can be compromised by the caching or by existence of the cross-domain boundaries in hosting scenarios. That is why I have already (long time ago) implemented a proper mechanism for discovering the script name via assembly attribute:
string scriptFile = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyDescriptionAttribute>().Description;
The limitations of CSSEnvironment can be observed with <cs-script>\Samples\ReflectScript.cs sample. The following fragment of it works perfectly yields different output (empty CSSEnvironment #*) if executed in Notepad++ because the editor hosts the script engine.
PrintScriptName("reflection #1 ", () => CSScript.GetScriptName(Assembly.GetExecutingAssembly()));
PrintScriptName("reflection #2 ", () => Assembly.GetExecutingAssembly().GetScriptName());
PrintScriptName("reflection #3 ", () => GetScriptName(thisAsm));
PrintScriptName("Environment Var ", () => Environment.GetEnvironmentVariable("EntryScript"));
PrintScriptName("CSSEnvironment #1", () => CSSEnvironment.PrimaryScriptFile); //script that was executed from command line or double-clicked
PrintScriptName("CSSEnvironment #2", () => CSSEnvironment.ScriptFile); //script that is currently executed; it may not be a PrimaryScriptFile if it is a pre-execution scripting scenarioOnly now, after reading the corresponding section of the documentation I realized that I didn't bring the developers attention to these limitations. I'll do that in the next release. And I will also update the API XML documentation.
Keep in mind that you can also analyse CSScriptRuntimeLocation environment variable for the location of the cscs.exe.
Thus the code above should be enough to solve your problem. Just run the ReflectScript.cs sample in your environment and see which methods works the most reliable. Keep in mind that all "reflection #*" are using under the hood the same a primitive reflection algorithm.
Regards,
Oleg