Closed yejinmo closed 2 years ago
The problem is with the Roslyn engine that expects the Roslyn not to support referencing loaded assemblies that have no assembly file available.
Meaning that you need to find a way to discover the location (e.g. Location()
vs .Location
) of that assembly.
CSScript.Evaluator.ReferenceAssemblyByNamespace("NPOI")
.ReferenceAssembly(typeof<ISheet>.Location()) // potentially better option
.LoadCode(...);
And... if you cannot then... it's not much you can do. Note, it is not a limitation of CS-Script but Roslyn.
The other option I can see is to try to use dynamic types instead of interfaces. You will lose type safety but will gain flexibility.
Another approach is to try to pass the host application instead. If the 'Single File' compiling option does what ILMerge does then the interface assembly is the same as the entry assembly.
On another topic, your code will not work as expected. You create and abandon a new instance evaluator every time you call ReferenceAssembly...
.
Please use Fluent Interface syntax (my code snippet) or simply create the instance of evaluator and then use it directly.
The problem is with the Roslyn engine that expects the Roslyn not to support referencing loaded assemblies that have no assembly file available.
Meaning that you need to find a way to discover the location (e.g.
Location()
vs.Location
) of that assembly.CSScript.Evaluator.ReferenceAssemblyByNamespace("NPOI") .ReferenceAssembly(typeof<ISheet>.Location()) // potentially better option .LoadCode(...);
And... if you cannot then... it's not much you can do. Note, it is not a limitation of CS-Script but Roslyn.
The other option I can see is to try to use dynamic types instead of interfaces. You will lose type safety but will gain flexibility.
Another approach is to try to pass the host application instead. If the 'Single File' compiling option does what ILMerge does then the interface assembly is the same as the entry assembly.
On another topic, your code will not work as expected. You create and abandon a new instance evaluator every time you call
ReferenceAssembly...
.Please use Fluent Interface syntax (my code snippet) or simply create the instance of evaluator and then use it directly.
Thanks for the suggestion, it looks like the problem is not that simple, I will disable Single File to keep the functionality available.
Description
Can .Net 6 Single File work with
ReferenceAssemblyOf()
?Code:
Crash:
Configuration
pubxml:
Other information
The point is
src/CSScriptLib/src/CSScriptLib/Evaluator.Roslyn.cs
:But:
Does it mean that Single File cannot be used with
ReferenceAssemblyOf()
? If so is there any other way to achieve something likeReferenceAssemblyOf()
?Thanks.