Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with Portable Class Library #100

Closed
speier opened this issue Feb 5, 2015 · 10 comments
Closed

Working with Portable Class Library #100

speier opened this issue Feb 5, 2015 · 10 comments

Comments

@speier
Copy link

speier commented Feb 5, 2015

I'm trying to use your library in a Portable Class Library (Profile7) with Xamarin Studio, get the latest pre-release version 1.0.3-rc6 via Nuget, it seems installed correctly.

But when I try to call the Send method, I got the following error:

Reference to type 'System.IO.FileInfo' claims it is defined assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089', but it could not be found

Is that possible to use your library in a Portable Class Library?
Could you please help with this problem, many thanks!

@sta
Copy link
Owner

sta commented Feb 12, 2015

Hello there,

That websocket-sharp library is built with .NET Framework 3.5 as target framework. And if the Portable Class Library supports only .NET Framework 4.0 or higher, i guess you cannot use it in your Portable Class Library project.

So, if you would like to use websocket-sharp in your project, i guess you should build it with your target framework (4.0 or higher) by yourself.

@speier
Copy link
Author

speier commented Feb 12, 2015

Hi! Thanks for your feedback. I ended up using a shared project with a wrapper around your websocket-sharp library. So I can use it in my cross platform projects, while my code still based in a portable class library.

@speier speier closed this as completed Feb 12, 2015
@craigjmidwinter
Copy link

@speier-- I know this is a closed issue, but would you mind giving a brief example if you get a chance? I think I'm running into the same issue

@hopewise
Copy link

@speier @wardcraigj I have the same issue here, any link to the websocket-sharp wrapper?

@craigjmidwinter
Copy link

@hopewise, I've been a bit consumed by another project, but I got a reply on another thread about a different websocket library that will work with UWP #270 (comment)

I haven't tested it though

@hopewise
Copy link

hopewise commented Jul 3, 2016

@sta I tried to re-build your library by targeting mono / .NET 4.5, it has successfully got compiled, however when I try to add the resulted dll file to my xamarin project, I got:

Reference to type 'System.IO.FileInfo' claims it is defined assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089', but it could not be found

Any advice about building your library and use it in my xamarin project?

@wardcraigj do you have an idea about what I am missing? I still need to use this library as it has most of what I need..

@craigjmidwinter
Copy link

I'm not entirely sure. If FileInfo is the only reference to mscorlib in the library, it might be easy enough to refactor it so its not needed? I wish I could be more helpful but I really haven't poked around in the library very much so I'm not sure where or why FileInfo is used. If you do manage to compile a modified version of the library, that would be very handy!

@hopewise
Copy link

hopewise commented Jul 4, 2016

Thanks, I have finally solved the issue, simply by commenting all methods that uses FileInfo, as I am not sending files content through the socket, but only straight strings..

@rudyryk
Copy link

rudyryk commented Sep 15, 2016

I've implemented a workaround for Xamarin.Forms via the dependency service approach:

using System;
using System.Threading.Tasks;
using WebSocketSharp;
using MyProject.Shared;

[assembly: Xamarin.Forms.Dependency (typeof (WebSocketSender))]

namespace MyProject.Shared
{
    public class WebSocketSender : IWebSocketSender
    {
        /// <summary>
        /// Empty method for reference.
        /// </summary>
        public static void Init ()
        {
        }

        /// <summary>
        /// Sends the message through the specified WebSocket connection.
        /// </summary>
        public Task<bool> SendMessage (WebSocket connection, string message)
        {
            var t = new TaskCompletionSource<bool> ();

            connection.SendAsync (
                (string)message,
                (result) => t.TrySetResult (result));

            return t.Task;
        }
    }
}

@Nickolas-
Copy link

Nickolas- commented Nov 29, 2016

I forked this project and remove unnecessary Send(FileInfo) method for Xamarin PCL project.
Right now you can easily compile it for pcl and add SendAsync to return Task. Maybe someone will wants it.
https://github.com/Nickolas-/websocket-sharp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants