我正在尝试使用filestream从我的资源中获取* .exe文件。我的代码是这样的:filerdr = New FileStream(My.Resources.ResourceManager.GetStream("filename.exe"), FileMode.Open)
但我得到这个错误
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'.
我也尝试过:filerdr = New FileStream(My.Resources.filename.exe, FileMode.Open
但仍然没有运气,请不要给我工作,请告诉我如何以我想要的方式做到这一点。
我想添加FileMode.Open
,然后使用
If filerdr.ReadByte = filerdr2.ReadByte AndAlso
filerdr.Length = filerdr2.Length Then
''''''''''''
End If
答案 0 :(得分:0)
我找到了解决方案。首先,我必须将我的变量“filerdr”从FileStream更改为UnmanagedMemoryStream,然后我必须编辑Resources.resx来自此
<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>
到此
<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>
简而言之。 System.Byte []到System.IO.MemoryStream。 这解决了问题,我的代码开始工作。