LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.NET FileStream

Solved!
Go to solution

Hi,

 

I would like to use .NET System.IO.FileStream class to load an image, but I cannot find it under System.IO (Select .NET Class). According to documentation http://msdn.microsoft.com/en-us/library/system.io.filestream(v=vs.100).aspx it should be there.

Interestingly also System.IO.Stream cannot be located via Select .NET Class, but I can obtain it if I create constant from Image.FromStream function (see attached vi).

What am I doing wrong here?

0 Kudos
Message 1 of 3
(4,789 Views)
Solution
Accepted by andrej

@andrej wrote:

Hi,

 

I would like to use .NET System.IO.FileStream class to load an image, but I cannot find it under System.IO (Select .NET Class). According to documentation http://msdn.microsoft.com/en-us/library/system.io.filestream(v=vs.100).aspx it should be there.

Interestingly also System.IO.Stream cannot be located via Select .NET Class, but I can obtain it if I create constant from Image.FromStream function (see attached vi).

What am I doing wrong here?


Hi there andrej,

 

FileStream is located under the System.IO namepsace but that is not the name of the assembly that it is located in. If you go to the link you posted, you can see that it is located in the assembly mscorlib.dll. This is one of the primary assemblies for the .Net framework and is typically implictly included in any build by the Microsoft C# compiler. It is confusing for adopters of .Net that a namespace is not the same as the assembly filename but the two are different things. A single assembly can contains several namespaces.

 

If you browse to the mscorlib.dll assembly in the GAC using LabVIEW and drill down into it's contents you will see Stream in the list, as well as the other dervied classes such as FileStream.

 

Note that, of course, you will not be able to create an actual Stream object (Constructor) since, according to MSDN documentation, it is an abstract class. LabVIEW prompts you in the dialog that the class has no public constructors. LabVIEW, however, repsects polymorphism and will allow you to create a class that dervies from Stream (eg. FileStream) and allow you to pass it to members that accept the abstract base Stream type (such as the Image.FromStream() method you have in your example).

 

Update: Another tip that might help - Image.FromStream() method is actual a static method call on the Image class. Since it is static (ie. there is no object to operate on) you do not need the .Net constant reference to the Invoke node reference terminal. Here an example (admittedly a little contrived).

 

FileStream Use LV13.png

Message 2 of 3
(4,763 Views)

Thank you very much! This was helpful!

0 Kudos
Message 3 of 3
(4,753 Views)