OYIon / LiveSharp

Public repository for the LiveSharp project
96 stars 4 forks source link

TypeError: Canot read property 'loadUrl' of undefined #72

Closed silentdiverchris closed 4 years ago

silentdiverchris commented 4 years ago

I'm trialling LiveSharp, installed yesterday and initially it seemed to work fine but today on first use (after reboot...) it's not rebuilding when I save my Xamarin project and I get the below error popup from the server window.

(Just verified I do have the NuGet package installed... thought i didn't for a moment - it's installed in the shared project, not in the Android/IOS ones)

image

3 log files created for this current run (build and deploy to Android emulator), first says;

18:41: Message: Loaded inject rule: * 18:41: Message: Loaded start method rule: 18:41: Message: Client Start method detected: System.Void [my application name]::.ctor() 18:41: Message: Client Start method detected: System.Void [my application name]::.cctor() 18:41: Message: Update handler: LiveSharp.XamarinFormsUpdateHandler 18:41: Message: Update handler: LiveSharp.XamarinFormsViewHandler 18:41: Message: Update handler: LiveSharp.XamarinFormsViewModelHandler 18:41: Warning: Injecting code into BindTap failed: Value cannot be null. Parameter name: method

2nd says (partial log around same time) 18:41:44 Starting dashboard process with arguments: /electronPort=8000 /electronWebPort=8002 /SolutionPath="C:\Dev[My Solution].sln" /ProjectName="[My project name]" /ProjectDir="C:\Dev[My project directory]" /NuGetPackagePath="C:\Users\Chris.nuget\packages\livesharp\1.5.21\build" 18:41:45 client connected: 127.0.0.1:53292 18:41:45 Client 127.0.0.1:53292 joined group 7 18:41:45 Client 127.0.0.1:53292 joined group 6

3rd says (partial log around same time) 18:41:48 The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. 18:41:48 The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. 18:41:48 The type or namespace name 'Debuggable' could not be found (are you missing a using directive or an assembly reference?)

...I'm assuming the last is talking about the LiveSharp server code, my app builds and works fine, just the LiveSharp logs have these errors.

Apologies for not asking in the gittable forum as suggested on the server window but on creating a user the OAuth message asked me to OK it having read access to 'team membership', 'private project boards' and 'private email addresses' - I'm not the owner of the project, not my place to give another company access to it's data so I couldn't create an account ans there's no 'register with an email address' option to gitter.

I've rebooted again and same message, rebuilt my project a few times, checked for NuGet updates and only installed LiveSharp yesterday so presumably have the latest version - as I say, it did seem to work yesterday in as much as I changed code and saved and the emulator updated - but it was very late, I kinda installed it, tried it, called it a good time to stop for he night and didn't look at it properly until today.

silentdiverchris commented 4 years ago

I just tried this with the CSharpForMarkupDemos solution that I was looking at yesterday and get the same 'A JavaScript error....' popup there too. Nothing untoward in the log for that run though, essentially all the success messages IO got when running my app, but without the ones about 'The type 'Object' is defined in an assembly that is not referenced' - but surely my app can find the definition of 'Object'... it's working fine ! - I'm still not clear whather it's complaining about my app or LiveSharp.

ionoy commented 4 years ago

Hello @chrisofthecoffee

Thank you for the detailed feedback!

Is The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. message coming from %TEMP%\server-*.log?

Also, when does loadURL popup appear? Is it consistent?

Thanks, Mihhail

silentdiverchris commented 4 years ago

Hi, thanks, yep, the three logs are all from %TEMP%\LiveSharp, first and third are from files server-blah.log, 2nd from build-blah.log

The popup appears... inconsistently... at the worst it appears both when the app is deploying/starting plus when I hit the Visual Studio stop button, but usually just when the app is deploying/starting... but sometimes not at all.

I'm using the CSharpForMarkupDemos project as a sanity check to see if it's just my project that causes the problem and I suspect it is, though the CSharp... project starting/closing does bring the message up sometimes... but I suspect only after my project has been at the server component previously (without it being shut down) and perhaps sullied it somehow. That's how it feels anyway.

I built a brand new project - I was planning to start afresh anyway, am learning Xamarin and there's a lot of experimental guff, pasted in code etc in the original project which may well be the cause of my problems - this just gave me the final impetus to bite the bullet. I reinstalled the LiveSharp server component and didn't run the sanity check project at all and I've not seen the message for a while so it does look like it was my previous project.

So... problem gone away in some sense but it'd be good to work out what it was anyway, if it's something janky about my project then I guess you guys still want your code to pick up on it to give better diagnostics, and I'd be curious to know what the problem is anyway.

I opened up the old project again (since the server component reinstall), it deployed and ran fine (no java popup), I made a change to a colour in some c#, saved and got the below in the logs window of the server component, same message as before (nothing in debugger window);

