Click here to Skip to main content
15,887,361 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more: , +
Adding to the previous questions I have asked:

How I can execute C# code using Roslyn in ASP.Net web form?


I want to know about Roslyn API ( execute ).
how should its input should be and waht's the output.
Preiously I explained that I try it with the console application in C# and it works however when I build the GUI using ASP .Net web form application it handle an error (NullReferenceException).

How could I find the code of execute API?

This is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using Roslyn.Scripting;
using Roslyn.Scripting.CSharp;
using Roslyn.Compilers;
using Roslyn.Compilers.CSharp;
using System.IO;

namespace WebApplication2
{
    public partial class _Default : Page
    {

        //private object result = new object();


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button_Click(object sender, EventArgs e)
        {
            String code = TextBox3.Text;
            var ScriptEngine = new ScriptEngine();
            var session = ScriptEngine.CreateSession();
            try
            {
                session.AddReference("System");
                session.AddReference("System.core");
                object result = session.Execute(code);
                TextBox2.Text = result.ToString();
            }
            catch (System.NullReferenceException err)
            {
                TextBox2.Text = err.Message;
            }

           



        }


    }
}
Posted
Updated 30-Mar-14 20:32pm
v3
Comments
Prasad Khandekar 31-Mar-14 2:40am    
Hello Mohammed,

Please have a look at http://msdn.microsoft.com/en-us/vstudio/hh500769.aspx.

Regards,

1 solution

This is not trivial stuff and you should do you homework better next time.

As lazy as I am at this moment I have found this in under a minute with little help from Google!

Read this:
Introduction to the Roslyn Scripting API
Using The Roslyn Scripting API in C#
and
C# as a Scripting Language in Your .NET Applications Using Roslyn by our fellow coder.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900