OutOfMemoryException with Directory.GetFiles()

Hi all!

We are using the FEZ Domino for a prototype project involving Mp3 files, and because of that we need to get all filenames on the connected mass storage device. The problem is that NETMF lacks a method for iterating through filnames one at a time. So if we load more that 40 Mp3s on the mass storage device, the Directory.GetFiles() will throw an OutOfMemoryException. This has been brought to the developers attention here: [url]http://netmf.codeplex.com/workitem/671[/url] and here: [url]http://www.netmf.com/Discussion/Forums/SingleForum/SingleThread.aspx?mode=singleThread&thread=31245011-4f6a-4206-b2d1-7def1c2e601a[/url] Since this is an ongoing project, and version 4.2 of NETMF is due in august/september, it would be great if you guys could help us compile the modified code… Is this possible?

Your link has extra dot at the end which makes it invalid.
It is possible, but it is totally up to GHI folks.

I would write an email directly to them explaining the project a little bit more.

yield return (e.g. IEnumerable) is definately the way this should have been implemented in .NET. I ~think they may have made that change in .Net 4.0 (or will vNext). I remember reading somewhere. I think I asked for that change year ago. In terms of NETMF, it is even a more important thing to have. However not sure how they implement that because AFAICT, Yield is still not supported in NETMF. Anyone have yield working with some compiler attribute?

Or another way, judging by what I see in the reflector, is to wrap the NativeFindFile into public IEnumerator. Should be really easy.

Another possible temporary workaround until fixed is by convention.
Use more directories and allow/demand only so many files per directory.

If your app has control over what goes on the drive, you could also use some kind of DB (e.g. your own FAT using xml, csv, txt) and enumerate that.

We are looking into it.

Providing a non-standard Microsoft NETMF library will be a hassle to many people because of different version numbers and needed firmware…etc

I haven’t tried this but you can use reflection to get the internal methods that internally enumerates the files so you don’t have to get them at once.

OK, so we will try reflection first then. I just can’t understand why it would be hard to compile everything with a modified Directory class, just as a temporary solution until NETMF 4.2 comes out…

I guess the difference is free vs “paid for” custom feature just for one customer.

http://www.tinyclr.com/forum/1/1503/

But this is a NETMF issue, not GHI. All we’re asking for is some help to compile the code with the right tools, but I guess we just need to try to fix it ourselves and wait for the new NETMF SDK for a proper fix…

GHI always work very promptly on solving problems and adding features. Something things look different than they are actually are. As always, we will make sure to do whatever is needed to give everyone in the community and our customers the best possible option that fits everyone.

But, if you need something specific to your needs then our sales guys will happily talk to you and find and option for you.

Of course I am not saying this will not be done but we have to think about it and make sure this option is good for everyone…we have thousands of customer :slight_smile:

Here is something for you to start with :wink: :

http://www.fezzer.com/project/259/ienumerable-directoryexgetfiles-helper/

Tested it with ~300 8.3 dummy files.

Directory.GetFiles threw an exception
DirectoryEx.GetFiles worked fine

Thank you Architect! This is a better solution until 4.2 comes out.

You are welcome. ;D