Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

FileInfo type not found when using WebSocketSharp SendAsync() method

I'm having a recurring problem when developing an app for the Hololens, and I'm completely lost as to what may be causing it. I'm using Unity 2018.1.4 and VS2017, building for .NET4.x framework and using the Newtonsoft.Json and WebSocketSharp plugins to try to write some data to a server. The build in Unity is using the Mixed Reality Toolkit package, and is set up to deploy to UWP platforms using the Mixed Reality Project/Mixed Reality Scene configurations that are built into this package.

The error occurs at build time in the Unity editor, and throws the message:

Assets\Scripts\UMCPInterface.cs(249,9): error CS7069: Reference to type 'FileInfo' claims it is defined in 'mscorlib', but it could not be found

The relevant code in my C# script is:
(It may be relevant that no errors appear in Visual Studio, only in the UnityEditor Console window)

using System;
using System.IO;
using UnityEngine;
using WebSocketSharp;
using Newtonsoft.Json;

public class UMCPInterface:MonoBehaviour{
    private WebSocket ws;
    public void logdata<T>(T data){
         ws.SendAsync(createLogDataMessage<T>(data), (bool status) =>
                {
                    appendToStatus("ws.SendAsync: " + status );
                });
    }

    string createLogDataMessage<T>(T loggingData){
        UMCPMessage<T> logMessage = new UMCPMessage<T> (loggingRootPath, MetadataLoggingDirectory, loggingData);
        return logMessage.getSerializedJSON ();
    }

    void appendToStatus(string message) {       
        if (DebugToConsole) {
            Debug.Log (message);
        }
    }

    [System.Serializable]
    public class UMCPMessage<T> {   
     public string @_ns;
     public string type;
     public string root;
     public string client_id;
     public string client_timestamp;
     public string message_id;
     public UMCPPayload<T>[] data;

     public UMCPMessage(string loggingRootPath, string dataPath, T metadata) {
        @_ns = "urn:x-ipstudio:ns:0.1";
        type = "urn:x-ipstudio:api:umcp.post";
        root = loggingRootPath;
        client_id = UMCPInterface.GetUniqueUMCPClientID ();
        client_timestamp = UMCPInterface.timeStamp ();
        message_id = UMCPInterface.createUUIDString ();
        data = new UMCPPayload<T>[1];
        data [0] = new UMCPPayload<T> (dataPath, metadata);
    }

    public string getSerializedJSON() {
        string json = JsonConvert.SerializeObject (this);
        json = json.Replace ("_ns", "@_ns");
        return json;
    }
}

The line that is throwing the error is the implementation of the SendAsync() method, which should be using the following override, as the method createLogDataMessage() returns a string value.

void WebSocket.SendAsync(string data, Action<bool> completed)

The first problem seems to be that the compiler is expecting the SendAsync() method to be using the following override, which expects a FileInfo object being passed in.

void WebSocket.SendAsync(System.IO.FileInfo fileInfo, Action<bool> completed)

However, this in itself shouldn't be a problem, as the project references the mscorlib library (and the System.IO namespace it contains) and I can explicitly create instances of a FileInfo object without any problems elsewhere in the script. As soon as I delete the line containing the SendAsync method the script compiles just fine, however obviously this is a pretty crucial function and I've had no luck so far in troubleshooting it.

If anyone has any suggestions/solutions/workarounds to this problem I'd be really grateful, it's been a stumbling block for a few days now!

Thanks

Best Answer

Answers

Sign In or Register to comment.