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

  • Home
  • SEARCH
  • 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 8095159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:01:46+00:00 2026-06-05T21:01:46+00:00

Sometime back I wrote a program using Mono compiler as a service as using

  • 0

Sometime back I wrote a program using Mono compiler as a service as

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.CSharp;

namespace MonoTest
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initializing the evaluator
            Evaluator.Init(new string[0]);           

            //Importing namespaces 
            Evaluator.Run("using System;");
            Evaluator.Run("using System.Linq;");
            Evaluator.Run("using System.Collections.Generic;");

            //Sum of 'n' numbers
            Evaluator.Run("List<int> numbers= new List<int> {1,2,3,4,5,6,7,8,9,10} ;");
            Evaluator.Run("var sum = numbers.Sum();");
            Evaluator.Run("Console.WriteLine(sum);");
        }
    }
}

//output

55

Now trying to do the same using Roslyn (my very first code)[Roslyn Project Type:console Application]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Roslyn.Scripting;
using Roslyn.Scripting.CSharp;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            var host = new ScriptingHost();
            string codeLine = string.Empty;
            codeLine += "List<int> numbers= new List<int> {1,2,3,4,5,6,7,8,9,10} ;" + Environment.NewLine;
            codeLine += "var sum = numbers.Sum();";
            codeLine += "Console.WriteLine(sum);";

            var res = host.Execute(codeLine);

            //Write the result back to console
            if (res != null)
                Console.WriteLine(" = " + res.ToString());

            Console.ReadKey();

        }
    }

    public class ScriptingHost
    {
        private ScriptEngine engine;
        private Session session;       

        public ScriptingHost()
        {
            //Create a session
            session = Session.Create(this);

            //Create the engine, just pass the assemblies and namespaces
            engine = new ScriptEngine(new Assembly[]
                                {
                                    typeof(Console).Assembly,
                                    typeof(ScriptingHost).Assembly,
                                    typeof(IEnumerable<>).Assembly,
                                    typeof(IQueryable).Assembly
                                },
                                new string[] 
                                { 
                                    "System", "System.Linq", 
                                    "System.Collections",
                                    "System.Collections.Generic"
                                }
                            );

        }

        //Pass the code to the engine, nothing much here
        public object Execute(string code)
        {
            return engine.Execute(code, session); --Error at this line
        }
    }
}

But getting this error

“(1,34): error CS8000: This language feature (‘object creation expression with initializer’) is not yet implemented in Roslyn.”

Please help

  • 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-05T21:01:49+00:00Added an answer on June 5, 2026 at 9:01 pm

    Looks like you will have to separate the creation of your list from populating it:

    codeLine += "List<int> numbers= new List<int>();";
    codeLine += "var values = new int[] {1,2,3,4,5,6,7,8,9,10};";
    codeLine += "numbers.AddRange(values);";
    

    Edit: or use the constructor overload which takes a list as suggested by @svick in the comments:

    codeLine += "var numbers = new List<int>(new int[] {1,2,3,4,5,6,7,8,9,10});";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using C# to write a program that uses a web service from
Some time back, I created two separate SharePoint projects in VS 2008; one using
I open up a notepad from my program using Process.Start() but the new opened
I have a program that simulates a text editor. It lets users add lines
I wrote a peer-to-peer networked game in Java using the java.net package and for
Here's the situation. Using a C# program, I have to POST big chunks of
At one point I wrote a packet capture program in haskell and it used
Whenever I type in a phone number, this program below that I wrote to
I wrote a multi user app in c# some time age using SQL Server
I have been using WPF and its built in validation controls for quiet sometime.

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.