Question

I am trying to get value of a Filehandle created using System.IO.FileStream class.

using System.IO;

Filestream fs = New FileStream("c:/1/txt",FileMOde.OpenorCreate,FileAccess.ReadWrite);

Intptr file_ptr = fs.Handle;

When I run this in XP-x86 os with debug configuration, it works fine. But when I run it in Ce-Arm OS with release configuration, it is throwing an error.

System.IO.FileStream does not contain a definition for Handle and no extension method Handle accepting a first argument of type System.IO.FileStream could be found (are you missing a using directive or an assembly reference?)

Should I make any changes when I am trying to build in release configurations. I know the release configuration will turn on all the compiler optimizations. But what does it have to do with inbuilt classes and properties? I am really confused. Please help.

Thanks in advance.

Was it helpful?

Solution

There are a few things going on here.

  1. Directories in Windows (desktop and CE) are delimited by the backslash '\' character, not the forward slash. Desktop Windows might not mind it, but Windows CE isn't going to like it.
  2. Windows CE has no notion of drive letters (or current directory for that matter) so your path is invalid for that reason as well.
  3. The CF FileStream doesn't expose the file handle, and I'd say for likely good reasons. That's the specific reason for the error you see. Messing with the handle outside of the managed stream can cause the managed side of things to get into an indeterminate state and lead to bad things. Why, exactly, do you need that handle? If we know that, maybe we can propose a workaround, but generally using that native handle is going to lead to bad things happening.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top