0

I have some IronPython code, and im passing variables to it and want to receive a result from python. I managed to get the result from IronPython when i create an engine in the current domain:

ScriptEngine pyEngine = IronPython.Hosting.Python.CreateEngine()

then i just take the result like that:

var result = this.pyScope.GetVariable("ObiektMS").code_1_1_1("II");

However, I need it sandboxed so im creating an AppDomain with restricted permissions and running the engine in it:

ScriptEngine pyEngine = IronPython.Hosting.Python.CreateEngine(newDomain)

But this time when i try to get the result in the samy way i get

An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in PythonTimeTests.exe

Is it because my "result" variable is in a different domain and the result from ironpython has to be serialized?

Is it possible to create a variable in the new domain? I want my program to do this:

1.Read a dictionary from a file.

2.Create a new domain with restrictions and pass the dictionary to it.

3.Do work in iron python by calling python functions from c#(all in restricted domain)

4.Return the results to the unrestricted domain.

Kuczi
  • 357
  • 4
  • 18

1 Answers1

1

Yes - cross domain variables are serialized between domains unless they inherit from MarshallByRefObject as explained here Sharing data between AppDomains

Your second question is "can I ... do some C# stuff" - yes; you can do anything you want in an AppDomain. You just need to follow the rules on AppDomain data transfer in order to pass stuff between AppDomains.

Community
  • 1
  • 1
PhillipH
  • 6,182
  • 1
  • 15
  • 25