23:01:31.859: FileSaved handler failed System.Exception: Serializing document failed at LiveSharp.VisualStudio.Services.DocumentSerializer..ctor(Project project, SyntaxNode documentRoot, SemanticModel semanticModel, ILogger logger, Func2 typeFilter, Func2 memberFilter) at LiveSharp.VisualStudio.Services.LiveSharpHandler.PrepareUpdatesAsync(Project project, SyntaxNode documentRoot, SemanticModel semanticModel, IReadOnlyList`1 updatedMethods, String documentName, Boolean isDryRun)

23:01:31.859: The type or namespace name 'Debuggable' could not be found (are you missing a using directive or an assembly reference?)

23:01:31.858: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.

Is it talking about mscorlib references in your server component or my app ? - I'm guessing the sever component as my app would presumably have collapsed a messy heap well before displaying the test page without such a fundamental dependency.

I'll forge ahead with my brand new unsullied app which doesn't seem to provoke the problem, more than happy to run tests and get more diagnostics though, if it helps.

silentdiverchris commented 4 years ago

A quick update, I ran for a couple of hours with no problems, LiveSharp updating many times with zero problems then the same message (below) popped up again. I wasn't doing anything special, hitting save after setting binding on an ActivityIndicator. No errors in any logs and the popup repeats on each start/deploy.

Closed the service and restarted, working fine again.

image

silentdiverchris commented 4 years ago

I think this is two different problems, perhaps I should have logged them as discrete issues, this morning, first run from freshly booted machine gets the same messages below from the project that was being LiveSharped just fine last night, no JavaScript error popup.

This is with the update to 1.5.23 I got from from NuGet last night.

10:31:49.280: Ended job: Dry run for [My application name] (2717)

10:31:49.279: FileSaved handler failed System.Exception: Serializing document failed at LiveSharp.VisualStudio.Services.DocumentSerializer..ctor(Project project, SyntaxNode documentRoot, SemanticModel semanticModel, ILogger logger, TypeRegistry typeRegistry, Func2 typeFilter, Func2 memberFilter) at LiveSharp.VisualStudio.Services.LiveSharpHandler.PrepareUpdatesAsync(Project project, SyntaxNode documentRoot, SemanticModel semanticModel, IReadOnlyList`1 updatedMethods, String documentName, Boolean isDryRun)

10:31:49.269: The type or namespace name 'Debuggable' could not be found (are you missing a using directive or an assembly reference?)

10:31:49.268: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.

...and shortly after, on a subsequent run (server component restarted), the Java popup appeared again on startup/deploy... I'm pretty convinced they're separate issues though.

ionoy commented 4 years ago

