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

Comapibility issue with .NET Core 2.0 Preview 2 #9

Closed
MCord opened this issue Aug 9, 2017 · 9 comments
Closed

Comapibility issue with .NET Core 2.0 Preview 2 #9

MCord opened this issue Aug 9, 2017 · 9 comments

Comments

@MCord
Copy link

MCord commented Aug 9, 2017

Hello,
Thanks for this library it saved me a lot of time!

When connecting to a samba share I get this error as soon as I call ListFiles (or any other method). This only happens with dotnetcore 2.0-preview2 and the same code works without any issue on dotnetcore 1.1

Failed to connect: [172.22.55.90]
   at SharpCifs.Smb.SmbTransport.Connect()
   at SharpCifs.Smb.SmbTree.TreeConnect(ServerMessageBlock andx, ServerMessageBlock andxResponse)
   at SharpCifs.Smb.SmbFile.DoConnect()
   at SharpCifs.Smb.SmbFile.Connect()
   at SharpCifs.Smb.SmbFile.Connect0()
   at SharpCifs.Smb.SmbFile.ResolveDfs(ServerMessageBlock request)
   at SharpCifs.Smb.SmbFile.Send(ServerMessageBlock request, ServerMessageBlock response)
   at SharpCifs.Smb.SmbFile.DoFindFirstNext(List`1 list, Boolean files, String wildcard, Int32 searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff)
   at SharpCifs.Smb.SmbFile.DoEnum(List`1 list, Boolean files, String wildcard, Int32 searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff)
   at SharpCifs.Smb.SmbFile.ListFiles(String wildcard, Int32 searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff)
   at SharpCifs.Smb.SmbFile.ListFiles(String wildcard)

I have also tried to set client IP by using

Config.SetProperty("jcifs.smb.client.laddr", ip);

but the issue persists.

Any advice?
Best Regards

@ume05rw
Copy link
Owner

ume05rw commented Aug 10, 2017

Thank you for using this!

I do not know what kind of scene it will happen, so imagine and write.
If you use it occasionally, library can not detect changes in the IP address of the device, use old IP address.

Once connected, Sharpcifs keeps holding the value of the local IP address at the time of connection.
If the address changes, try the SmbFile.Initialize();

Execution order is:
SharpCifs.Config.SetProperty ("jcifs.smb.client.laddr", [ip address]);
SmbFile.Initialize();
var smbFile = new SmbFile ("connection uri string");
var list = smbFile.listFiles();

I hope that Google Translate will show you well!

@glent1
Copy link

glent1 commented Sep 19, 2017

The problem is caused by the call to Socket.SendToAsync(args) in the Send method of SocketEx. The Completed event in SocketAsyncEventArgs never gets called, because (I am guessing) it is running synchronously as mentioned here ...

https://blogs.msdn.microsoft.com/dotnet/2017/06/07/performance-improvements-in-net-core/

I read the source of socket.cs and whilst I think the boolean that SendToAsync sets might mean it ran synchronously, I'm not sure. If it is, just doing this in SocketEx.Send will fix the issue ...

if (SendToAsync(args))
{
if (!evt.Wait(_soTimeOut))
{
throw new TimeoutException("No data sent.");
}
}

If not, replacing the whole method with this ...

public void Send(byte[] buffer, int offset, int length, EndPoint destination = null)
{
using (var evt = new ManualResetEventSlim(false))
{

            base.BeginSendTo(buffer, offset, length, SocketFlags.None, destination ?? RemoteEndPoint, new AsyncCallback(delegate { evt.Set(); }), this);
            if (!evt.Wait(_soTimeOut))
            {
                throw new TimeoutException("No data sent.");
            }
        }
    }

definitely will.

@MCord
Copy link
Author

MCord commented Sep 20, 2017

I am seeing the same behavior. You solution works perfectly. Thanks !

@ume05rw
Copy link
Owner

ume05rw commented Sep 21, 2017

Thanks for your feedbacks!

I could not reproduce in my own environment(Win10, .NetCore2.0 SDK),
"SocketAsyncEventArgs.Completed" event always raised on my code.
Please tell me about your environment.

and, fix SocketEx.cs on dev-branch:
https://github.com/ume05rw/SharpCifs.Std/blob/dev/SharpCifs.STD1.3/Util/Sharpen/SocketEx.cs

I am glad if you try this code to see if it works correctly.

@glent1
Copy link

glent1 commented Sep 22, 2017

Your environment is the same as mine. I am seeing the behaviour via a Windows .Net Core 2.0 Test Project. Interestingly, the problem does not happen in an Android deployment of the code.

Your dev-branch SocketEx fixes the problem.

I'm looking forward to you updating your nuget package so I can dispense with the local copy of the code.

By the way - thanks for this project!

@ume05rw
Copy link
Owner

ume05rw commented Sep 22, 2017

I published now, new ver 0.2.10.
https://www.nuget.org/packages/SharpCifs.Std/0.2.10

thank you everyone!

@ume05rw
Copy link
Owner

ume05rw commented Oct 4, 2017

Does anyone still have a look at this issue?
I could not reproduce this problem, so it's a bit indigestion...

If problems also occur, I will resume this issue!

@ume05rw ume05rw closed this as completed Oct 4, 2017
@MCord
Copy link
Author

MCord commented Oct 4, 2017 via email

@MCord
Copy link
Author

MCord commented Oct 8, 2017 via email

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

3 participants