Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# dynamic compilation and "Microsoft.CSharp.dll" error

I'm doing the example that can be found here. So I'm trying to run IronPython in a C# script:

Python:

def hello(name):
    print "Hello " + name + "! Welcome to IronPython!"
    return

def add(x, y):
    print "%i + %i = %i" % (x, y, (x + y))
    return

def multiply(x, y):
    print "%i * %i = %i" % (x, y, (x * y))
    return

C#:

using IronPython.Hosting;
using IronPython.Runtime;
using Microsoft.Scripting.Hosting;
using System;

namespace IntroIronPython
{
    class IronPythonMain
    {
        static void Main(string[] args)
        {
            // Create a new ScriptRuntime for IronPython
            Console.WriteLine("Loading IronPython Runtime...");
            ScriptRuntime python = Python.CreateRuntime();

            try
            {
                // Attempt to load the python file
                Console.WriteLine("Loading Python File...");
                // Create a Dynamic Type for our Python File
                dynamic pyfile = python.UseFile("PythonFunctions.py");
                Console.WriteLine("Python File Loaded!");

                Console.WriteLine("Running Python Commands...\n");

                // Call the hello(name) function
                pyfile.hello("Urda");
                …

And from here I have this error: "Dynamic Operation cannot be compiled without "Microsoft.CSharp.dll" assembly reference." And I seriously don't understand what that is about, what did I forget to add?

In my references I have: References of my project

Thx for your help.

Ps: I'm on MonoDevelop.

like image 225
ssx Avatar asked Jul 10 '12 15:07

ssx


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Why is C named so?

Quote from wikipedia: "A successor to the programming language B, C was originally developed at Bell Labs by Dennis Ritchie between 1972 and 1973 to construct utilities running on Unix." The creators want that everyone "see" his language. So he named it "C".


2 Answers

This is what helped me. I am using Xamarian Studio v5.8.1 (build 8) to write a C# program. I just had to right click "References" -> "Edit References" -> started typing "Microsoft" in the search bar -> Checked the box next to "Microsoft.CSharp" -> and clicked "OK".

I just saved and ran the program after that - everything works as expected!

like image 188
tylerlindell Avatar answered Sep 22 '22 16:09

tylerlindell


Ok. Basically, my mistake was linked to the fact that I added my IronPython assemblies from the wrong platform. Verify that:

  • Target Framework: 4.0

  • Add all the assemblies provided by IronPython in [IronPython-2.7.3]->[Platforms]->[Net40].

Thx to everyone who gave me advices.

Ps:Now, of course, there is another problem… But it's not about that topic anymore.

like image 26
ssx Avatar answered Sep 19 '22 16:09

ssx