lastfm icon indicating copy to clipboard operation
lastfm copied to clipboard

issue with exception

Open rickerk6gdo opened this issue 6 years ago • 12 comments

The follow code intermittently will cause me to get the NullReferenceException Object reference not set to an instance of an object. with Xamarin forms. Even when I do the NULL check on the instance, it gives me the fault.

Ideas?

public async void GetXml( string artist, string song) { //Check network status

		{
			lastfmclass = new lastfmimage();
			inxml = true;
			

			var auth = new LastAuth("71b08e0", "b93eb5a3f84fc175e");
			var albumApi = new AlbumApi(auth); // this is an unauthenticated call to the API
			var trackApi = new TrackApi(auth); // this is an unauthenticated call to the API
			var artistApi = new ArtistApi(auth); // this is an unauthenticated call to the API

			var response = await trackApi.GetInfoAsync(song,artist);
			var response2 = await artistApi.GetInfoAsync(artist);


			var songinfo = response.Content; // visions is a LastAlbum
			
			var artistinfo = response2.Content;
			
			if (songinfo != null)
			{
				if (songinfo.AlbumName != null)
				{
					response1 = await albumApi.GetInfoAsync(artist, songinfo.AlbumName);

					var albuminfo = response1.Content;

					if (albuminfo != null)
					{
						lastfmclass.AlbumImage = albuminfo.Images.Large.AbsoluteUri;
					}
				}
			}



			lastfmclass.ImageUri = "";
			//	Debug.Assert(artistinfo.MainImage.Large.AbsoluteUri == null, "art is null");

			//	if (artistinfo.MainImage.Large.AbsoluteUri == null)
			//	{
			//		return;
			//	}
			//	else
			if (artistinfo != null)
			{
			
				lastfmclass.ImageUri = artistinfo.MainImage.Large.AbsoluteUri;
			
			
				
			}
			//ImageUri = new UriImageSource { Uri = new Uri(prodPic) },
			//public string ArtistImage => $"prefix-{OtherProperty}-suffix.png";
			
			BindingContext = lastfmclass;
			inxml = false;

		}
	}

rickerk6gdo avatar Nov 15 '18 18:11 rickerk6gdo

Can you post the stack trace of the exception?

rikkit avatar Nov 16 '18 12:11 rikkit

there is none.. attached screenshot . If I take the LFM code out, no fault

lastfmerror

rickerk6gdo avatar Nov 16 '18 19:11 rickerk6gdo

This looks like it could be related to #76.

What version of the package are you using, and can you provide some more details on the project? Is it possible to share the source in order to try to reproduce the issue?

rikkit avatar Nov 18 '18 12:11 rikkit

No problem, what's a good way to send it to only you.

rickerk6gdo avatar Nov 19 '18 19:11 rickerk6gdo

version of last fm is 1.1.0.339.

This will only happen intermittently . I do have it on a timer to call lastfm code

Device.StartTimer(TimeSpan.FromSeconds(10), () => { Browser.Source = (Browser.Source as UrlWebViewSource).Url; if (!inxml) lastfm();

		    // Set the grid to invisible
		    // IsGridVisible = false;

		    // TRUE for we want the timer to start again after this code
		    // If return FALSE: timer stops
		    return true;
	    });

rickerk6gdo avatar Nov 21 '18 20:11 rickerk6gdo

Rikki?

rickerk6gdo avatar Nov 26 '18 23:11 rickerk6gdo

Sorry @rickerk6gdo, you can email your source to hello [at] rikk [dot] it but I can't promise I'll be able to try anything soon. In the spirit of open source, could you post on this thread more details about your project? What platform? What version of .Net? What NuGet packages are you using? I don't currently have much time to investigate this for you so if this kind of info is public maybe someone else will be able to help you.

rikkit avatar Nov 27 '18 10:11 rikkit

Thanks

VS 2017 with xarmain forms 3.4.10008975 Xam.plugin.media 4.0.1.5 Plugin.mediamanager 0.4.5 Inflateable..lastfm 1.1.0.339 HTML agilitypack 1.8.10

Building for IOS and android.

I guess I dont understand why I'd be getting nulls back from XML, rather than empty string sets.

rickerk6gdo avatar Nov 27 '18 18:11 rickerk6gdo

finally got a call stack.

does this give any clues?

0x5C in UIKit.UIApplication.UIApplicationMain	C#
0xB in UIKit.UIApplication.Main at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.10/src/Xamarin.iOS/UIKit/UIApplication.cs:79,4	C#
0x2F in UIKit.UIApplication.Main at /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.10/src/Xamarin.iOS/UIKit/UIApplication.cs:63,4	C#

0x9 in kqlh.iOS.Application.Main at d:\stream2\kqlh\kqlh.iOS\Main.cs:19,5 C#

rickerk6gdo avatar Nov 29 '18 23:11 rickerk6gdo

I don't think so. Couple of Qs

  • Is it just the iOS project you experience this on? Or Android also?
  • Are you calling Inflatable.Lastfm methods from the UI thread or a background thread? Because it looks like the UI thread is crashing from the stacktrace there. (Not 100% sure if this is a relevant question - my knowledge of threading in apps come from a Windows background, not Android or iOS)

rikkit avatar Dec 13 '18 15:12 rikkit

Is it just the iOS project you experience this on? Or Android also?

 both;

Are you calling Inflatable.Lastfm methods from the UI thread or a background thread? Because it looks like the UI thread is crashing from the stacktrace there. (Not 100% sure if this is a relevant question - my knowledge of threading in apps come from a Windows background, not Android or iOS) Calling them from the Mainpage.cs. This is Similar to WinMain under Windows. I set up a global var in the init code... then do a 'new' it each time I enter the function.

------ Original Message ------ From: "Rikki Tooley" [email protected] To: "inflatablefriends/lastfm" [email protected] Cc: "Rick Ruhl" [email protected]; "Mention" [email protected] Sent: 12/13/2018 7:36:46 AM Subject: Re: [inflatablefriends/lastfm] issue with exception (#133)

I don't think so. Couple of Qs

Is it just the iOS project you experience this on? Or Android also?Are you calling Inflatable.Lastfm methods from the UI thread or a background thread? Because it looks like the UI thread is crashing from the stacktrace there. (Not 100% sure if this is a relevant question - my knowledge of threading in apps come from a Windows background, not Android or iOS) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/inflatablefriends/lastfm/issues/133#issuecomment-447012214, or mute the thread https://github.com/notifications/unsubscribe-auth/AhbR0RLAkmHvGLfzlYDXaqb9pUw33DScks5u4nQOgaJpZM4YhYPC.

rickerk6gdo avatar Dec 13 '18 18:12 rickerk6gdo

If you're in VS - try unticking the "Just My Code" option in the debugger when you repro. You might get a better stacktrace.

rikkit avatar Dec 14 '18 12:12 rikkit