Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8920729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:21:03+00:00 2026-06-15T06:21:03+00:00

I am embedding a C# script engine into my application using Roslyn and so

  • 0

I am embedding a C# script engine into my application using Roslyn and so far, I can execute code with no issues. I can for example execute the following code:

using System;
var str = "Hello Roslyn";
Console.WriteLine(str);

I am facing compilation issues when building my syntax tree out the code snippet above. The compiler complains about statements directly embedded into the main namespace which makes sense when writing a normal C# program but not in my case as I am going the script way.

Question:
Is there a way to build an error free syntax tree out of a C# script?

EDIT
Here is the code I am using to build the syntax tree.

SyntaxTree tree = SyntaxTree.ParseText(context.SourceCode);
Compilation compilation = Compilation.Create("CSharp", syntaxTrees: new[] {tree}, references: references);

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:21:05+00:00Added an answer on June 15, 2026 at 6:21 am

    You need to specify that you’re parsing script code instead of regular code:

    SyntaxTree tree = SyntaxTree.ParseText(source, options: new ParseOptions(kind: SourceCodeKind.Script));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The application I am working on allows embedding script sinppets into a document. For
I'm using the example in python's 2.6 docs to begin a foray into embedding
I am embedding a report into my ASP.NET app using the report viewer control.
I'm thinking about embedding arbitrary JSON in the DOM like this: <script type=application/json id=stuff>
I am embedding a Youtube video on a website using swfObject so I can
I am embedding a swf file into the parent swf file and my code
I am embedding Lua in a C++ application, and I am using luaL_dofile to
When embedding a JavaScript interpreter (Rhino) into a Java application (to be able to
I'm trying to run the embedding example and I can't load a module from
I am running groovy by embedding it in a Java application via the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.