MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

ASP.NET Core - iOS Specific - Unable to read beyond the end of the stream #942

Open animjn opened 4 years ago

animjn commented 4 years ago

image

Question Hi! I've the Dataportal hosted in ASP.NET Core. Trying to connect from Android works fine, but when attempted to connect from iOS I get the above error. Wanted to check if can give provide some insights into it.

Version and Platform CSLA version: 5.1 OS: iOS, ASP.NET Core

rockfordlhotka commented 4 years ago

It is hard to help without the full ToString output from the exception. You need to capture that and provide the results here.

animjn commented 4 years ago

Thank you for looking into it. The following is the complete ex.ToString(). The AppServerCore project is setup similar to ProjectTracker 5.1. I receive the following only on connecting from iOS

Csla.DataPortalException: Unable to read beyond the end of the stream.
  at Csla.DataPortalClient.HttpProxy.Update (System.Object obj, Csla.Server.DataPortalContext context, System.Boolean isSync) [0x00163] in <feea9dc9b09a48e6b208754bd584bf7b>:0 
  at Csla.DataPortal`1[T].DoUpdateAsync (T obj, System.Boolean isSync) [0x0066f] in <feea9dc9b09a48e6b208754bd584bf7b>:0 
  at Csla.DataPortal`1[T].ExecuteAsync (T command) [0x00069] in <feea9dc9b09a48e6b208754bd584bf7b>:0 
  at Csla.DataPortal.ExecuteAsync[T] (T command) [0x00065] in <feea9dc9b09a48e6b208754bd584bf7b>:0 
  at Avs.Site.Library.Utility.VerifyServerUri (System.String uri) [0x000c7] in C:\Users\ash\Documents\Source\Site\Avs.Site.Library\Utility\Utility.cs:135 
  at Avs.Site.UI.Shared.Views.ConnectionSettingsPage.TryVerifyServerURI (System.String uri) [0x00035] in C:\Users\ash\Documents\Source\Site\Avs.Site.UI.Shared\Views\Settings\ConnectionSettingsPage.xaml.cs:232 

System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
   at System.IO.BinaryReader.InternalRead(Int32 numBytes)
   at Csla.Serialization.Mobile.CslaBinaryReader.Read(Stream serializationStream)
   at Csla.Server.Hosts.HttpPortalController.InvokePortal(String operation, Stream requestStream, Stream responseStream)
rockfordlhotka commented 4 years ago

That's not so easy to troubleshoot, sadly there are a number of possible issues I can think of.

  1. There might be a size limit on the HttpClient in iOS causing the response data to get cut off mid-stream - so maybe you can raise that limit (if there is one)
  2. You might be getting some unexpected server error like a 404 or 5xx or something - and the deserialization process fails because it isn't a binary data feed as expected; using Fiddler can help
  3. I've seen something like this when a specific type can't be serialized - specifically when trying to pass a custom principal/identity type - and I don't know what that happened, but it seems vaguely similar

I'd recommend putting Fiddler on the wire so you can see exactly what is going over the network.

animjn commented 4 years ago

Thanks Rocky! What's a bit baffling is that, I've setup duplicate Dataportals in Azure in .NET 4.7 and .NET Core 3.1, based on samples and only the following single case gives an exception.

rockfordlhotka commented 4 years ago

Agreed, I don't know what is going on. I assume you've done some searching to find out of HttpClient works differently on iOS or something like that?

I suppose you could try the gRPC data portal channel and see if that's any different. I suspect not though, because I have a hunch that gRPC might use HttpClient behind the scenes (?).

Bowman74 commented 4 years ago

You might be running into App Transport Security. Is your dataportal connection using HTTPS with at least TLS 1.2? If not have you added your endpoint as an exception in the info.plist?

See the following: https://docs.microsoft.com/en-us/xamarin/cross-platform/macios/http-stack

Edit to add: The MS docs are wrong on the defaults. New projects use NSUrlSession for the underlying handling of HttpClient which will run into ATS restrctions.

animjn commented 4 years ago

Hi! After seeing a related post I tried to reproduce it with Project Tracker and log the raw response using Fiddler -

HTTP/1.1 200 OK
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Mon, 18 May 2020 13:40:47 GMT
Content-Length: 1136 

���������.Csla.Server.Hosts.HttpChannel.HttpResponse, /c���������
_fieldManager������������������+Csla.Core.FieldManager.FieldDataManager, /c���������    ErrorData���������������_businessObjectType������������sCsla.Server.Hosts.HttpChannel.HttpResponse, Csla, Version=5.1.0.0, Culture=neutral, PublicKeyToken=93be5fdc093e4c30�
GlobalContext������������
ObjectData����������������/Csla.Server.Hosts.HttpChannel.HttpErrorInfo, /c���������������������������������������������������tCsla.Server.Hosts.HttpChannel.HttpErrorInfo, Csla, Version=5.1.0.0, Culture=neutral, PublicKeyToken=93be5fdc093e4c30��ExceptionTypeName    �����������System.IO.EndOfStreamException��Message
����������,Unable to read beyond the end of the stream.��Source������������System.Private.CoreLib�
StackTrace�������������   at System.IO.BinaryReader.InternalRead(Int32 numBytes)
   at Csla.Serialization.Mobile.CslaBinaryReader.Read(Stream serializationStream)
   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Stream serializationStream)
   at Csla.Server.Hosts.HttpPortalController.InvokePortal(String operation, Stream requestStream, Stream responseStream)