[IronPython] Importing System in IronPython 2 beta 5

Serge R deus.verus at gmail.com
Sun Sep 21 17:23:47 CEST 2008


Works like a charm, thank you.

On 9/22/08, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
>
> Ronnie Maor wrote:
>
>> I get the same problem.
>>
>> Another symptom is that "import System" fails if you don't AddReference
>> first. never needed to do that for IPy 1.1 and don't need to either when
>> running ipy 2.0.
>>
>>
> When embedding IronPython you need to add references to both 'System.dll'
> and 'mscorlib.dll'. This is done for you in the console, but not when
> embedding IronPython.
>
> You can do this using the 'LoadAssembly' method of the ScriptRuntime:
>
> _runtime.LoadAssembly(typeof(String).Assembly);
> _runtime.LoadAssembly(typeof(Uri).Assembly);
>
> Michael
>
> It fails with my hosting code, and also reproduces with the "hello world"
>> hosting sample:
>>
>> http://blogs.msdn.com/seshadripv/archive/2008/09/11/dlr-hosting-sample-simple-dlr-host-using-the-new-app-config-based-scriptruntime-creation.aspx
>>
>> The only changes I made to the sample were
>> 1) delete ruby configuration from App.config and the line of code that
>> builds a ruby engine (I don't have the assemblies for ruby)
>> 2) change the line defining the source code to:
>>            ScriptSource source =
>> pyEng.CreateScriptSourceFromString(@"import System",
>> SourceCodeKind.Statements);
>> 3) remove the code that gets the "output" variable from pyEng (since we
>> don't produce it)
>>
>> like I said, this fails with "No module named System".
>> If you add a clr.AddReference("System"), then import works, but dir()
>> seems to only show namespaces and not types, so import System.DateTime will
>> fail.
>>
>> I'm now looking at sources for IronPythonConsole to see what the
>> difference is, but if someone knows what I'm doing wrong, please tell...
>>
>> thanks
>> Ronnie
>>
>> On Sun, Sep 21, 2008 at 8:31 AM, Serge R <deus.verus at gmail.com <mailto:
>> deus.verus at gmail.com>> wrote:
>>
>>    I am migrating from 1.1 and have been unable to import System.Math
>>    class. I took a look at what's actually been imported
>>
>>    clr.AddReference("System")
>>    import System
>>    print dir(System)
>>
>>    On IP2 I got a small list that didn't contain Math or many other
>>    classes. Am I referencing something wrong?
>>
>>    IP2 List:
>>    ['CodeDom', 'Collections', 'ComponentModel', 'Configuration',
>>    'Diagnostics', 'FileStyleUriParser', 'FtpStyleUriParser',
>>    'GenericUriParser', 'GenericUriParserOptions',
>>    'GopherStyleUriParser', 'HttpStyleUriParser', 'IO',
>>    'LdapStyleUriParser', 'Media', 'Net', 'NetPipeStyleUriParser',
>>    'NetTcpStyleUriParser', 'NewsStyleUriParser', 'Runtime',
>>    'Security', 'Text', 'Threading', 'Timers', 'Uri', 'UriBuilder',
>>    'UriComponents', 'UriFormat', 'UriFormatException',
>>    'UriHostNameType', 'UriIdnScope', 'UriKind', 'UriParser',
>>    'UriPartial', 'UriTypeConverter', 'Web']
>>
>>    IP1 List:
>>    ['AccessViolationException', 'Action', 'ActivationContext',
>>    'Activator', 'AppDomain', 'AppDomainInitializer',
>>    'AppDomainManager', 'AppDomainManagerInitializationOptions',
>>    'AppDomainSetup', 'AppDomainUnloadedException',
>>    'ApplicationException', 'ApplicationId', 'ApplicationIdentity',
>>    'ArgIterator', 'ArgumentException', 'ArgumentNullException',
>>    'ArgumentOutOfRangeException', 'ArithmeticException', 'Array',
>>    'ArraySegment', 'ArrayTypeMismatchException',
>>    'AssemblyLoadEventArgs', 'AssemblyLoadEventHandler',
>>    'AsyncCallback', 'Attribute', 'AttributeTargets',
>>    'AttributeUsageAttribute', 'BadImageFormatException',
>>    'Base64FormattingOptions', 'BitConverter', 'Boolean', 'Buffer',
>>    'Byte', 'CLSCompliantAttribute', 'CannotUnloadAppDomainException',
>>    'Char', 'CharEnumerator', 'CodeDom', 'Collections', 'Comparison',
>>    'ComponentModel', 'Configuration', 'Console',
>>    'ConsoleCancelEventArgs', 'ConsoleCancelEventHandler',
>>    'ConsoleColor', 'ConsoleKey', 'ConsoleKeyInfo',
>>    'ConsoleModifiers', 'ConsoleSpecialKey', 'ContextBoundObject',
>>    'ContextMarshalException', 'ContextStaticAttribute', 'Convert',
>>    'Converter', 'CrossAppDomainDelegate', 'DBNull',
>>    'DataMisalignedException', 'DateTime', 'DateTimeKind',
>>    'DateTimeOffset', 'DayOfWeek', 'Decimal', 'Delegate',
>>    'Deployment', 'Diagnostics', 'DivideByZeroException',
>>    'DllNotFoundException', 'Double', 'DuplicateWaitObjectException',
>>    'EntryPointNotFoundException', 'Enum', 'Environment',
>>    'EnvironmentVariableTarget', 'EventArgs', 'EventHandler',
>>    'Exception', 'ExecutionEngineException', 'FieldAccessException',
>>    'FileStyleUriParser', 'FlagsAttribute', 'FormatException',
>>    'FtpStyleUriParser', 'GC', 'GCCollectionMode', 'GenericUriParser',
>>    'GenericUriParserOptions', 'Globalization',
>>    'GopherStyleUriParser', 'Guid', 'HttpStyleUriParser',
>>    'IAppDomainSetup', 'IAsyncResult', 'ICloneable', 'IComparable',
>>    'IConvertible', 'ICustomFormatter', 'IDisposable', 'IEquatable',
>>    'IFormatProvider', 'IFormattable', 'IO', 'IServiceProvider',
>>    'IndexOutOfRangeException', 'InsufficientMemoryException',
>>    'Int16', 'Int32', 'Int64', 'IntPtr', 'InvalidCastException',
>>    'InvalidOperationException', 'InvalidProgramException',
>>    'LdapStyleUriParser', 'LoaderOptimization',
>>    'LoaderOptimizationAttribute', 'LocalDataStoreSlot',
>>    'MTAThreadAttribute', 'MarshalByRefObject', 'Math', 'Media',
>>    'MemberAccessException', 'MethodAccessException',
>>    'MidpointRounding', 'MissingFieldException',
>>    'MissingMemberException', 'MissingMethodException',
>>    'ModuleHandle', 'MulticastDelegate',
>>    'MulticastNotSupportedException', 'Net', 'NetPipeStyleUriParser',
>>    'NetTcpStyleUriParser', 'NewsStyleUriParser',
>>    'NonSerializedAttribute', 'NotFiniteNumberException',
>>    'NotImplementedException', 'NotSupportedException',
>>    'NullReferenceException', 'Nullable', 'Object',
>>    'ObjectDisposedException', 'ObsoleteAttribute', 'OperatingSystem',
>>    'OperationCanceledException', 'OutOfMemoryException',
>>    'OverflowException', 'ParamArrayAttribute', 'PlatformID',
>>    'PlatformNotSupportedException', 'Predicate', 'Random',
>>    'RankException', 'Reflection', 'ResolveEventArgs',
>>    'ResolveEventHandler', 'Resources', 'Runtime',
>>    'RuntimeArgumentHandle', 'RuntimeFieldHandle',
>>    'RuntimeMethodHandle', 'RuntimeTypeHandle', 'SByte',
>>    'STAThreadAttribute', 'Security', 'SerializableAttribute',
>>    'Single', 'StackOverflowException', 'String', 'StringComparer',
>>    'StringComparison', 'StringSplitOptions', 'SystemException',
>>    'Text', 'ThreadStaticAttribute', 'Threading', 'TimeSpan',
>>    'TimeZone', 'TimeoutException', 'Timers', 'Type', 'TypeCode',
>>    'TypeInitializationException', 'TypeLoadException',
>>    'TypeUnloadedException', 'TypedReference', 'UInt16', 'UInt32',
>>    'UInt64', 'UIntPtr', 'UnauthorizedAccessException',
>>    'UnhandledExceptionEventArgs', 'UnhandledExceptionEventHandler',
>>    'Uri', 'UriBuilder', 'UriComponents', 'UriFormat',
>>    'UriFormatException', 'UriHostNameType', 'UriIdnScope', 'UriKind',
>>    'UriParser', 'UriPartial', 'UriTypeConverter', 'ValueType',
>>    'Version', 'Void', 'WeakReference', 'Web', '_AppDomain',
>>    '__builtins__', '__dict__', '__name__']
>>
>>    _______________________________________________
>>    Users mailing list
>>    Users at lists.ironpython.com <mailto:Users at lists.ironpython.com>
>>    http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>>
>
>
> --
> http://www.ironpythoninaction.com/
> http://www.voidspace.org.uk/
> http://www.trypython.org/
> http://www.ironpython.info/
> http://www.theotherdelia.co.uk/
> http://www.resolverhacks.net/
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080922/6ef927dd/attachment.html>


More information about the Ironpython-users mailing list