I am trying to get the demo from http://www.mono-project.com/MySQL working on Ubuntu 11.10, using Mono 2.10.5.
Installed MySQL v2 drivers (after renaming) to the gac. Added provider a line to the machine.config.
Hello World demo compiles and runs fine. The following code executes and connects on MSVS fine.
The compile cmd works: mcs TestMysqlConnect.cs -r:System.Data.dll -r:/home/steve/MONO/Assemblies/Mysql/v2/MySql.Data.dll
using System;
using System.Data;
using MySql.Data.MySqlClient;
public class Test
{
public static void Main(string[] args)
{
string connectionString =
"Server=192.168.111.4;" +
"Database=LOADTRACKER;" +
"Port=3306;" +
"User ID=oec;" +
"Password=oec;" +
"Pooling=false";
Console.WriteLine("Create MySqlConnection");
IDbConnection dbcon;
dbcon = new MySqlConnection(connectionString);
Console.WriteLine("dbcon.Open();");
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
Console.WriteLine("dbcon.CreateCommand();");
// requires a table to be created named employee
// with columns firstname and lastname
// such as,
// CREATE TABLE employee (
// firstname varchar(32),
// lastname varchar(32));
string sql =
"SELECT Account, Security " +
"FROM accesslist";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
string acct = (string) reader["Account"];
string sec = (string) reader["Security"];
Console.WriteLine("Acct: " + acct + " (" + sec + ")");
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}
Executing this code produces:
$mono ./TestMysqlConnect.exe
Create MySqlConnection
dbcon.Open();
Unhandled Exception: System.OverflowException: Number overflow.
at (wrapper managed-to-native) object:__icall_wrapper_mono_array_new_specific (intptr,int)
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.HandleAuthChange (MySql.Data.MySqlClient.MySqlPacket packet) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate (Boolean reset) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.NativeDriver.Authenticate (System.String authMethod, Boolean reset) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.NativeDriver.Open () [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Driver.Open () [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.OverflowException: Number overflow.
at (wrapper managed-to-native) object:__icall_wrapper_mono_array_new_specific (intptr,int)
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.HandleAuthChange (MySql.Data.MySqlClient.MySqlPacket packet) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate (Boolean reset) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.NativeDriver.Authenticate (System.String authMethod, Boolean reset) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.NativeDriver.Open () [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Driver.Open () [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000] in <filename unknown>:0
Interestingly, if I provide a bad user/password, I get the expected exception of:
[ERROR] FATAL UNHANDLED EXCEPTION: MySql.Data.MySqlClient.MySqlException: Authentication to host '192.168.111.4' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'#'linux' (using password: YES) ---> MySql.Data.MySqlClient.MySqlException: Access denied for user 'root'#'linux' (using password: YES)
Any help is greatly appreciated. Thank you.
Related
I'm trying to use the Raspberry Sharp IO library to write to a pin on the Pi. But it gives me an exception on runtime. It had worked before, but doesnt any more. Why is this error being thrown?
using System;
using Raspberry.IO.GeneralPurpose;
using Raspberry.IO.GeneralPurpose.Behaviors;
using System.Threading;
namespace blinky
{
class MainClass
{
public static void Main (string[] args)
{
// Here we create a variable to address a specific pin for output
// There are two different ways of numbering pins--the physical numbering, and the CPU number
// "P1Pinxx" refers to the physical numbering, and ranges from P1Pin01-P1Pin40
var led1 = ConnectorPin.P1Pin03.Output();
// Here we create a connection to the pin we instantiated above
var connection = new GpioConnection(led1);
while(true){
// Toggle() switches the high/low (on/off) status of the pin
connection.Toggle(led1);
Thread.Sleep(250);
}
// connection.Close();
}
}
}
returns this error:
pi#Minion01 ~/blinky1/blinky1/bin/Debug $ mono ./blinky1.exe
Unhandled Exception:
Raspberry.IO.Interop.MemoryMapFailedException: Exception of type 'Raspberry.IO.Interop.MemoryMapFailedException' was thrown.
at Raspberry.IO.Interop.MemoryMap.ThrowOnError[MemoryMapFailedException] (IntPtr result) [0x00000] in <filename unknown>:0
at Raspberry.IO.Interop.MemoryMap.Create (IntPtr address, UInt32 size, MemoryProtection protection, MemoryFlags memoryflags, Int32 fileDescriptor, UInt32 offset) [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionDriver..ctor () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionSettings.GetBestDriver (GpioConnectionDriverCapabilities capabilities) [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionSettings.get_DefaultDriver () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionSettings..ctor () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.GpioConnectionSettings settings, IEnumerable`1 pins) [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.PinConfiguration[] pins) [0x00000] in <filename unknown>:0
at blinky.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: Raspberry.IO.Interop.MemoryMapFailedException: Exception of type 'Raspberry.IO.Interop.MemoryMapFailedException' was thrown.
at Raspberry.IO.Interop.MemoryMap.ThrowOnError[MemoryMapFailedException] (IntPtr result) [0x00000] in <filename unknown>:0
at Raspberry.IO.Interop.MemoryMap.Create (IntPtr address, UInt32 size, MemoryProtection protection, MemoryFlags memoryflags, Int32 fileDescriptor, UInt32 offset) [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionDriver..ctor () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionSettings.GetBestDriver (GpioConnectionDriverCapabilities capabilities) [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionSettings.get_DefaultDriver () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionSettings..ctor () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.GpioConnectionSettings settings, IEnumerable`1 pins) [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.PinConfiguration[] pins) [0x00000] in <filename unknown>:0
at blinky.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
How may i fix it?
I had tried to run this through monodevelop on the pi and also using mono filename.exe . Neither worked. But it did when I used sudo ./filename.exe.
I'm currently working on a project which has to run on mono.
Normally, everything works just fine. But when I try to run it in a separate screen on my ubuntu 14.04 server, it won't start after crashing once. The error that occurs is the following:
System.UriFormatException: Invalid URI: The URI scheme is not valid.
at System.Uri.Parse (UriKind kind, System.String uriString) <0x40141e70 + 0x000b3> in <filename unknown>:0
at System.Uri.ParseUri (UriKind kind) <0x40141d50 + 0x00023> in <filename unknown>:0
at System.Uri..ctor (System.String uriString, Boolean dontEscape) <0x401459e0 + 0x001b7> in <filename unknown>:0
at System.Uri..ctor (System.String uriString) <0x401459b0 + 0x00013> in <filename unknown>:0
at System.Xml.XmlResolver.ResolveUri (System.Uri baseUri, System.String relativeUri) <0x401403f0 + 0x0010b> in <filename unknown>:0
at System.Xml.XmlUrlResolver.ResolveUri (System.Uri baseUri, System.String relativeUri) <0x401403c0 + 0x00017> in <filename unknown>:0
at System.Xml.XmlTextReaderImpl..ctor (System.String uriStr, System.Xml.XmlReaderSettings settings, System.Xml.XmlParserContext context, System.Xml.XmlResolver uriResolver) <0x4013e610 + 0x00060> in <filename unknown>:0
at System.Xml.XmlReaderSettings.CreateReader (System.String inputUri, System.Xml.XmlParserContext inputContext) <0x4013e4a0 + 0x0008f> in <filename unknown>:0
at System.Xml.XmlReader.Create (System.String inputUri, System.Xml.XmlReaderSettings settings, System.Xml.XmlParserContext inputContext) <0x4013e420 + 0x0005f> in <filename unknown>:0
at System.Xml.XmlReader.Create (System.String inputUri, System.Xml.XmlReaderSettings settings) <0x4013e3c0 + 0x00013> in <filename unknown>:0
at Project.Server.Settings..ctor () <0x4013c1f0 + 0x0006f> in <filename unknown>:0
This seems very strange to me, as the code that produces the error is the following:
private XDocument configFile;
public Settings()
{
var readerSettings = new XmlReaderSettings { CheckCharacters = false };
using (var reader = XmlReader.Create("config.xml", readerSettings))
{
configFile = XDocument.Load(reader);
}
}
As mentioned before, everything works just fine when run the first time. But after it crashed once, it won't start and crashes with this error. More strangely, I can fix the problem by terminating the screen and making a new one and running the exact same command.
Has anybody encountered something like this before? Is this something that can be prevented?
The following works on vanilla .NET but throws a ReflectionTypeLoadException when I try to run it through mono:
var props = new Dictionary<string, string>();
props["CheckForSystemRuntimeDependency"] = "true";
using (var msWorkspace = MSBuildWorkspace.Create(props))
{
...
Exception is:
System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (System.Reflection.Assembly,bool)
at System.Reflection.Assembly.GetTypes () [0x00000] in :0
at System.Reflection.Assembly+<>c__Iterator0.MoveNext () [0x00000] in :0
at System.Linq.Enumerable+c__Iterator102[System.Reflection.TypeInfo,System.Type].MoveNext () [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateSelectManyIterator>c__Iterator122[System.Reflection.Assembly,System.Type].MoveNext () [0x00000] in :0
at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor (IEnumerable1 types, System.Composition.Convention.AttributedModelProvider attributeContext) [0x00000] in <filename unknown>:0
at System.Composition.Hosting.ContainerConfiguration.CreateContainer () [0x00000] in <filename unknown>:0
at Microsoft.CodeAnalysis.Host.Mef.MefHostServices.Create (IEnumerable1 assemblies) [0x00000] in :0
at Microsoft.CodeAnalysis.Host.Mef.DesktopMefHostServices.get_DefaultServices () [0x00000] in :0
at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create (IDictionary`2 properties) [0x00000] in :0
...
Is this a known problem?
For me it helped to manually add all Linq.* libraries to the Project
I had to change the auth system behind the Google Analytics API following the old auth system becoming defunct. As a result of a SO post, my auth file went from:
protected override void Load(ContainerBuilder builder)
{
builder.Register(c =>
{
var service = new AnalyticsService("mrfreeman.com");
service.setUserCredentials("robot#mrfreeman.com", "jellyfish");
return service;
});
builder.RegisterType<AnalyticsNewsletterTrackingSource>().As<INewsletterTrackingSource>();
builder.RegisterType<AnalyticsSearchTrackingSource>().As<ISearchTrackingSource>();
builder.RegisterType<AnalyticsEmailLinkTracker>().As<IEmailLinkTracker>();
}
To:
private const string ServiceAccountEmail = "blabla#developer.gserviceaccount.com";
private static readonly string KeyPath = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.PrivateBinPath ?? AppDomain.CurrentDomain.BaseDirectory, "Key.p12");
private static readonly X509Certificate2 Certificate = new X509Certificate2(KeyPath, "notasecret", X509KeyStorageFlags.Exportable);
private readonly ServiceAccountCredential _credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(ServiceAccountEmail)
{
Scopes = new[] { "https://www.googleapis.com/auth/analytics" }
}.FromCertificate(Certificate));
protected override void Load(ContainerBuilder builder)
{
builder.Register(c =>
{
_credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Wait();
var service = new AnalyticsService("mrfreeman.com");
var requestFactory = new GDataRequestFactory("shazbot2.0");
requestFactory.CustomHeaders.Add(string.Format("Authorization: Bearer {0}", _credential.Token.AccessToken));
service.RequestFactory = requestFactory;
return service;
});
builder.RegisterType<AnalyticsNewsletterTrackingSource>().As<INewsletterTrackingSource>();
builder.RegisterType<AnalyticsSearchTrackingSource>().As<ISearchTrackingSource>();
builder.RegisterType<AnalyticsEmailLinkTracker>().As<IEmailLinkTracker>();
}
Doing all the necessary boiler plate of copying the generated developer email address and P12 key into the project.
The problem is this: It works on Windows but throws problems with the services running on mono and are dependant on the Analytics module. Currently using 4.0.2 version of Mono.
What I've tried:
Using old and new versions of mono - 3.10 and 4.2.0 pre-release to run the service (which is itself built by Visual Studio) and check if exception is produced.
Import System.Net.Http and copy to local (currently not referenced in service) - still produces same exception
At this stage I'm cornered into learning the new Google Analytics API and re-writing everything from scratch as I tried to use the old API but update the Auth API with little luck, but feel this a blunt-instrument type solution.
The stack trace is the same on any version and is:
FATAL Unhandled exception occurred.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Invalid IL code in System.Net.Http.HttpClientHandler:.ctor (): method body is empty.
at Google.Apis.Http.HttpClientFactory.CreateHandler (Google.Apis.Http.CreateHttpClientArgs args) <0x40280100 + 0x0003b> in <filename unknown>:0
at Google.Apis.Http.HttpClientFactory.CreateHttpClient (Google.Apis.Http.CreateHttpClientArgs args) <0x4027ff90 + 0x0002d> in <filename unknown>:0
at Google.Apis.Auth.OAuth2.ServiceAccountCredential..ctor (Google.Apis.Auth.OAuth2.Initializer initializer) <0x4027f6d0 + 0x00438> in <filename unknown>:0
at jellyfish.Analytics.AnalyticsModule..ctor () <0x4027ed00 + 0x00103> in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) <0x7f8257b94780 + 0x0003f> in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) <0x7f8257b94780 + 0x00079> in <filename unknown>:0
at System.RuntimeType.CreateInstanceMono (Boolean nonPublic) <0x7f82579c1ec0 + 0x00116> in <filename unknown>:0
at System.RuntimeType.CreateInstanceSlow (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) <0x7f82579c1e70 + 0x00049> in <filename unknown>:0
at System.RuntimeType.CreateInstanceDefaultCtor (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) <0x7f82579c1c10 + 0x0005c> in <filename unknown>:0
at System.Activator.CreateInstance[T] () <0x7f82578dfb70 + 0x0008a> in <filename unknown>:0
at Autofac.ModuleRegistrationExtensions.RegisterModule[TModule] (IModuleRegistrar registrar) <0x40273470 + 0x0004f> in <filename unknown>:0
at Autofac.ModuleRegistrationExtensions.RegisterModule[TModule] (Autofac.ContainerBuilder builder) <0x40273330 + 0x0006b> in <filename unknown>:0
at jellyfish.Cron.Program.BuildContainer (ILog log) <0x402730e0 + 0x0005f> in <filename unknown>:0
at jellyfish.Cron.Program.ExecuteJob (System.Type jobType) <0x4021abe0 + 0x0007b> in <filename unknown>:0
Unknown errno: Protocol error
Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Invalid IL code in System.Net.Http.HttpClientHandler:.ctor (): method body is empty.
at Google.Apis.Http.HttpClientFactory.CreateHandler (Google.Apis.Http.CreateHttpClientArgs args) <0x40280100 + 0x0003b> in <filename unknown>:0
at Google.Apis.Http.HttpClientFactory.CreateHttpClient (Google.Apis.Http.CreateHttpClientArgs args) <0x4027ff90 + 0x0002d> in <filename unknown>:0
at Google.Apis.Auth.OAuth2.ServiceAccountCredential..ctor (Google.Apis.Auth.OAuth2.Initializer initializer) <0x4027f6d0 + 0x00438> in <filename unknown>:0
at jellyfish.Analytics.AnalyticsModule..ctor () <0x4027ed00 + 0x00103> in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) <0x7f8257b94780 + 0x0003f> in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) <0x7f8257b94780 + 0x00079> in <filename unknown>:0
at System.RuntimeType.CreateInstanceMono (Boolean nonPublic) <0x7f82579c1ec0 + 0x00116> in <filename unknown>:0
at System.RuntimeType.CreateInstanceSlow (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) <0x7f82579c1e70 + 0x00049> in <filename unknown>:0
at System.RuntimeType.CreateInstanceDefaultCtor (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) <0x7f82579c1c10 + 0x0005c> in <filename unknown>:0
at System.Activator.CreateInstance[T] () <0x7f82578dfb70 + 0x0008a> in <filename unknown>:0
at Autofac.ModuleRegistrationExtensions.RegisterModule[TModule] (IModuleRegistrar registrar) <0x40273470 + 0x0004f> in <filename unknown>:0
at Autofac.ModuleRegistrationExtensions.RegisterModule[TModule] (Autofac.ContainerBuilder builder) <0x40273330 + 0x0006b> in <filename unknown>:0
at jellyfish.Cron.Program.BuildContainer (ILog log) <0x402730e0 + 0x0005f> in <filename unknown>:0
at jellyfish.Cron.Program.ExecuteJob (System.Type jobType) <0x4021abe0 + 0x0007b> in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Invalid IL code in System.Net.Http.HttpClientHandler:.ctor (): method body is empty.
at Google.Apis.Http.HttpClientFactory.CreateHandler (Google.Apis.Http.CreateHttpClientArgs args) <0x40280100 + 0x0003b> in <filename unknown>:0
at Google.Apis.Http.HttpClientFactory.CreateHttpClient (Google.Apis.Http.CreateHttpClientArgs args) <0x4027ff90 + 0x0002d> in <filename unknown>:0
at Google.Apis.Auth.OAuth2.ServiceAccountCredential..ctor (Google.Apis.Auth.OAuth2.Initializer initializer) <0x4027f6d0 + 0x00438> in <filename unknown>:0
at jellyfish.Analytics.AnalyticsModule..ctor () <0x4027ed00 + 0x00103> in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) <0x7f8257b94780 + 0x0003f> in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) <0x7f8257b94780 + 0x00079> in <filename unknown>:0
at System.RuntimeType.CreateInstanceMono (Boolean nonPublic) <0x7f82579c1ec0 + 0x00116> in <filename unknown>:0
at System.RuntimeType.CreateInstanceSlow (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) <0x7f82579c1e70 + 0x00049> in <filename unknown>:0
at System.RuntimeType.CreateInstanceDefaultCtor (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) <0x7f82579c1c10 + 0x0005c> in <filename unknown>:0
at System.Activator.CreateInstance[T] () <0x7f82578dfb70 + 0x0008a> in <filename unknown>:0
at Autofac.ModuleRegistrationExtensions.RegisterModule[TModule] (IModuleRegistrar registrar) <0x40273470 + 0x0004f> in <filename unknown>:0
at Autofac.ModuleRegistrationExtensions.RegisterModule[TModule] (Autofac.ContainerBuilder builder) <0x40273330 + 0x0006b> in <filename unknown>:0
at jellyfish.Cron.Program.BuildContainer (ILog log) <0x402730e0 + 0x0005f> in <filename unknown>:0
at jellyfish.Cron.Program.ExecuteJob (System.Type jobType) <0x4021abe0 + 0x0007b> in <filename unknown>:0
I was having similar issue, So thought try removing and adding the following DLLS to fix it.
Removed System.net.http, OkHttp, ModernClient. Found the issue was with ModernClientHttp and OkHttp dlls added under references.
I have removed OkHttp and ModernClientHttp and added the ModernClientHttp via Nuget and that works for me.
Give a try if that helps.
Its my first time using mono, I have compiled some ready code and tried to use on my linux host yet i get strange error. I am not really experienced with C# like experts but i can manage code.
I forgot to mention, there isnt any single app using port 5031. I even changed port to random numbers yet it still gives same error.
Unhandled Exception:
System.Net.Sockets.SocketException: Address already in use
at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpListener.Start (Int32 backlog) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpListener.Start () [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.NetTcp.TcpChannelListener`1[System.ServiceModel.Channels.IDuplexSessionChannel].OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.ListenerLoopManager.Setup (TimeSpan openTimeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.ServiceHostBase.OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open () [0x00000] in <filename unknown>:0
at H_Auth.AuthSvc.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException: Address already in use
at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpListener.Start (Int32 backlog) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpListener.Start () [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.NetTcp.TcpChannelListener`1[System.ServiceModel.Channels.IDuplexSessionChannel].OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.ListenerLoopManager.Setup (TimeSpan openTimeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.ServiceHostBase.OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open () [0x00000] in <filename unknown>:0
at H_Auth.AuthSvc.Main (System.String[] args) [0x00000] in <filename unknown>:0
and this is my code
namespace H_Auth
{
internal class AuthSvc
{
private static void Main(string[] args)
{
var adrs = new Uri[1];
adrs[0] = new Uri("net.tcp://localhost:5031/");
using (ServiceHost serviceHost = new ServiceHost(typeof (HBChannel), adrs))
{
try
{
serviceHost.AddServiceEndpoint(typeof (IA), (System.ServiceModel.Channels.Binding) new NetTcpBinding(SecurityMode.None), "Auth.svc");
ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
serviceHost.Description.Behaviors.Add((IServiceBehavior) metadataBehavior);
((ServiceHostBase) serviceHost).AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
serviceHost.Open();
string str = Regex.Match(((AssemblyFileVersionAttribute) Assembly.GetEntryAssembly().GetCustomAttributes(typeof (AssemblyFileVersionAttribute), false)[0]).Version, "^\\d+\\.\\d+").Value;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Revision " + str + "\r\n");
Console.ResetColor();
Console.WriteLine("press \"S\" for stats print");
Console.WriteLine();
ConsoleKeyInfo consoleKeyInfo = new ConsoleKeyInfo();
while (consoleKeyInfo.Key != ConsoleKey.Enter)
{
consoleKeyInfo = Console.ReadKey(true);
if (consoleKeyInfo.Key == ConsoleKey.S)
{
AuthImpl.Instance.RemoveExpiredSessions();
AuthSvc.PrintStats(AuthImpl.Instance.GetSessions);
}
}
serviceHost.Close();
}
catch (CommunicationException ex)
{
Logging.Ex(ex.Message);
serviceHost.Abort();
}
}
Console.ReadLine();
}
private static void PrintStats(List<SessInfo> Sessions)
{
Console.WriteLine("Current active sessions:");
Dictionary<string, int> dictionary1 = new Dictionary<string, int>();
foreach (SessInfo sessInfo in Sessions)
{
if (!dictionary1.ContainsKey(sessInfo.BotSignature))
{
dictionary1.Add(sessInfo.BotSignature, 1);
}
else
{
Dictionary<string, int> dictionary2;
string botSignature;
(dictionary2 = dictionary1)[botSignature = sessInfo.BotSignature] = dictionary2[botSignature] + 1;
}
}
if (dictionary1.Count > 0)
{
foreach (KeyValuePair<string, int> keyValuePair in dictionary1)
Console.WriteLine(string.Format("'{0}': {1} user {2}", (object) keyValuePair.Key, (object) keyValuePair.Value, keyValuePair.Value > 1 ? (object) "S" : (object) ""));
}
else
Console.WriteLine("There is no active sessions");
}
}
}
I had the same problem and I've figured it out.
My problem (and maybe yours) was that I was using the same base port for different endpoints.
Notice that, it works for Windows, but not for Linux:
var host = new ServiceHost(typeof(MyService), new Uri("net.tcp://localhost:10500/UCB"));
host.AddServiceEndpoint(typeof(IService1), CreateTcpBinding(), "IService1");
host.AddServiceEndpoint(typeof(IService2), CreateTcpBinding(), "IService2");
This will create the following:
net.tcp://localhost:10500/UCB/IService1
net.tcp://localhost:10500/UCB/IService2
It works on Windows, but not on Linux, something to do with port-sharing.
In order to work on Linux, we need to have different ports, like:
net.tcp://localhost:10500/UCB/IService1
net.tcp://localhost:10501/UCB/IService2
Working code:
var host = new ServiceHost(typeof(MyService), new Uri("net.tcp://localhost"));
host.AddServiceEndpoint(typeof(IService1), CreateTcpBinding(), "net.tcp://localhost:10500/UCB/IService1");
host.AddServiceEndpoint(typeof(IService2), CreateTcpBinding(), "net.tcp://localhost:10501/UCB/IService2");