Bug 21622 - oData - BeginSaveChanges never calls the service or fires the AsyncCallback Action when ID is GUID generated by server
Summary: oData - BeginSaveChanges never calls the service or fires the AsyncCallback A...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies ()
Version: 4.0.0
Hardware: PC Windows
: High normal
Target Milestone: Untriaged
Assignee: Ludovic Henry
URL:
Depends on:
Blocks:
 
Reported: 2014-07-26 17:48 UTC by Anthony
Modified: 2017-02-08 20:05 UTC (History)
16 users (show)

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


Attachments
Xamarin.Forms app which illustrates the bug (543.83 KB, application/x-zip-compressed)
2014-07-26 17:48 UTC, Anthony
Details
Desktop Repo targeting Mono (30.40 KB, application/zip)
2015-07-07 10:31 UTC, Anthony
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 GitHub or Developer Community 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 NOT_REPRODUCIBLE

Description Anthony 2014-07-26 17:48:51 UTC
Created attachment 7497 [details]
Xamarin.Forms app which illustrates the bug

After adding an entity to the DataServiceContext, which has a GUID primary key field assigned by the server, that call to BeginSaveChanges() never calls the service or fires the AsyncCallback action.  

Below is an excerpt from the attached sample project which illustrates the issue.

	var context = new XamarinTestEntities(new Uri(_serviceURI));

	// Creating DTO User to send to service
	// Not setting ID as that is set by the service
	var userToAdd = new User()
	{
		Name = name
	};

	// Adding user to context
	context.AddToUsers(userToAdd);
	
	// The AsyncCallback for BeginSaveChanges never fires for some reason on Android.
	// Works fine on iOS and WP
	context.BeginSaveChanges(result =>
	{
		// This code will never execute
		context.EndSaveChanges(result);
		
		Device.BeginInvokeOnMainThread(() => successAction(userToAdd));

	}

Thanks :)
Comment 1 Ram Chandra 2014-07-28 09:43:45 UTC
I can reproduce the reported behavior with the attached project . I’ll need confirmation from the developer if this is a bug. Leaving as NEW for now.

I have checked this issue with iOS project also and I am getting the same behavior.

Screencast:http://www.screencast.com/t/ZeyW0V5lIyae

Environment Info:

Microsoft Visual Studio Professional 2013
Version 12.0.30501.00 Update 2
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

LightSwitch for Visual Studio 2013   06177-004-0444002-02701
Microsoft LightSwitch for Visual Studio 2013

Office Developer Tools - May 2014 Update ENU   06177-004-0444002-02701
Microsoft Office Developer Tools for Visual Studio 2013 - May 2014 Update ENU

Team Explorer for Visual Studio 2013   06177-004-0444002-02701
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06177-004-0444002-02701
Microsoft Visual Basic 2013

Visual C# 2013   06177-004-0444002-02701
Microsoft Visual C# 2013

Visual C++ 2013   06177-004-0444002-02701
Microsoft Visual C++ 2013

Visual F# 2013   06177-004-0444002-02701
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06177-004-0444002-02701
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06177-004-0444002-02701
Windows Phone SDK 8.0 - ENU

ASP.NET and Web Tools   2013.2.50425
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Windows Azure Web Sites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Windows Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.1.20409.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.1
Provides common services for use by Azure Mobile Services and Windows Azure Tools.

NuGet Package Manager   2.8.50313.46
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.30919.1
Microsoft SQL Server Data Tools

Windows Azure Mobile Services Tools   1.1
Windows Azure Mobile Services Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.1.228.0 (2349ba7b70529ea26ba842e1ec32d054bd6abb3b)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android
Comment 2 Anthony 2014-07-31 05:38:05 UTC
Hi!

Just wanted to add that this was working with iOS and WP.  After updating to the most recent beta, it stopped working on iOS as well. Still works fine on WP.

Thanks
Comment 3 Anthony 2014-08-06 06:01:29 UTC
Hi!

Is there any update on this bug?

Thanks
Comment 4 Anthony 2014-09-11 06:48:12 UTC
Hi!

Is there any update on this bug?  Please let me know if you need additional information.

Thanks
Comment 5 Ian Mai 2014-10-27 20:13:49 UTC
Are there any next steps that we can provide for a work around for this as this is still a problem for Anthony.
Comment 6 Shruti 2015-01-20 03:25:23 UTC
As per comment 1 and 2, we are setting its status as Confirmed.
Comment 7 Jonathan Pryor 2015-01-20 11:49:14 UTC
Looks like a bug in System.Data.Services.Client.
Comment 10 Anthony 2015-07-07 10:29:17 UTC
Hi,

As requested I created a desktop version that targets the Mono Runtime.

@Marek if it helps at all, this was working on iOS when I originally posted the bug.  Now it appears to no work on iOS either. 

I'm not sure how to build against and older version, but if it is possible, I'd try a version that is a 12-14 months old.

Please let me know if I can be of any other assistance, as I really would like this bug fixed.

Thanks for your time,
Ant
Comment 11 Anthony 2015-07-07 10:31:00 UTC
Created attachment 11906 [details]
Desktop Repo targeting Mono
Comment 12 Marek Habersack 2015-08-25 06:24:17 UTC
Reassigning to Mono proper since the bug is reproducible on desktop Mono using
the project from comment 11 and it also affects Xamarin.iOS.
Comment 13 jackjoy 2015-08-26 20:58:16 UTC
Maybe same problem with bug 31450:
https://bugzilla.xamarin.com/show_bug.cgi?id=31450
Comment 14 Ludovic Henry 2015-09-16 10:38:47 UTC
A workaround for this problem: instead of using the Begin/End mechanism, use the threadpool directly:

ThreadPool.QueueUserWorkItem (_ =>
    {
        try
        {
            context.SaveChanges ();                         
        }
        catch (Exception ex)
        {
            exceptionAction (ex.InnerException ?? ex);
            return;
        }
        successAction(userToAdd);
    },
    null);

This fixes the issue on my machine with the desktop repro, I didn't test on devices.
Comment 15 Anthony 2015-09-16 11:25:21 UTC
Hi Ludovic!

Thanks for the workaround.  I appreciate it. :)

I'm consuming this from a PCL. 

I abstracted out the call to ThreadPool.QueruerUserWorkItem but I also noticed that SaveChanges does not exist in the PCL version of System.Data.Services.Client.DataServiceContext.

Do you have any guidance on how to get around this?  Maybe I am missing something.

Thanks,
Ant
Comment 16 Ludovic Henry 2015-09-16 11:56:33 UTC
On the PCL front, I have absolutely no experience, sorry about that...

But, if Begin/EndSaveChanges are available with PCL, you can also work around SaveChanges with the following code:

context.EndSaveChanges (context.BeginSaveChanges ());
Comment 17 Anthony 2015-09-16 12:53:50 UTC
Hi Ludovic!

It seems that with 
context.EndSaveChanges (context.BeginSaveChanges ());
it sometimes works the first time but the second call hangs.  When I pause and look at the callstack, I find:

in System.Threading.WaitHandle.WaitOne_internal
in System.Threading.WaitHandle.WaitOne
in System.Data.Services.Client.BaseAsyncResult.EndExecute<System.Data.Services.Client.BaseSaveResult>
in System.Data.Services.Client.DataServiceContext.EndSaveChanges

I also want to better understand the implications of calling 
context.EndSaveChanges (context.BeginSaveChanges ());

Thanks again for your assistance.  

I am EXTREMELY eager to get this issue resolved.

Ant
Comment 18 Anthony 2015-09-17 08:28:07 UTC
Hi Ludovic,

Just wanted to follow-up.

I've tried the following workaround, unfortunately, none work.

All solutions were defined as interfaces and attempted to be injected into the PCL.

1. Created an interface and implement in the platform specific library.
void SaveChanges(DataServiceContext context)
{


}
Comment 19 Anthony 2015-09-17 08:38:11 UTC
Hi Ludovic,

