0

I m trying to use filestream to get a *.exe file from my resources. my code is this: filerdr = New FileStream(My.Resources.ResourceManager.GetStream("filename.exe"), FileMode.Open) but i get this error with it

Overload resolution failed because no accessible 'New' can be called with these arguments:
'Public Sub New(handle As Microsoft.Win32.SafeHandles.SafeFileHandle, access As System.IO.FileAccess)': Value of type 'System.IO.UnmanagedMemoryStream' cannot be converted to 'Microsoft.Win32.SafeHandles.SafeFileHandle'.
'Public Sub New(handle As System.IntPtr, access As System.IO.FileAccess)': Value of type 'System.IO.UnmanagedMemoryStream' cannot be converted to 'System.IntPtr'.
'Public Sub New(path As String, mode As System.IO.FileMode)': Value of type 'System.IO.UnmanagedMemoryStream' cannot be converted to 'String'.

I have also tried: filerdr = New FileStream(My.Resources.filename.exe, FileMode.Open

but still no luck, please don't give me work arounds and please tell me how to do this the way i want to do it.

I want to add FileMode.Open and then compare it to another file, by using

If filerdr.ReadByte = filerdr2.ReadByte AndAlso 
     filerdr.Length = filerdr2.Length  Then 
'''''''''''' 
End If 
6
  • Doesn't My.Resources.ResourceManager.GetStream("filename.exe") already return you a stream? You don't need a FileStream. Oct 13 '13 at 10:08
  • I want to add FileMode.Open . and then compare it to another file, by using If filerdr.ReadByte = filerdr2.ReadByte AndAlso filerdr.Length = filerdr2.Length Then '''''''''''' End If Oct 13 '13 at 10:21
  • What part of that can you not do without using a FileStream? Oct 13 '13 at 13:05
  • Read the comment closely...GetStream returns a stream - are you saying you cant read from it? Oct 13 '13 at 13:05
  • I get this error: Resource 'file' was not a Stream - call GetObject instead. and when i use GetObject, I get this error: Unable to cast object of type 'System.Byte[]' to type 'System.IO.UnmanagedMemoryStream'. Both errors are: (InvalidOperationException was unhandled) Oct 13 '13 at 13:50
0

I found the solution. first i had to change my variable "filerdr" from FileStream to UnmanagedMemoryStream and then i had to edit the Resources.resx From this

<data name="MyFile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\MyFile.exe;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>

To this

<data name="MyFile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\MyFile.exe;System.IO.MemoryStream, mscorlib, Version=2.0.0.0,            Culture=neutral, PublicKeyToken=b77a5c561934e089</value>

In short words. System.Byte[] to System.IO.MemoryStream. This solved the problem and my code started working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.