From venky.92 at gmail.com Tue Apr 4 09:10:35 2017 From: venky.92 at gmail.com (Venkatesh Potluri) Date: Tue, 4 Apr 2017 18:40:35 +0530 Subject: [Ironpython-users] getting a PythonAst from a string containing Python code in c# Message-ID: Hi list, I am trying to get an IronPython.Compiler.Ast.PythonAst from a c# string containing some python code. How do I go about doing this in c#? My understanding is that I first have to create a parser using IronPython.Compiler.Parser.CreateParser() and then parse the code to get a PythonAst. However, I am not sure of the correct arguments required for the CreateParser() call, the SourceUnit required for a CompilerContext, etc. Also, the parser has a method ParseFile() that returns a PythonAst. Is there a way to parse a c# string containing the python code and get a PythonAst? I am new to IronPython so am not sure if I am missing something here. Thanks in advance. Best regards, Venkatesh From Petri.Alapiessa at varian.com Tue Apr 4 08:56:03 2017 From: Petri.Alapiessa at varian.com (Petri Alapiessa) Date: Tue, 4 Apr 2017 12:56:03 +0000 Subject: [Ironpython-users] Ironpython cannot load .Net DLL Message-ID: Hi, My company uses .NET and has libraries to application interface. I would like to use python to invoke application functions. A prerequisite is that I can load .NET DLL that interacts with that application. But I am stuck here, Ironpython cannot load one of the dependent DLL's or it's dependency. My python script references Components.dll, which in turn references some other .NET DLL's, including "Blaa.Blaa.Testing.Automation.dll". That is not found, see log below Here is my Ironpython script: -------------------------------------------------------------------------------------------------------------------------- import clr import sys sys.path.append('D:\\tfs\\sandbox\\calculatordemo\\calculatordemo\\_Dependencies') from exceptions import SystemError, Exception import System import System.Reflection clr.AddReference('Components') from System.Reflection import ReflectionTypeLoadException try: from Components import Calculator calculator = Calculator() calculator.Start() print Calculator.Ready() except System.Reflection.ReflectionTypeLoadException as e2: print e2.LoaderExceptions[0] except Exception as e2: print('Exception occurred: ' + e2.message) -------------------------------------------------------------------------------------------------------------------------- Output: System.IO.FileNotFoundException: Could not load file or assembly 'Blaa.Blaa.Testing.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bd317adc1d7d9856' or one of its dependencies. The system cannot find the file specified. File name: 'Blaa.Blaa.Testing.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bd317adc1d7d9856' === Pre-bind state information === LOG: DisplayName = Blaa.Blaa.Testing.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bd317adc1d7d9856 (Fully-specified) LOG: Appbase = file:///C:/Program Files (x86)/IronPython 2.7/ LOG: Initial PrivatePath = NULL Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Program Files (x86)\IronPython 2.7\ipy64.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: Post-policy reference: Blaa.Blaa.Testing.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bd317adc1d7d9856 LOG: The same bind was seen before, and was failed with hr = 0x80070002. --------------------------------------------------------------------------------------------------------------------------- All dependencies should be in _Dependencies-folder. Similar script created as C# project works. IL Spy does not show any dependencies that should not be available. Thanks for any help in helping to solve this! I did not yet find any help after several days of studies. Best Wishes, Petri Alapiessa -------------- next part -------------- An HTML attachment was scrubbed... URL: From slide.o.mix at gmail.com Tue Apr 4 10:54:21 2017 From: slide.o.mix at gmail.com (Slide) Date: Tue, 04 Apr 2017 14:54:21 +0000 Subject: [Ironpython-users] Ironpython cannot load .Net DLL In-Reply-To: References: Message-ID: Please try adding the Dependencies directory to the sys.path. You can do it like this: sys.path.append('path/to/Dependencies') On Tue, Apr 4, 2017, 07:52 Petri Alapiessa wrote: > Hi, > > My company uses .NET and has libraries to application interface. I would > like to use python to invoke application functions. A prerequisite is that > I can load .NET DLL that interacts with that application. > > But I am stuck here, Ironpython cannot load one of the dependent DLL's or > it's dependency. > > > > My python script references Components.dll, which in turn references some > other .NET DLL?s, including ?Blaa.Blaa.Testing.Automation.dll?. > > That is not found, see log below > > > > Here is my Ironpython script: > > > -------------------------------------------------------------------------------------------------------------------------- > > import clr > > import sys > > > sys.path.append('D:\\tfs\\sandbox\\calculatordemo\\calculatordemo\\_Dependencies') > > > > from exceptions import SystemError, Exception > > import System > > import System.Reflection > > > > clr.AddReference('Components') > > > > from System.Reflection import ReflectionTypeLoadException > > > > try: > > from Components import Calculator > > calculator = Calculator() > > calculator.Start() > > print Calculator.Ready() > > except System.Reflection.ReflectionTypeLoadException as e2: > > print e2.LoaderExceptions[0] > > except Exception as e2: > > print('Exception occurred: ' + e2.message) > > > -------------------------------------------------------------------------------------------------------------------------- > > Output: > > System.IO.FileNotFoundException: Could not load file or assembly > 'Blaa.Blaa.Testing.Automation, Version=3.0.0.0, Culture=neutral, > PublicKeyToken=bd317adc1d7d9856' or one of its dependencies. The system > cannot find the file specified. > > File name: 'Blaa.Blaa.Testing.Automation, Version=3.0.0.0, > Culture=neutral, PublicKeyToken=bd317adc1d7d9856' > > > > === Pre-bind state information === > > LOG: DisplayName = Blaa.Blaa.Testing.Automation, Version=3.0.0.0, > Culture=neutral, PublicKeyToken=bd317adc1d7d9856 > > (Fully-specified) > > LOG: Appbase = file:///C:/Program Files (x86)/IronPython 2.7/ > > LOG: Initial PrivatePath = NULL > > Calling assembly : (Unknown). > > === > > LOG: This bind starts in default load context. > > LOG: Using application configuration file: C:\Program Files > (x86)\IronPython 2.7\ipy64.exe.Config > > LOG: Using host configuration file: > > LOG: Using machine configuration file from > C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. > > LOG: Post-policy reference: Blaa.Blaa.Testing.Automation, Version=3.0.0.0, > Culture=neutral, PublicKeyToken=bd317adc1d7d9856 > > LOG: The same bind was seen before, and was failed with hr = 0x80070002. > > > --------------------------------------------------------------------------------------------------------------------------- > > > > All dependencies should be in _Dependencies-folder. Similar script created > as C# project works. IL Spy does not show any dependencies that should not > be available. > > > > Thanks for any help in helping to solve this! I did not yet find any help > after several days of studies. > > > > > > Best Wishes, > > > > Petri Alapiessa > > > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > https://mail.python.org/mailman/listinfo/ironpython-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Petri.Alapiessa at varian.com Wed Apr 5 02:24:14 2017 From: Petri.Alapiessa at varian.com (Petri Alapiessa) Date: Wed, 5 Apr 2017 06:24:14 +0000 Subject: [Ironpython-users] Ironpython cannot load .Net DLL In-Reply-To: References: Message-ID: It?s already there, 3. line. The error disappears when I add DLL to GAC. But it?s a workaround. I am still interested can this be fixed otherwise. From: Slide [mailto:slide.o.mix at gmail.com] Sent: 04 April 2017 17:54 To: Petri Alapiessa ; ironpython-users at python.org Subject: Re: [Ironpython-users] Ironpython cannot load .Net DLL Please try adding the Dependencies directory to the sys.path. You can do it like this: sys.path.append('path/to/Dependencies') On Tue, Apr 4, 2017, 07:52 Petri Alapiessa > wrote: Hi, My company uses .NET and has libraries to application interface. I would like to use python to invoke application functions. A prerequisite is that I can load .NET DLL that interacts with that application. But I am stuck here, Ironpython cannot load one of the dependent DLL's or it's dependency. My python script references Components.dll, which in turn references some other .NET DLL?s, including ?Blaa.Blaa.Testing.Automation.dll?. That is not found, see log below Here is my Ironpython script: -------------------------------------------------------------------------------------------------------------------------- import clr import sys sys.path.append('D:\\tfs\\sandbox\\calculatordemo\\calculatordemo\\_Dependencies') from exceptions import SystemError, Exception import System import System.Reflection clr.AddReference('Components') from System.Reflection import ReflectionTypeLoadException try: from Components import Calculator calculator = Calculator() calculator.Start() print Calculator.Ready() except System.Reflection.ReflectionTypeLoadException as e2: print e2.LoaderExceptions[0] except Exception as e2: print('Exception occurred: ' + e2.message) -------------------------------------------------------------------------------------------------------------------------- Output: System.IO.FileNotFoundException: Could not load file or assembly 'Blaa.Blaa.Testing.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bd317adc1d7d9856' or one of its dependencies. The system cannot find the file specified. File name: 'Blaa.Blaa.Testing.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bd317adc1d7d9856' === Pre-bind state information === LOG: DisplayName = Blaa.Blaa.Testing.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bd317adc1d7d9856 (Fully-specified) LOG: Appbase = file:///C:/Program Files (x86)/IronPython 2.7/ LOG: Initial PrivatePath = NULL Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Program Files (x86)\IronPython 2.7\ipy64.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: Post-policy reference: Blaa.Blaa.Testing.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bd317adc1d7d9856 LOG: The same bind was seen before, and was failed with hr = 0x80070002. --------------------------------------------------------------------------------------------------------------------------- All dependencies should be in _Dependencies-folder. Similar script created as C# project works. IL Spy does not show any dependencies that should not be available. Thanks for any help in helping to solve this! I did not yet find any help after several days of studies. Best Wishes, Petri Alapiessa _______________________________________________ Ironpython-users mailing list Ironpython-users at python.org https://mail.python.org/mailman/listinfo/ironpython-users -------------- next part -------------- An HTML attachment was scrubbed... URL: