Bug 25193 - XElement casting from SQL Server XML field fails in Linq query
Summary: XElement casting from SQL Server XML field fails in Linq query
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data ()
Version: 3.8.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-12-09 11:44 UTC by Alex Diaz
Modified: 2014-12-09 21:54 UTC (History)
1 user (show)

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

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 for Bug 25193 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Alex Diaz 2014-12-09 11:44:31 UTC
I am running the same code in Mono 3.10 for Mac and .NET Framework 4.5. IT works in .NET but in Xamarin it fails to process a Linq query.

//Save to database
				qry = from prod in dc.products where prod.id == id select prod;
				if (qry.Count() > 0)
					var item = qry.Single();
					item.name = tree.Root.name;
					MemoryStream stream = tree.Serialize ();
					item.product1 = stream.ToArray();
					item.modified_by = user;
					item.modified = DateTime.Now;
					item.size = (int)stream.Length;
                                        string xml = tree.SerializeToString();
                                        item.product_xml = XElement.Parse(xml);
					product product = new product();
					MemoryStream stream = tree.Serialize ();
					product.product1 = stream.ToArray();
					product.name = tree.Root.name;
					product.created_by = user;
					product.modified_by = user;
					product.created = DateTime.Now;
					product.modified = DateTime.Now;
					product.store_id = store_id;
					product.size = (int)stream.Length;
                                        string xml = tree.SerializeToString();
                                        product.product_xml = XElement.Parse(xml);
					product.active = false;

Cannot cast from source type to destination type.

Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): System.Data.Linq.
Exception stack trace:

at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,System.Data.IDataRecord,DbLinq.Data.Linq.Mapping.MappingContext) <IL 0x000af, 0x00487>
at DbLinq.Data.Linq.Sugar.Implementation.QueryRunner.Select<OnlinePriceSystem.Models.product> (DbLinq.Data.Linq.Sugar.SelectQuery) <0x0029a>
at DbLinq.Data.Linq.Sugar.Implementation.QueryRunner.SelectSingle<OnlinePriceSystem.Models.product> (DbLinq.Data.Linq.Sugar.SelectQuery,bool) <0x00090>
at DbLinq.Data.Linq.Sugar.Implementation.QueryRunner.SelectScalar<OnlinePriceSystem.Models.product> (DbLinq.Data.Linq.Sugar.SelectQuery) <0x00284>
at DbLinq.Data.Linq.Implementation.QueryProvider`1<OnlinePriceSystem.Models.product>.Execute<OnlinePriceSystem.Models.product> (System.Linq.Expressions.Expression) <0x0009c>
at System.Linq.Queryable.Single<OnlinePriceSystem.Models.product> (System.Linq.IQueryable`1<OnlinePriceSystem.Models.product>) <0x00184>
at OnlinePriceSystem.Controllers.TreeViewController.SaveProduct (int) [0x00369] in /Users/alex/online-price-system/OPS/Controllers/TreeViewController.cs:671
at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,System.Web.Mvc.ControllerBase,object[]) <IL 0x0000e, 0x00077>
at System.Web.Mvc.ActionMethodDispatcher.Execute (System.Web.Mvc.ControllerBase,object[]) <IL 0x00008, 0x00031>
at System.Web.Mvc.ReflectedActionDescriptor.Execute (System.Web.Mvc.ControllerContext,System.Collections.Generic.IDictionary`2<string, object>) <IL 0x0007a, 0x002d3>
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod (System.Web.Mvc.ControllerContext,System.Web.Mvc.ActionDescriptor,System.Collections.Generic.IDictionary`2<string, object>) <IL 0x00003, 0x00033>
at System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeSynchronousActionMethod (System.Web.Mvc.ControllerContext,System.Web.Mvc.ActionDescriptor,System.Collections.Generic.IDictionary`2<string, object>) <IL 0x00004, 0x00034>
at System.Web.Mvc.Async.AsyncControllerActionInvoker/<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41 () <IL 0x00018, 0x00043>
at System.Web.Mvc.Async.AsyncResultWrapper/<>c__DisplayClass8`1<System.Web.Mvc.ActionResult>.<BeginSynchronous>b__7 (System.IAsyncResult) <0x00029>
at System.Web.Mvc.Async.AsyncResultWrapper/WrappedAsyncResult`1<System.Web.Mvc.ActionResult>.End () <0x000c4>
at System.Web.Mvc.Async.AsyncResultWrapper.End<System.Web.Mvc.ActionResult> (System.IAsyncResult,object) <0x00067>
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod (System.IAsyncResult) <IL 0x00006, 0x00033>
at System.Web.Mvc.Async.AsyncControllerActionInvoker/<>c__DisplayClass37/<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33 () <IL 0x00030, 0x000a2>
at System.Web.Mvc.Async.AsyncControllerActionInvoker/<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49 () <IL 0x00008, 0x0004c>
Comment 1 Alex Diaz 2014-12-09 21:51:03 UTC
It seems that the problem is in the method SubmitChanges() of class DataContext