Im新到VB.Net。我試圖調試我的項目,但我得到一個警告:變量'csCryptoStream'在它被賦值之前使用。在運行時會導致空引用異常警告變量'csCryptoStream'在它被賦值之前被使用。空引用異常可能會導致在運行時
我該如何解決它?
Private Sub EncryptOrDecryptFile(strInputFile As String, strOutputFile As String, bytKey As Byte(), bytIV As Byte(), Direction As crypt.CryptoAction)
' The following expression was wrapped in a checked-statement
Try
Me.fsInput = New FileStream(strInputFile, FileMode.Open, FileAccess.Read)
Me.fsOutput = New FileStream(strOutputFile, FileMode.OpenOrCreate, FileAccess.Write)
Me.fsOutput.SetLength(0L)
Dim bytBuffer As Byte() = New Byte(4096) {}
Dim lngBytesProcessed As Long = 0L
Dim lngFileLength As Long = Me.fsInput.Length
Dim cspRijndael As RijndaelManaged = New RijndaelManaged()
Me.pbStatus.Value = 0
Me.pbStatus.Maximum = 100
Dim csCryptoStream As CryptoStream
Select Case Direction
Case crypt.CryptoAction.ActionEncrypt
csCryptoStream = New CryptoStream(Me.fsOutput, cspRijndael.CreateEncryptor(bytKey, bytIV), CryptoStreamMode.Write)
Case crypt.CryptoAction.ActionDecrypt
csCryptoStream = New CryptoStream(Me.fsOutput, cspRijndael.CreateDecryptor(bytKey, bytIV), CryptoStreamMode.Write)
End Select
While lngBytesProcessed < lngFileLength
Dim intBytesInCurrentBlock As Integer = Me.fsInput.Read(bytBuffer, 0, 4096)
Warning ---> csCryptoStream.Write(bytBuffer, 0, intBytesInCurrentBlock)
' The following expression was wrapped in a unchecked-expression
lngBytesProcessed += CLng(intBytesInCurrentBlock)
' The following expression was wrapped in a unchecked-expression
Me.pbStatus.Value = CInt(Math.Round(CDec(lngBytesProcessed)/CDec(lngFileLength) * 100.0))
End While
給它分配一個值,你使用之前,它是可能先嚐試了明顯的事情... –