[IronPython] problem accessing/import System.IO.Packaging using IronPython

Dino Viehland dinov at exchange.microsoft.com
Thu Nov 29 01:53:40 CET 2007


System.IO.Packaging is in WindowsBase.dll so you need to add a reference to that DLL:

import clr
clr.AddReference('WindowsBase')
from System.IO import Packaging
print dir(Packaging)
['CertificateEmbeddingOption', 'CompressionOption', 'EncryptedPackageEnvelope', 'EncryptionOption', 'InvalidSignatureEventHandler', 'PackUriHelper', 'Package',
'PackageDigitalSignature', 'PackageDigitalSignatureManager', 'PackagePart', 'PackagePartCollection', 'PackageProperties', 'PackageRelationship', 'PackageRelatio
nshipCollection', 'PackageRelationshipSelector', 'PackageRelationshipSelectorType', 'RightsManagementInformation', 'SignatureVerificationEventArgs', 'StorageInf
o', 'StreamInfo', 'TargetMode', 'VerifyResult', 'ZipPackage', 'ZipPackagePart']

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Raymond Yee
Sent: Wednesday, November 28, 2007 4:46 PM
To: users at lists.ironpython.com
Subject: [IronPython] problem accessing/import System.IO.Packaging using IronPython

I've not been able to figure out how to import Package from
System.IO.Packaging.  Below is some code to illustrate my problem.
(I've run this code in  IronPython 2.0A6 and 1.1.  I  have .NET 3.0
installed.)   Basically,

from System.IO import Packaging

gives me the error

ImportError: Cannot import name Packaging

whereas something like

from System.IO import FileStream, FileMode, FileAccess

works fine.

Part of the issue is that System.IO.Packaging is part of .NET 3.0 but
not .NET 2.0 -- but I can certainly access other libraries (assemblies?
I'm new to .NET) -- such as System.Speech -- as show below.    Is the
problem that there is no System.Speech at all in .NET 2.0 but there is
already a System.IO in .NET 2.0  -- so IronPython can't pick up the .NET
3.0 parts of System.IO?  I know that System.IO.Packaging is on my system
-- I have some C# code that uses it.

Thanks in advance for any help!

-Raymond Yee

-----------------------------------

Here's the code:

# documenting my problem with getting System.IO.Packaging to work in ipy

import clr

# I can't figure out how to load System.IO.Packaging -- which is part of
.NET 3.0
#
http://msdn2.microsoft.com/en-us/library/system.io.packaging.package.aspx
is part of .NET 3.0

try:
  from System.IO import Packaging
  print "success:  from System.IO import Packaging"
except:
  print "error: from System.IO import Packaging"

#
http://www.ironpython.info/index.php/SHA1Managed_from_System.Security.Cryptography
# shows that we can access System.IO.{FileStream, FileMode, FileAccess}

from System.IO import FileStream, FileMode, FileAccess
print "success:  from System.IO import FileStream, FileMode, FileAccess"

# I can get at other assemblies that are .NET 3.0
# e.g.,
http://msdn2.microsoft.com/en-us/library/system.speech.synthesis.aspx

try:
  clr.AddReference('System.Speech')
  from System.Speech.Synthesis import SpeechSynthesizer
  print "success: adding System.Speech"
except:
  print "error:  adding System.Speech"


# print out why System.IO doesn't contain Packaging

import System
print "dir(System.IO): \n" , dir(System.IO), "\n"

# print out the references that are available

print "clr.References:"
for r in clr.References:
  print r

# Is the problem that there is no System.Speech at all in .NET 2.0 but
there is already a System.IO in .NET 2.0 -- so
# IronPython can't pick up the .NET 3.0 parts of System.IO?

-----------------

Here's the output I get:

error: from System.IO import Packaging
success:  from System.IO import FileStream, FileMode, FileAccess
success: adding System.Speech
dir(System.IO):
['BinaryReader', 'BinaryWriter', 'BufferedStream', 'Compression',
'Directory', 'DirectoryInfo', 'DirectoryNotFoundException', 'DriveInfo',
'DriveNotFoundException', 'DriveType', 'EndOfStreamException',
'ErrorEventArgs', 'ErrorEventHandler', 'File', 'FileAccess',
'FileAttributes', 'FileInfo', 'FileLoadException', 'FileMode',
'FileNotFoundException', 'FileOptions', 'FileShare', 'FileStream',
'FileSystemEventArgs', 'FileSystemEventHandler', 'FileSystemInfo',
'FileSystemWatcher', 'IODescriptionAttribute', 'IOException',
'InternalBufferOverflowException', 'InvalidDataException',
'IsolatedStorage', 'MemoryStream', 'NotifyFilters', 'Path',
'PathTooLongException', 'Ports', 'RenamedEventArgs',
'RenamedEventHandler', 'SearchOption', 'SeekOrigin', 'Stream',
'StreamReader', 'StreamWriter', 'StringReader', 'StringWriter',
'TextReader', 'TextWriter', 'UnmanagedMemoryStream',
'WaitForChangedResult', 'WatcherChangeTypes']

clr.References:
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Speech, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35

_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list