mono c# strange Address already in use error - c#

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");

Related

PING ERROR C# - Parameter name: hostName

I need help.. I checking for if user of PC connected to Internet..
It works for me.. and for many people.. But for someone no
and it's writing this into output_log.txt
ERROR:
ArgumentNullException: Argument cannot be null.
Parameter name: hostName
at System.Net.Dns.GetHostByName (System.String hostName) [0x00000] in <filename unknown>:0
at System.Net.NetworkInformation.Ping.GetNonLoopbackIP () [0x00000] in <filename unknown>:0
at System.Net.NetworkInformation.Ping.SendPrivileged (System.Net.IPAddress address, Int32 timeout, System.Byte[] buffer, System.Net.NetworkInformation.PingOptions options) [0x00000] in <filename unknown>:0
at System.Net.NetworkInformation.Ping.Send (System.Net.IPAddress address, Int32 timeout, System.Byte[] buffer, System.Net.NetworkInformation.PingOptions options) [0x00000] in <filename unknown>:0
at System.Net.NetworkInformation.Ping.Send (System.String hostNameOrAddress, Int32 timeout, System.Byte[] buffer, System.Net.NetworkInformation.PingOptions options) [0x00000] in <filename unknown>:0
at System.Net.NetworkInformation.Ping.Send (System.String hostNameOrAddress, Int32 timeout, System.Byte[] buffer) [0x00000] in <filename unknown>:0
at System.Net.NetworkInformation.Ping.Send (System.String hostNameOrAddress, Int32 timeout) [0x00000] in <filename unknown>:0
at System.Net.NetworkInformation.Ping.Send (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Net.NetworkInformation.Ping:Send (string)
at Internet.Connection.Check () [0x00000] in <filename unknown>:0
at MyGame.Load.Loader.StartLoading () [0x00000] in <filename unknown>:0
at Loader+<Start>c__IteratorA.MoveNext () [0x00000] in <filename unknown>:0
(Filename: Line: -1)
Code:
namespace Internet
{
using System;
using System.Net.NetworkInformation;
using UnityEngine;
public class Connection
{
public static void Check()
{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
if (ping.Send("89.203.249.74").Status != IPStatus.Success)
{
Debug.Log("NO INTERNET CONNECTION");
Application.Quit();
}
}
}
}
So Please help

How to fix a Memory Map Failed Exception for GPIO write on raspberry pi

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.

LimitToFirst in Firebase (Unity)

Currently developing an application in Unity wherein I need to get the top 3 products that are being used. I am using the code below in retrieving data:
FirebaseDatabase.DefaultInstance
.GetReference ("Products").OrderByChild("used").LimitToFirst(3)
.ValueChanged += HandleValueChanged;
}
void HandleValueChanged(object sender, ValueChangedEventArgs args) {
if (args.DatabaseError != null) {
Debug.LogError (args.DatabaseError.Message);
return;
}
It is not working, I am receiving this error:
System.NullReferenceException: Object reference not set to an instance of an object
at ShowProducts.HandleValueChanged (System.Object sender, Firebase.Database.ValueChangedEventArgs args) [0x000be] in C:\Users\jorren\Documents\JKL\Assets\Scripts\ShowProducts.cs:697
at Firebase.Database.Internal.Core.ValueEventRegistration.FireEvent (Firebase.Database.Internal.Core.View.DataEvent eventData) [0x00000] in <filename unknown>:0
at Firebase.Database.Internal.Core.View.DataEvent.Fire () [0x00000] in <filename unknown>:0
at Firebase.Database.Internal.Core.View.EventRaiser+Runnable30.Run () [0x00000] in <filename unknown>:0
at Firebase.Database.DotNet.DotNetPlatform+SynchronizationContextTarget+<PostEvent>c__AnonStorey0.<>m__0 (System.Object x) [0x00000] in <filename unknown>:0
at Firebase.Unity.UnitySynchronizationContext+SynchronizationContextBehavoir+<Start>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0
UnityEngine.Debug:Log(Object)
Firebase.Unity.<Start>c__Iterator0:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
But when I use LimitToLast(), it is working fine
Big thanks!

MvvmCross Community SQLite plugin - NotSupportedException

I am developing a Xamarin app (currently for Android) with SQLite plugin onboard.
One of the first methods I added to work with db is following:
public ItemType FindItemById<ItemType> (int id) where ItemType : IDataItem, new()
{
return connection.Table<ItemType> ().Where (item => item.id == id).FirstOrDefault ();
}
The following exception is thrown when I call the method:
InnerException was NotSupportedException: Cannot compile: Parameter
at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].CompileExpr (System.Linq.Expressions.Expression expr, System.Collections.Generic.List`1 queryArgs) [0x00000] in <filename unknown>:0
at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].CompileExpr (System.Linq.Expressions.Expression expr, System.Collections.Generic.List`1 queryArgs) [0x00000] in <filename unknown>:0
at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].CompileExpr (System.Linq.Expressions.Expression expr, System.Collections.Generic.List`1 queryArgs) [0x00000] in <filename unknown>:0
at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].CompileExpr (System.Linq.Expressions.Expression expr, System.Collections.Generic.List`1 queryArgs) [0x00000] in <filename unknown>:0
at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].GenerateCommand (System.String selectionList) [0x00000] in <filename unknown>:0
at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].GetEnumerator () [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[Prototype.Core.Services.DataStore.Product].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[Prototype.Core.Services.DataStore.Product]..ctor (IEnumerable`1 collection) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.ToList[Product] (IEnumerable`1 source) [0x00000] in <filename unknown>:0
at Community.SQLite.TableQuery`1[Prototype.Core.Services.DataStore.Product].FirstOrDefault () [0x00000] in <filename unknown>:0
at Prototype.Core.Services.DataStore.Repository.FindItemById[Product] (Int32 id) [0x0000e] in e:\Projects\Mobile\AppMaster\crossplatform\Prototype\Prototype.Core\Services\DataStore\Repository.cs:55
at Prototype.Core.ViewModels.SingleProductViewModel.Init (Prototype.Core.ViewModels.Navigation navigation) [0x00022] in e:\Projects\Mobile\AppMaster\crossplatform\Prototype\Prototype.Core\ViewModels\SingleProductViewModel.cs:28
Could someone explain what am I doing wrong?
Added:
This has something to do with the "genericity" of this method. When I wrote it like this (usual non-generic method):
public Product FindProductById (int id)
{
return connection.Table<Product> ().Where (product => product.id == id).Select (product => product).FirstOrDefault ();
}
it started working... Could it be a bug in SQLite plugin?

ObjectDisposedException when selecting DataGridView cells?

I think I have found a bug in mono, but I have not isolated it completely, I need help to isolate my problem.
To reproduce this error
run csharp HelloWorld.cs
click any cell
modify the contents of that cell.
click on any other cell.
NOTE: I think my question is related to this question but is closer to isolating the problem.
Note: I have tried this on mono 3.0.4 and mono 3.0.1 and mono 2.10.x on linux
NOTE 2: I have also tried compiling this into a .exe and it still has the same errors
It will produce this call trace message:
System.ObjectDisposedException: The object was used after being disposed.
at System.Windows.Forms.Control.CreateHandle () [0x00000] in <filename unknown>:0
at System.Windows.Forms.TextBoxBase.CreateHandle () [0x00000] in <filename unknown>:0
at System.Windows.Forms.Control.CreateControl () [0x00000] in <filename unknown>:0
at System.Windows.Forms.Control.SetVisibleCore (Boolean value) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Control.set_Visible (Boolean value) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:set_Visible (bool)
at System.Windows.Forms.DataGridView.BeginEdit (Boolean selectAll) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore (Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridView.OnMouseDown (System.Windows.Forms.MouseEventArgs e) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Control.WmLButtonDblClick (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridView.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0
at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) [0x00000] in <filename unknown>:0
System.ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
0
at System.Collections.ArrayList.ThrowNewArgumentOutOfRangeException (System.String name, System.Object actual, System.String message) [0x00000] in <filename unknown>:0
at System.Collections.ArrayList.get_Item (Int32 index) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridViewRowCollection.SharedRow (Int32 rowIndex) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridView.GetRowInternal (Int32 rowIndex) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridView.GetCellInternal (Int32 colIndex, Int32 rowIndex) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridView.OnCellLeave (System.Windows.Forms.DataGridViewCellEventArgs e) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore (Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridView.MoveCurrentCell (Int32 x, Int32 y, Boolean select, Boolean isControl, Boolean isShift, Boolean scroll) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridView.OnColumnCollectionChanged (System.Object sender, System.ComponentModel.CollectionChangeEventArgs e) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridViewColumnCollection.OnCollectionChanged (System.ComponentModel.CollectionChangeEventArgs e) [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridViewColumnCollection.Clear () [0x00000] in <filename unknown>:0
at System.Windows.Forms.DataGridView.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0
at System.ComponentModel.Component.Dispose () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.ComponentModel.Component:Dispose ()
at System.Windows.Forms.Control.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0
at System.Windows.Forms.ContainerControl.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Form.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0
at System.ComponentModel.Component.Dispose () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.ComponentModel.Component:Dispose ()
at System.Windows.Forms.Form.WmClose (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Form.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0
at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) [0x00000] in <filename unknown>:0
contents of HelloWorld.cs:
using System.Data;
using System.Drawing;
using System.Windows.Forms;
public class HelloWorld : Form {
public HelloWorld () {
Button quit = new Button ();
quit.Text = "quit";
quit.Click += new EventHandler (OnClickQuit);
quit.Location = new Point(500, 400);
DataGridView dgv = new DataGridView();
dgv.AutoSize = true;
DataTable table1 = new DataTable("patients");
table1.Columns.Add("name");
table1.Columns.Add("id");
table1.Rows.Add("sam", 1);
table1.Rows.Add("mark", 2);
DataSet ds = new DataSet("office");
ds.Tables.Add(table1);
dgv.DataSource = ds;
dgv.DataMember = ds.Tables[0].TableName;
Controls.AddRange(new Control[] { dgv, quit });
}
void OnClickQuit(object sender, EventArgs e) {
Close();
}
}
Application.Run (new HelloWorld ());

Categories