There is a directory named SolutionCache in .nuget\LiveSharp\[version]\build It contains project information that LiveSharp uses for internal compilations. Please find the file named [YourProjectName].info and send it to me. Also, you can send it to my email (mihhail.maslakov at gmail dot com) or PM me on Gitter (https://gitter.im/LiveSharp/Lobby)

silentdiverchris commented 4 years ago

Thanks, am emailing diags to you now, unable to send to Gitter (see email).

ionoy commented 4 years ago

Could you try the attached NuGet package? I've updated the Roslyn dependencies, which is the most likely candidate to be the problem here. 

LiveSharp.1.5.26.zip

silentdiverchris commented 4 years ago

Trying to install with "Install-Package LiveSharp -Source d:\temp" gives the "The 'Source' parameter is not respected for the transitive package management based project(s)..." error (https://github.com/NuGet/Home/issues/7189) - have unzipped it to my visual studio offline packages directory and tried to install that way but it doesn't appear when I change source to search local folder... I've not done this before so I could well be missing something obvious...

In the meantime I notice there's a 1.5.25 on NuGet, I'll update to that and see if anything changes, doing that I notice I only have LiveSharp in my shared project, guess that's OK as it's working most of the time at least.

silentdiverchris commented 4 years ago

Hi, it's not working at all now, the logs window shows that it picks up source changes but the debugger window shows nothing happening, so source changes but no code update. I've uninstalled server and package, restarted, reinstalled and same. I'm on 1.5.25 but tried it on 1.5.23 again just in case. Server version 1.5.1 just reinstalled from a fresh download.

The logs windows shows the below, note the '...watcher created for at C:\Dev...' - I'm sure it used to say something between the 'for' and the 'at'.

19:08:29.281: Updating Views\LandingPage.cs 19:08:29.076: Starting job: Handling C# update: C:\Dev[path...]Views\LandingPage.cs 19:08:15.037: Ended job: Dry run for app name 19:08:10.386: Starting job: Dry run for [app name] 19:08:10.363: watcher created for at C:\Dev[path...]\ 19:08:10.312: Workspace loading finished in 1112ms

ionoy commented 4 years ago

Please check if there is anything in the Output window after the update.

silentdiverchris commented 4 years ago

Ah, good call, didn't think to check there;

[0:] livesharp: error: System.Exception: MethodInfo not found Define (ValueTuple2[]) at LiveSharp.Runtime.IL.MethodMetadata.GetCompatibleMethod (System.Collections.Generic.IEnumerable1[T] methodList, System.String methodName, System.Int32[] parameterTypeTokens, System.Type[] genericTypeArguments, System.Boolean exactArgumentTypes, System.Boolean throwIfNotFound) [0x00267] in :0 at LiveSharp.Runtime.IL.MethodMetadata.DeserializeMembers (System.Collections.Generic.IEnumerable1[T] memberElements) [0x003c8] in <cef3f13c8ccf43e099826c1e36a2d61c>:0 at LiveSharp.Runtime.IL.MethodMetadata..ctor (LiveSharp.Runtime.IL.TypeMetadata typeMetadata, System.Xml.Linq.XElement methodElement, LiveSharp.Runtime.Virtual.VirtualAssembly virtualAssembly, LiveSharp.ILogger logger) [0x0014b] in <cef3f13c8ccf43e099826c1e36a2d61c>:0 at LiveSharp.Runtime.IL.DocumentMetadata..ctor (System.Xml.Linq.XElement documentElement, LiveSharp.Runtime.Virtual.VirtualAssembly virtualAssembly, LiveSharp.ILogger logger, System.Func2[T,TResult] methodFilter) [0x0016a] in :0 at LiveSharp.Runtime.LiveSharpRuntime.UpdateDocument (System.Xml.Linq.XElement element, System.Func`2[T,TResult] methodFilter) [0x00007] in :0 at LiveSharp.Runtime.LiveSharpRuntime.LiveSharpMessageReceived (System.String messageContent, System.Byte contentType, System.Int32 groupId) [0x00025] in :0

ionoy commented 4 years ago

Can you post the definition of the Define method? Is there anything unusual about it? Does it work if you comment out the part that uses Define?

Thanks!

silentdiverchris commented 4 years ago

Hi, the only call to something called 'Define' is 6 versions of the below, creating grid definitions, I don't have a function called Define.

Commented them all out, should work ok apart from layout going crazy... testing... aha... I get activity in the debugger window !!

Yep, that's what's breaking it - nice one - I could possibly define them another way, do you want me to keep a branch to test a fix with ? - afaik it's standard c# markup.

(later yep, it's in MS examples here so I'm not doing anything too crazy/experimental :)

Unfortunately this is an aside to the above problem, I should have raised another issue but it all seemed connected at the time !

image

silentdiverchris commented 4 years ago

This seems worthy of mention... image

ionoy commented 4 years ago

Please try the updated LiveSharp package (1.5.27). I have fixed the Define issue.

silentdiverchris commented 4 years ago

Ok thanks, I updated from 1.5.25 to 1.5.27 and now when I start/deploy the server window stays on the 'You can start the application now' panel and doesn't switch to the runtime panels. Un/re-installed client and server, rebooted, rebuilt, same.

Looking in the logs I can't see any errors, the below seems to say the server and client have said hello;

log file... 18:42:13 client connected: 192.168.1.15:51524 18:42:14 Client 192.168.1.15:51524 joined group 1 18:42:14 Client 192.168.1.15:51524 joined group 4 18:42:14 (runtime) LiveSharp Server connected

output window... [0:] livesharp: Connected to 192.168.1.15:50540 [0:] livesharp: LiveSharp Server connected

It finds the startup interface fine; 19:09: Message: Client Start method detected: System.Void [blah].App::.ctor()

...so I don't understand why the server display isn't switching / watches not being set etc. - that worked fine before, any ideas / diags I can send ?

I'm super-happy to do all I can to help work out what's wrong, I'm well-invested in doing so having spent the last few days recoding XAML pages to C# as the new way forward with LiveSharp - if LiveSharp gives me the hot reload I'm giving up with switching then I'll gladly register, if it works it'll be fantastic but I really need to be making some progress soon and having to constantly rebuild for the smallest change is heavy going !

ionoy commented 4 years ago

This one should fix your issue.

LiveSharp.1.5.29.zip

silentdiverchris commented 4 years ago

You're absolutely correct, it did indeed, thanks.

OK, I'm live updating again which is great, I ran it for a few iterations to try to get the JavaScript error and got one after a while, below, the message is slightly different to that reported above, the property it can't read is now 'isDestroyed' rather than 'loadUrl', though that's not just changed, I've seen the 'isDestroyed' version before now.

The paths have changed as I put the server component in a more convenient folder.

image

silentdiverchris commented 4 years ago

All the above is working now, lets close this epic - thanks for all your help.