The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Archive for the ‘.NET’ Category

.NET/C# – Issue with FileStream on network with transfers larger than 64 megabyte

Posted by jpluimers on 2009/04/27

Quite a while ago (2006!), I bumped into an issue when copying large chuncks of data to a network.

I posted it to Google, mentioned that breaking up the data in smaller blocks worked, but never had the time to post the solution.

So here it is :-)

First the problem:

The old code consistently fails when:

  • the FileStream is on a network
  • and the MemoryStream is 64 megabytes or larger

The old code succeeds when:

  • the MemoryStream is smaller than 64 megabytes
  • or the FileStream is not on a network

An example of the exception message you get upon failure:

System.IO.IOException: Insufficient system resources exist to complete the requested service.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.FileStream.Write(Byte[] array, Int32 offset, Int32 count)
   at System.IO.BufferedStream.Write(Byte[] array, Int32 offset, Int32 count)
...

Then the old code:

        public static void WriteMemoryStreamToFile(string filename, MemoryStream memory)
        {
            using (Stream
                file = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite),
                fileBuffer = new BufferedStream(file)
            )
            {
                byte[] memoryBuffer = memory.GetBuffer();
                int memoryLength = (int)memory.Length;
                fileBuffer.Write(memoryBuffer, 0, memoryLength); //##jpl: drawback: works only up to 2 gigabyte!
                fileBuffer.Close();
                file.Close();
            }
        }

Note that the old code already has a limitation of 2 gigabyte, back then this was not an issue (in 2006 there were not that many people having more than 2 gigabytes of memory, now that is a different story).

Read the rest of this entry »

Posted in .NET, C#, Development | 6 Comments »

.NET/C# – obtaining information through WMI

Posted by jpluimers on 2009/04/25

WMI (Windows Management Instrumentation) is a way of obtaining information from your PC that otherwise might be hard to find.
WMI is based on Common Information Model (CIM), so you’ll see an example of that too.

There is one drawback: for a lot of the WMI, you need to have enough privileges (like: being an admin, which none of you should be, right?).
So beware!

You can use WMI from C#, but you have to generate the C# classes for the WMI classes first.

I’ll show some examples for WMI Win32 classes, as I needed some of those classes recently myself.

Before I forget:
in order to browse through the WMI Win32 object instances, you can download this nifty WMI Administrative Tools toolset from the Microsoft MSDN site. Note that these are from 2002, and they only reliably work from within Internet Explorer.
Read the rest of this entry »

Posted in .NET, C#, Development, Software Development, Visual Studio and tools | Leave a Comment »

.NET/C# – converting UTF8 to ASCII (yes, you *can* loose information with this) using System.Text.Encoding

Posted by jpluimers on 2009/04/23

Quite a while ago, we needed to exchange some text files with .NET and a DOS application (yes, they still exist!).

Since the .NET app already exchanged text files with other applications using UTF8, we had to reencode those into plain ASCII.
(yes, I am aware there are dozens of codepages we could encode to, we decided to stick with 7-bit ASCII, and warned the client about possible information loss).

A couple of months later, we neede to exchange information with an app doing Windows-1252, and then even later on to a web-app needing ISO 8859-1 (both are Western European encodings).
So I decided to refactor the UTF8 to ASCII conversion app into something more maintainable.

But first let me show you how you can dump all of the .NET supported encodings:
Read the rest of this entry »

Posted in .NET, ASCII, C#, Development, Encoding, Software Development, Unicode, UTF-8, UTF8 | 3 Comments »

Speaking @ Microsoft DevDays ’09, May 28-29, The Hague

Posted by jpluimers on 2009/04/21

DevDays '09 logo

I’ll be speaking during the Microsoft DevDays ‘09 that are held from May 28-29 (27 if you count the preconference) in The Hague (at the World Forum, previously known as Nederlands Congres Centrum).

My session is in the “Geek Night” track that is held on the evening of May 28.

It is gonna be a cool session, showing collaboration on many levels:

  • as in integration between .NET and hardware (WebCams and Servos through USB)
  • as cooperation between you and Open Source projects
  • as building your own shooter device from plexiglass and other easy to obtain hardware
  • as interaction between users and the automated shooter device

DevDays '09 logo Geek Night

The session works towards the creation of an automated shooter device.
It consists of a USB webcam of which you monitor the video stream, a USB Servo Controller that steers Servos and relais, and a laserpointer.
The laserpointer can track moving objects (like you, the audience!) as seen through the  webcam.

During the session you see the pro’s and con’s of using Open Source, what can go wrong when using multiple-web-cams, and much much more.

Prepare for a fun night!

Posted in .NET, C#, Conferences, DevDays09, Development, Event, Software Development | Tagged: | Leave a Comment »