Share via

Windows.Networking.Sockets.DataWriter.StoreAsync throws System.Exception on Hololens 2

BothLine 6 Reputation points
2022-07-28T11:17:51.09+00:00

I am currently developing an application for the Hololens 2 in Unity.
This application is communicating via Websocket with a mobile device, where the Websocket Server is located.
The communication is established and works fine, I even can send pings and some data.
But at some point, the following method starts to throw an exception:
Windows.Networking.Sockets.DataWriter.StoreAsync()

which I use like this:

private async Task SendAsync(byte[] Data)  
{  
	DataWriter dataWriter = new DataWriter(streamsocket.OutputStream);  
	try  
	{  
		dataWriter.WriteBytes(Data);  
		await dataWriter.StoreAsync(); // <- throws System.Exception  
	}  
	catch (Exception ex)  
	{  
		Debug.Log(ex.Message); // <- UnityEngine.Debug.Log: "Exception of type 'System.Exception' was thrown."  
	}  
	finally  
	{  
		dataWriter?.DetachStream();  
		dataWriter?.Dispose();  
	}  
}  

where the variable streamsocket is of type "Windows.Networking.Sockets.StreamWebSocket".

and here is the full callstack for when the exception is thrown

Exception of type 'System.Exception' was thrown.  
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])  
UnityEngine.Logger:Log(LogType, Object)  
UnityEngine.Debug:Log(Object)  
WebSocketSharp.<SendAsyncTask>d__21:MoveNext()  
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(TStateMachine&)  
WebSocketUWP.WebSocket:Send(Byte[])  
<PostToServer>d__27:MoveNext()  
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)  
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)  
<PostToServerAndWait>d__28:MoveNext()  
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)  
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)  
<>c__DisplayClass26_0:<SendMessageImplAsync>b__0()  
Microsoft.MixedReality.WebRTC.Unity.Signaler:Update()  

thanks for your help advance

Developer technologies | Universal Windows Platform (UWP)
Windows development | Windows API - Win32
HoloLens | Development
HoloLens | Development

The process of creating immersive mixed reality applications for Microsoft HoloLens,

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


1 answer

Sort by: Most helpful
  1. BothLine 6 Reputation points
    2022-08-04T15:02:53.947+00:00

    Thanks for your response!
    I kind of fixed the issue. I'm not 100% percent sure, but probably was the data size too large for a single StoreAsync() call.
    I now simply split up the data I want to send into smaller chunks and send them one by one with a small delay, which now works perfectly fine!

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.