Open Glabenwitt opened 4 years ago
I'm also trialling LiveSharp, and am running into what looks like the same issue:
received C# update
Received update for method LoginPage.Build
Updating control node iSurvey.LoginPage
InitializeComponent iSurvey.LoginPage
warning: Constructor initialization failed.
After the update, the view is empty.
LoginPage
is a ContentPage
subclassBuild()
Build()
only contains Content = new Label { Text = @"some text" };
Edit: It seems at some point in my testing I had a stale build. It indeed looks like the problem was constructor arguments. I had a single boolean argument with a default. When I removed the argument, live reload started working.
So the question becomes, how do we support Views with constructor arguments?
I came to the same result, after deleted my constructor's parameters this error go away but all my code doesn't work after a reload.
It would be great to have an option to recreate completelly Pages and ViewModels instead of keeping their state (keeping constructor's parameters).
Thanks for the issue!
Here is an update you can try. This does the following:
1) Stores the latest ContentPage
that had any method calls
2) If the call is to the constructor, store arguments
3) When update received:
3.1) If the latest ContentPage
is among the updated types
3.1.1) If it is, tries calling Build
method
3.1.2) If there is no Build
, tries to recreate the page with the stored arguments
3.2) If the latest ContentPage
is NOT among the updated types, try the original initialization inherited from LiveXAML (doesn't support ctor arguments)
Hi, thank's for the package but It didn't work. I have this error when I try to update my code :
[0:] Received update for method CSBaseQuestionView.Build
[0:] warning: Updated element not found: Formulaire4_0.XForms.Controls.Cells.CSBaseQuestionView
[0:] warning: Reloading current page
[0:] Updating control node Xamarin.Forms.NavigationPage
[0:] InitializeComponent Formulaire4_0.XForms.Pages.QuestionnaireSaisiDetailPage
[0:] error: Failed to call ctor:
System.MissingMethodException: Constructor on type 'Formulaire4_0.XForms.Pages.QuestionnaireSaisiDetailPage' not found.
at System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) [0x0022b] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/rttype.cs:5535
at System.Activator.CreateInstance (System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x000b5] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/activator.cs:107
at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/activator.cs:112
at LiveSharp.Support.XamarinForms.Updating.ElementInitializer.TryCallingConstructor (Xamarin.Forms.Element originalElement, System.Object[] args) [0x00009] in <9ab7c85ee3a14757bd8037d6db63eb31>:0
[0:] warning: Constructor initialization failed.
The iniatial update is not triggered by an update on my page but on a view which is inside a CollectionView on my page. And this page has ctor parameters. With your previous explaination, I think this is why it didn't work.
The second line of the log say : "Updated element not found". Is this because it's inside a datatemplate or I have someting wrong in my code ? because if I can reload only what i've updated, reloading whole page won't trigger and the constructor problem go away.
@Glabenwitt Yeah, I forgot that your element is inside the DataTemplate. Anyway, I have published an update to NuGet that should finally resolve this issue. Please try it.
Thanks!
Hi, I just want to try Livesharp in a Xamarin Forms project and when I modify a View, I got this message in the output console.
[0:] Received update for method CSBaseQuestionView.Build
[0:] warning: Updated element not found: Formulaire4_0.XForms.Controls.Cells.CSBaseQuestionView
[0:] warning: Reloading current page
[0:] Updating control node Xamarin.Forms.NavigationPage
[0:] InitializeComponent Formulaire4_0.XForms.Pages.QuestionnaireSaisiDetailPage
[0:] warning: Constructor initialization failed.
How can I have more information about the error in order to update my code to make it work ?
Some context : I use the free temporary version of livesharp (I wanted to works before buy it) The view I try to modify is use inside a DataTemplateSelector. My Page is a Xaml page and the constructor has multiples parameters with defaults values for some. I've test only in Android. I see nothing more in the console.