cs-script: Publish to single file gives an empty Assembly.Location which crashes Roslyn Evaluator

I’m running a .NET 7 WPF app with a reference to CSScriptLib nuget.

My project works great and scripts run right in debug mode. When I publish I get the error:

“Current version of Roslyn-based evaluator does not support referencing assemblies which are not loaded from the file location.”

I publish to a single file which merges most of the referenced dlls into a single dll. Looks like this code in Evaluator.Roslyn.cs is having a problem with it:

        public override IEvaluator ReferenceAssembly(Assembly assembly)
        {
            //Microsoft.Net.Compilers.1.2.0 - beta
            if (assembly.Location.IsEmpty())

I checked this in my code when publishing both to many files and to a single file and in the latter case Location is empty.

            if (string.IsNullOrEmpty(typeof(IRunScriptAsync).Assembly.Location))
                throw new System.Exception("Assembly.Location is empty");

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 22 (13 by maintainers)

Commits related to this issue

Most upvoted comments

It works! Amazing thank you.

dotnet publish -c Release --no-self-contained

Sorry for the confusion, I am using your project and yes it does work in self contained mode. The problem arises when deployed as Framework dependent, or self-contained = false.

I have always used Framework dependent deployments, due to a smaller file size, but I’m thinking self-contained does have benefits, and the bandwidth is not such a big deal these days. So deploying self-contained as the solution is not a problem.