4

I have written code for my game that need to run a function of my python code. I am using Ironpython for my project. However, when I am trying to use C# dynamic typing to call a function in the code below, it compiles but I get the following error from the Internals:

" Assets/Scripts/WordSearchAlgorithm.cs(37,29): error CS1502: The best overloaded method match for
System.Runtime.CompilerServices.CallSite,object>>.Create(System.Runtime.CompilerServices.CallSiteBinder)' has some invalid arguments " "
Assets/Scripts/WordSearchAlgorithm.cs(37,29): error CS1503: Argument
'#1' cannot convert 'object' expression to type
'System.Runtime.CompilerServices.CallSiteBinder' " "
Assets/Scripts/WordSearchAlgorithm.cs(37,61): error CS0234: The type
or namespace name 'RuntimeBinder' does not exist in the namespace
`Microsoft.CSharp'. Are you missing an assembly reference? "
Assets/Scripts/WordSearchAlgorithm.cs(37,61): error CS1502: The best
overloaded method match for 'System.Runtime.CompilerServices.CallSite>.Create(System.Runtime.CompilerServices.CallSiteBinder)' has some invalid arguments

I think mono doesn't support this. Could you please give me a solution to help me?

static public void StartSearchAlgorithm()
{
    List < string > myList = new List < string > ()
    {
        "fxie",
         "amlo",
         "ewbx",
         "astu"
    };
    var ironPythonRuntime = Python.CreateRuntime();
    try
    {
        //Load the Iron Python file/script into the memory
        //Should be resolve at runtime
        dynamic loadIPython = ironPythonRuntime.UseFile("C:/py.py");
        //Invoke the method and print the result
        loadIPython.BoggleWords(myList, loadIPython.MakeTrie("C:/words.txt")); // here is my problem to calling function from python that unity logError
        //    Debug.Log(string.Format("dd", loadIPython.BoggleWords(myList, loadIPython.MakeTrie("C:/words.txt"))));
    }
    catch (FileNotFoundException ex)
    {}
}
Yannick Meeus
  • 5,643
  • 1
  • 35
  • 34
Amirhossein
  • 39
  • 1
  • 8

1 Answers1

2

Unity uses the Mono 2.0 version of .NET, which is similar to .NET 3.5. dynamic was introduced in .NET 4.0, so Unity will probably not compile.

There is the option to change Mono 2.0 sub to Mono 2.0 full in the Player Settings, but I don't know if that supports dynamic. At least you can try.

enter image description here

Community
  • 1
  • 1
Marnix
  • 6,384
  • 4
  • 43
  • 78
  • I am trying to change Mono 2.0 sub to Mono 2.0 full in the Player Settings but error still exist – Amirhossein Mar 18 '16 at 11:31
  • Then it is not supported in Mono 2.0. Also see this answer: http://answers.unity3d.com/questions/686244/using-c-dynamic-typing-with-unity-434f1.html – Marnix Mar 18 '16 at 12:14
  • Thanks Marnix for your Answering , I had seen this topic before but like code above. I want to call my Python function that without using C# dynamic typing do not work . I don't know maybe should change my coding – Amirhossein Mar 18 '16 at 12:27
  • Can you find an IronPython library that uses .NET 3.5 maybe? – Marnix Mar 18 '16 at 12:42
  • I had used IronPython 2.6 from C#4.0 , but unity had errors for its Libraries – Amirhossein Mar 18 '16 at 13:13
  • IronPython 2.7.5 seems to have Net35 dll's as well. Try to reference those in your project and see if it doesn't use `dynamic`. – Marnix Mar 18 '16 at 13:17