WebSecurity.ResetPassword unable to work - asp.net-mvc

I have MVC4 application and i am using default membership. I have changed UserId from int to Bigint. When i call WebSecurity.ResetPassword with token and new password it is showing error :
Cannot implicitly convert type 'long' to 'int?'. An explicit conversion exists (are you missing a cast?)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot implicitly convert type 'long' to 'int?'. An explicit conversion exists (are you missing a cast?)
Source Error:
Dim newpassw As String = mdl.Password
Dim response As Boolean = WebSecurity.ResetPassword(mdl.PasswordResetToken, newpassw)
When i changed UserId from Bigint to int its working fine. But i need Bigint instead of int for UserId in database. How to do Websecurity.ResetPassword for Bigint?

Related

Null safety type promotion when assigning non-null value literal

In nullsafety.dartpad.dev if I write the following code:
void main() {
String? name = 'Bob';
print(name.length);
}
I get the following compile-time error:
An expression whose value can be 'null' must be null-checked before it can be dereferenced
And the following runtime error:
Property 'length' cannot be accessed on 'String?' because it is potentially null.
The Type promotion on null checks documentation says:
The language is also smarter about what kinds of expressions cause promotion. An explicit == null or != null of course works. But explicit casts using as, or assignments, or the postfix ! operator we’ll get to soon also cause promotion. The general goal is that if the code is dynamically correct and it’s reasonable to figure that out statically, the analysis should be clever enough to do so.
Question
There is no possible way name could be null in the code above. The documentation also says assignments should cause type promotion. Am I misunderstanding type promotion or is this a bug in DartPad?
Clarification
Since a couple of the answers are providing workaround solutions to the error messages, I should clarify that I'm not trying to solve the coding problem above. Rather, I'm saying that I think the code should work as it it. But it doesn't. Why not?
This answer is in response to the bounty that was added to the original question. The bounty reads:
Please explain how String? is different from String and how type
promotion works in Dart.
String? vs String
The type String? can contain a string or null. Here are some examples:
String? string1 = 'Hello world';
String? string2 = 'I ❤️ Dart';
String? string3 = '';
String? string4 = null;
The type String, on the other hand, can only contains strings (once null safety is a part of Dart, that is). It can't contain null. Here are some examples:
String string1 = 'Hello world';
String string2 = 'I ❤️ Dart';
String string3 = '';
If you try to do the following:
String string4 = null;
You'll get the compile-time error:
A value of type 'Null' can't be assigned to a variable of type 'String'.
The String type can't be null any more than it could be an int like 3 or a bool like true. This is what null safety is all about. If you have a variable whose type is String, you are guaranteed that the variable will never be null.
How type promotion works
If the compiler can logically determine that a nullable type (like String?) will never be null, then it converts (or promotes) the type to its non-nullable counterpart (like String).
Here is an example where this is true:
void printNameLength(String? name) {
if (name == null) {
return;
}
print(name.length);
}
Although the parameter name is nullable, if it actually is null then the function returns early. By the time you get to name.length, the compiler knows for certain that name cannot be null. So the compiler promotes name from String? to String. The expression name.length will never cause a crash.
A similar example is here:
String? name;
name = 'Bob';
print(name.length);
Although name is nullable here, too, the string literal 'Bob' is obviously non-null. This also causes name to be promoted to a non-nullable String.
The original question was regarding the following:
String? name = 'Bob';
print(name.length);
It seems that this should also promote name to a non-nullable String, but it didn't. As #lrn (a Google engineer) pointed out in the comments, though, this is a bug and when null safety comes out, this will also work like the previous example. That is, name will be promoted to a non-nullable String.
Further reading
Sound null safety
Type promotion on null checks
I understand what you are saying. Try this out.
In order for type promotion to work you must first confirm that the value is not null as the documentation says.
As you can see in the picture dart is able to do the type promotion or understand that name is not going to be null because it checks that on the if statement beforehand.
But if using it outside the if statement without checking if it is not null beforehand, dart knows it can be assigned null anytime again. That’s why it encourages always checking if it is null. Because any instatiated variable ( a variable with a value assigned) can be assigned null in the future.

Delphi FDQuery Fieldbyname conversion error

I have defined a MySQL database with a table that includes a field of type varchar(128), I call it fieldinquestion. I use a query to access this field, which usually works nicely. However, when I assign a string to the field, I get an error that I don't understand.
try
Self.FDQuery1.FieldByName('fieldinquestion').AsString:='Hello There'; //or something similar.
except
---> error: 'Could not convert variant of type (String) into type (Double)'
aDataType:=Self.FDQuery1.FieldByName(GCssValidationDisplay).DataType; --datatype is ftString
end;
In the try..except clause, this causes an error, but a verification for the datatype shows it is a string!
Any ideas?

how to cast Edm.Guid to Edm.String in odata

how to cast guid into string in odata, i have tried the $filter=(startswith(cast(CustomerID, 'Edm.String'),'1')) but it throws exception Unknown function 'cast'.
To perform a cast, the type shouldn't be in quotes. So it should be:
$filter=startswith(cast(CustomerID, Edm.String),'1')
(I also removed the extra brackets)

Error while parsing xml attribute

I am getting error on
I.ID=((Element) nl.item(i)).getAttributes().getNamedItem("ID").getNodeValue();
the error is that
getNamedItem required INT and found String
When i give an Int value then the error said that it required String and found Int.
Issue Resolved.
getNamedItem is returning String value while ID is an integer value. so i put string to integer parser which resolved my issue.

Changing grails "no conversion strategy" error that is not in message.properties

Is there a way to change Grails conversion mismatch error to custom message?
I am getting:
Failed to convert property value of type java.lang.String to required
type java.util.Map for property items;nested exception is
java.lang.IllegalStateException: Cannot convert value of type
[java.lang.String] to required type [java.util.Map] for property
items: no matching editors or conversion strategy found
This error type is not in messages.properties. I am getting this if a user tries to inject request parameter which is not a map into my Command Object, they shouldn't be doing this, but that besides the point:
class CartCommand implements Serializable {
Map<Integer, Integer> items =
MapUtils.lazyMap([:], FactoryUtils.constantFactory(''))
}
Thanks
Use the following key in your message.properties:
cartCommand.items.typeMismatch.map

Resources