Bug 46971 - Exception when using linq to fetch AddressBook
Summary: Exception when using linq to fetch AddressBook
Status: RESOLVED INVALID
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-11-15 03:37 UTC by Squall Leonhart
Modified: 2017-06-19 16:37 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
This is the test project (82.23 KB, application/zip)
2016-11-17 04:23 UTC, Squall Leonhart
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Squall Leonhart 2016-11-15 03:37:40 UTC
I'm using Xamarin.Mobile to get the addressbook.

I created an Interface and implement following method:

private IEnumerable<Contact> GetContacts()
{
	return _addressbook.Select(p => new Contact
	{
		Name = p.DisplayName,
		PhoneNumber = p.Phones.Select(q => q.Number.Replace("-", "").Replace("+84", "0").Trim())
	});
}

It's throw following exception at runtime: System.ArgumentException: Unhandled expression type: 'MemberInit'

If i change to foreach, it's work:

private IEnumerable<Contact> GetContacts()
{
	foreach (var p in _addressbook)
	{
		var contact = new Contact
		{
			Name = p.DisplayName,
			PhoneNumber = p.Phones.Select(q => q.Number.Replace("-", "").Replace("+84", "0").Trim())
		};
		yield return contact;
	}
}
Comment 1 adrianknight89 2016-11-15 17:39:48 UTC
Can you attach a repro instead?
Comment 2 Squall Leonhart 2016-11-17 04:23:24 UTC
Created attachment 18494 [details]
This is the test project

I attach the test project.

Or you can clone the following repository:
https://github.com/Knight1988/AddressbookApp.git
Comment 3 E.Z. Hart [MSFT] 2017-06-19 16:37:39 UTC
This is an issue with Xamarin.Mobile; it's not a Xamarin.Forms bug. You should open an issue at https://github.com/xamarin/Xamarin.Mobile/issues