Just wanted to follow-up.

I've tried the following workaround, unfortunately, none work.

All solutions were defined as interfaces and attempted to be injected into the
PCL.

1. Created an interface and implemented in the platform specific library.

void SaveChanges(DataServiceContext context)
{
	context.SaveChanges();
}

This did not work because the DataServiceContext from the PCL comes from Microsoft.Data.Services.Client while the platform specific one comes from System.Data.Services.Client and it would not compile.

2. Created the interface
    public interface IDataServiceContext
    {
        void CreateContext(Uri serviceURI, string userSessionId);
        void AddObject(string objectName, object entity);
        void UpdateObject(object entity);
        void DeleteObject(object entity);
        bool SaveChanges(Action<Exception> exceptionAction);
    }

and implemented the platform specific logic. The CreateContext method creates a platform specific instance. This compiles but fails at runtime, because the call to AddObject fails with an error indicating that the entity object passed in is an invalid type and missing the IsEntityType flag.

At this point, I do not know how else to workaround this. 

Please let me know what else can be done.

Thanks again for your assistance,
Ant
Comment 20 Anthony 2015-09-18 11:22:33 UTC
Hi Ludovic,

I was wondering if you have any additional insights.  Unfortunately, this bug is preventing me from releasing.

Is there anything I can do to assist?

Thanks for your time,
Ant
Comment 21 Ludovic Henry 2015-09-21 05:17:28 UTC
Hi Anthony,

I tried over the weekend to find another workaround, but I couldn't get it to work. I am also actively working on fixing the Begin/End invoke on sockets, but it still is in a pull request. As soon as it lands on mono/master, I will check if it fixes your problem.

Thank you,
Ludovic
Comment 22 Anthony 2015-09-21 06:51:58 UTC
Hi Ludovic!

Thanks so much for the update :)

I appreciate it!

Let me know if there is anything I can do to help.

Take care,
Ant
Comment 23 Anthony 2015-09-22 08:18:38 UTC
Hi Ludovic :)

Do you have an update ETA when it will land in mono/master for testing?

Thanks,
Ant
Comment 24 PJ 2015-10-02 10:41:43 UTC
Unfortunately we don't have an updated ETA at this time Anthony. 

I can say it will definitely not be making it into our Cycle 6 initial release, so I'm updating the milestone.
Comment 25 Anthony 2015-10-04 17:48:11 UTC
Hi PJ & Ludovic,

It appears I was able to get around this bug by using the sync methods. 

I'm nearly complete, there is a LARGE of code that needed to be refactored, but I abstracted out the calls to the data service via interfaces and implemented the service logic in the iOS and Android specific classes libraries (sharing the same iOS/Android files using file linking)

This also allowed me to take advantage of wrapping the calls in Task.Run() to allow for async/await to be used in the PCL.

I'll update once I am fully completed.

Thanks again for the assistance, and the workaround can be of value to someone.

Please let me know if you have any questions.

Take care,
Ant
Comment 26 Filip Drsek 2015-10-05 05:23:32 UTC
I and my colleagues have the same problem, which is probably due to this bug. We want to create a Xamarin.Forms application that would be able to read, add, update and delete items in an OData service, and we do not manage to make it work. Therefore we would be very happy to at least know when we can expect this issue to be resolved.
Comment 28 EJ 2015-12-28 12:52:43 UTC
Any news on this? This bug prevents our app from going live.

@Anthony; is your work-around finally working for you?

Thanks,
Ernstjan
Comment 29 Anthony 2015-12-29 16:39:29 UTC
Hi @Ernstjan!

My workaround has been working great. I like it better actually, because now I am returning a Task<T> and I can use async and await. 

Took a while to refactor, but in the end it was better choice.

Please let me know if you have any questions.

All the best,
Ant
Comment 30 PJ 2016-03-02 20:17:21 UTC
This bug is not going to make it into C6SR2, and I don't have a concrete estimate on the timeline for the fix. Removing the milestone until we have another update from Ludovic.