Bug 38167 - Method 'TcpListener.Create' not found
Summary: Method 'TcpListener.Create' not found
Status: RESOLVED ANSWERED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 4.0.0
Hardware: PC All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-29 08:32 UTC by Emil Dinchev
Modified: 2016-01-29 09:28 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Emil Dinchev 2016-01-29 08:32:13 UTC
Hello,
In my code I'm using the following statement:
TcpListener tcpListener = new TcpListener(IPAddress.Any, port);

This code is called from different threads and sometimes I receive MissingMethodException with the message "Method 'TcpListener.Create' not found". First of all, I'm not using TcpListener.Create. Second: some calls do not throw this exception. I have the impression that something is not good synchronized in your libraries. Now I will try to synchronize all calls to TcpListener constructor. Please tell me, if you can find the reason for this strange behavoiur.
Comment 1 Emil Dinchev 2016-01-29 09:28:54 UTC
Hello,
I noticed that the reason for this was the JIT compiler. Actually my code was:
TcpListener tcpListener;
if (Environment.OSSystem.PlatformID == UNIX){
  // Dual sockets are still not supported by MONO.
  tcpListener = new TcpListener(IPAddress.Any, port);
}
else
{
  // From .NET 4.5 this factory method can be used.
  tcpListener = TcpListener.Create(port);
}

The code was compiled targeting .NET 4.5 and therefore I did'n notice the problem. The solution was to put the 2 branches above in 2 separate methods attributed with [MethodImpl(MethodImplOptions.NoInlining)]