In the following code I need to add my assembly so that the script can make use of its classes:
var options = ScriptOptions.Default.AddImports("MyAssembly");
var code = "using MyAssembly.MyNamespace;" +
"public class TestClass {" +
" public int HelloWorld(int num) {" +
" return 5 + num;" +
" }" +
"}";
But the following exception is thrown:
Exception thrown: 'Microsoft.CodeAnalysis.Scripting.CompilationErrorException' in Microsoft.CodeAnalysis.Scripting.dll Microsoft.CodeAnalysis.Scripting.CompilationErrorException: error CS0246: The type or namespace name 'MyAssembly' could not be found (are you missing a using directive or an assembly reference?)
I added the assembly in the host project too. I've also tried the examples from here but they didn't work either.
What is the correct syntax to add an assembly?
See Question&Answers more detail:os