Why, oh why, is System.IO.Packaging.StorageRoot internal?

I need to access data in compound files.
They contain data from [more or less legacy] applications I need to extract (say, for an IFilter).
 
My application is going to be .NET 2.0 so I would look into COM interop-ing with IStorage and IStream and their friends, which seems to be quite a nightmare to get right in the time I’m allowed to spend.

 

Luckily, Microsoft seems to already have completed an implementation in WinFX that covers this base. As of the January CTP it’s in  C:WINDOWSMicrosoft.NETWindowsv6.0.5070WindowsBase.dll, in the System.IO.Packaging namespace.
 
The classes in this namespace are mainly targeted at supporting the package formats for the new and upcoming Office XML and Xml Paper specifications, which are probably cool and all.
 
What’s not cool is that StorageRoot is internal, leaving me now other choices than:
 
– Be a good guy and implement it again. This would also allow my app to run on W2K.
 
– Be a bad guy and use The Force:

Type storageRootType = typeof(StorageInfo).Assembly.GetType("System.IO.Packaging.StorageRoot", true, false);

StorageInfo info = storageRootType.InvokeMember(

"Open",

BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod,

null,

null,

new object[] { fileName, FileMode.Open, fileAccess }) as StorageInfo;

if (null == info)

throw new InvalidOperationException("Clear and Present Failure");

 

Being a bad guy is unfortunately not an option for anybody trying to make and sell some honest software.

 

Mad world.

 

[The ugly font size and missing indentation is courtesy of MSN Spaces. Anyway, it’s free and I don’t have time to bother.]

Advertisements
This entry was posted in Coding Horror. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s