-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static command don't resolve viewmodel correctly #809
Comments
Calling instance methods on viewmodels from static commands is not supported. You should use Static Command Services. Since the static commands don't send the viewmodel to the server, property values of the viewmodel are unknown and the object will be in a strange and probably inconsistent state. The same applies to the dependencies passed in the constructor - for historical reasons, they are set to null because it was implemented before DotVVM was using |
Oh, I see. I think the exception is best solution of this |
I don't think so, the arguments of a static command are simply deserialized using Newtonsoft.Json and, apparently it passes nulls to constructors (if a property of the same name does not exist). This is how arguments are processed: https://github.com/riganti/dotvvm/blob/master/src/DotVVM.Framework/Hosting/DotvvmPresenter.cs#L332 |
@tomasherceg What can we do about this? Shall we also use the dotvvm serializer static command arguments? (this is certainly a breaking change) Or call it a "feature"? |
I think that the only reason for using an instance method as a target of static commands is the dependency injection, so we can change the behavior and make a breaking change here - I don't think we'll break someone as this entire situation is quite rare, and if the viewmodel instance can be created for the original page load, it should resolve for a static command as well. |
Now, I don't know if you mean banning everything except In any case, it does not really solve the problem, since we are still deserializing the other parameters in this way. |
We've discussed this and it is a breaking change so it needs to go to v3.
|
Dependencies are
null
when static command is executed so I get NullReferenceException in constructor.DotVVM version: 2.4.0.1
The text was updated successfully, but these errors were encountered: