I'm (attempting) implementing a customer membership provider for an application (code from the custom SQL membership provider video) and upon creating a new user in with a standard create user wizard control in debug mode, I get this error:
String reference not set to an instance of a String. Parameter name: s
I semi-understand why but can't quite get it. Here's the method that throws the error:
''' <summary>
''' Encode password.
''' </summary>
''' <param name="password">Password.</param>
''' <returns>Encoded password.</returns> Private Function EncodePassword(ByVal password
As String) As String
Dim encodedPassword As String = password
Select Case PasswordFormat Case MembershipPasswordFormat.Clear
Case MembershipPasswordFormat.Encrypted
encodedPassword = _
Convert.ToBase64String(EncryptPassword(Encoding.Unicode.GetBytes(password))) Case MembershipPasswordFormat.Hashed Dim hash As HMACSHA1 =
New HMACSHA1()
hash.Key = HexToByte(_machineKey.ValidationKey) encodedPassword = _
System.Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(encodedPassword))) Case Else
Throw New ProviderException("Unsupported password format.") End Select
Return encodedPassword End Function
I have the right info in my web.config, machine key, all of the necessary stuff to make it work. The password field in the corresponding table is nvarchar255. Any help is hugely appreciated! Thanks. :)
The error indicates that the encodedPassword is null (Nothing). Since you're initially setting it to the password parameter, that means you're trying to encode a null password.
Just as RichardD mentioned, it's probably caused by the null string. If you want to see how exactly it happened, I suggest you to set break points and debug the application
line by line. When debugging, you could check the value.
P.S. press F5 can jump to the next break point and F10 to the next line.
Thanks.
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
rcg26
Participant
958 Points
167 Posts
String reference not set to an instance of a String. Parameter name: s error
Oct 15, 2008 02:18 PM|LINK
I'm (attempting) implementing a customer membership provider for an application (code from the custom SQL membership provider video) and upon creating a new user in with a standard create user wizard control in debug mode, I get this error:
String reference not set to an instance of a String. Parameter name: s
I semi-understand why but can't quite get it. Here's the method that throws the error:
''' <summary>
''' Encode password.
''' </summary>
''' <param name="password">Password.</param>
''' <returns>Encoded password.</returns>
Private Function EncodePassword(ByVal password As String) As String
Dim encodedPassword As String = password
Select Case PasswordFormat
Case MembershipPasswordFormat.Clear
Case MembershipPasswordFormat.Encrypted
encodedPassword = _
Convert.ToBase64String(EncryptPassword(Encoding.Unicode.GetBytes(password)))
Case MembershipPasswordFormat.Hashed
Dim hash As HMACSHA1 = New HMACSHA1()
hash.Key = HexToByte(_machineKey.ValidationKey)
encodedPassword = _
System.Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(encodedPassword)))
Case Else
Throw New ProviderException("Unsupported password format.")
End Select
Return encodedPassword
End Function
I have the right info in my web.config, machine key, all of the necessary stuff to make it work. The password field in the corresponding table is nvarchar255. Any help is hugely appreciated! Thanks. :)
Always looking, always learning.
RichardD
Contributor
3950 Points
549 Posts
Re: String reference not set to an instance of a String. Parameter name: s error
Oct 15, 2008 06:55 PM|LINK
rcg26
Participant
958 Points
167 Posts
Re: String reference not set to an instance of a String. Parameter name: s error
Oct 16, 2008 12:44 PM|LINK
Always looking, always learning.
Wencui Qian ...
All-Star
56784 Points
5796 Posts
Microsoft
Re: String reference not set to an instance of a String. Parameter name: s error
Oct 20, 2008 07:11 AM|LINK
Hi rcg26,
Just as RichardD mentioned, it's probably caused by the null string. If you want to see how exactly it happened, I suggest you to set break points and debug the application line by line. When debugging, you could check the value.
P.S. press F5 can jump to the next break point and F10 to the next line.
Thanks.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
arunbnair
Member
2 Points
1 Post
Re: String reference not set to an instance of a String. Parameter name: s error
Dec 17, 2008 08:57 AM|LINK
Hi;
Im getting same error in my reports. Iwants to solve it very urgently....
I think by this time u may got the answer and solved ur problem. Please help me out.
Im using vb.net and crystal reports.
please its very urgent;;;;
please mail the solution to arunbnair.001@gmail.com