internal void ValidateReferences(CommonCompilation compilation, DiagnosticBag diagnostics) { foreach (AssemblyIdentity identity in compilation.ReferencedAssemblyNames) { if (CommonScriptEngine.IsReservedAssemblyName(identity)) { DiagnosticBagExtensions.Add(diagnostics, ErrorCode.ERR_ReservedAssemblyName, (Location)null, new object[1] { (object)identity.GetDisplayName(false) }); } } }
private void Initialize() { this.scripting = new ScriptEngine( new[] { typeof(string).Assembly, // mscorlib typeof(System.Diagnostics.Stopwatch).Assembly, // System.dll typeof(Enumerable).Assembly, // System.Core.dll typeof(LoggingRewriter).Assembly, // this }, new[] { "System", "System.Collections.Generic", "System.Diagnostics", "System.Linq" }); SyntaxTree.ParseCompilationUnit(String.Empty); }
public CondenseLiteralsRewriter() { engine = new ScriptEngine(); session = engine.CreateSession(); }
protected override void RunInteractive(RunOptsBase opts, RunResult result) { new PermissionSet(PermissionState.Unrestricted).Assert(); CommonScriptEngine scriptEngine = this.CreateSciptEngine(); Session session = scriptEngine.CreateSession(); var codeBlock = (ConsoleOrScriptCodeBlock)opts.CodeBlock; var referencedDlls = this.GetGacDlls(codeBlock.CodeBlock); foreach (var referenceDll in referencedDlls) { session.AddReference(referenceDll); } var libs = GetNonGacDlls(); foreach (var path in libs) { session.AddReference(path); } Submission <object> submission; try { // we compile code there submission = session.CompileSubmission <object>(codeBlock.CodeBlock); } catch (ThreadAbortException) { throw; } catch (Exception ex) { if (!string.IsNullOrEmpty(ex.Message) && ex.Message.Contains(ErrorWhenCompileConsoleProjectAsScript)) { /*Case 4067: DotNetFiddle throws exception on VbNet Script * https://entech.fogbugz.com/default.asp?4067#31607 * This issue occurs, when user is trying to compile VB.Net Console project as VB.Net Script project. * So, there is main entry point 'Module Sub Main' in snippet. * Then Roslyn throws following exception "(3) : error BC35000: Requested operation is not available because the runtime library function 'Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute..ctor' is not defined." * In same case for C#, Roslyn just ignores 'console' code. * So for VB.Net case we just return 'success' and empty string. */ result.IsSuccess = true; result.ConsoleOutput = ""; } else { ValidateCodeResult validateCodeResult = ValidateCode(codeBlock.CodeBlock); result.IsSuccess = false; result.FailureType = RunResultFailureType.CompilerErrors; result.CompilerErrors = validateCodeResult.Errors; } if (result.CompilerErrors == null) { result.CompilerErrors = new List <ValidationError> { ValidationError.CreateFromException(ex) }; } TryCleanRoslynCacheHack(); PermissionSet.RevertAssert(); return; } object execResult = null; try { this.OnStartingExecution(); PermissionSet.RevertAssert(); execResult = submission.Execute(); this.OnFinishedExecution(); } catch (ThreadAbortException) { throw; } catch (Exception ex) { result.IsSuccess = false; result.FailureType = RunResultFailureType.RunTimeException; result.RunTimeException = new ExceptionInfo(ex); } finally { result.ConsoleOutput = _consoleWriter.ToString().TrimEnd(); if (execResult != null) { result.ConsoleOutput += Environment.NewLine; result.ConsoleOutput += "[Return value]: " + execResult; } // don't need it as we modified Roslyn assemblies and made fix in them // TryCleanRoslynCacheHack(); } }
private void Initialize() { this.scripting = new ScriptEngine ( new[] { typeof (string).Assembly, // mscorlib typeof (System.Diagnostics.Stopwatch).Assembly, // System.dll typeof (Enumerable).Assembly, // System.Core.dll typeof (LoggingRewriter).Assembly, // this }, new[] { "System", "System.Collections.Generic", "System.Diagnostics", "System.Linq" }); SyntaxTree.ParseCompilationUnit (String.Empty); }