Can't get Razor MVC to work on Mono - c#

I'm running through the tutorial here to build an ASP.NET MVC website: http://www.asp.net/mvc/overview/getting-started/introduction/adding-a-view. I'm not using MSVC, but MonoDevelop, as I'm on a Linux system.
I'm running into some issues when I tried to add a Razor view to My HelloWorld Controller's Index function. Right now, the code for Views/HelloWorld/Index.cshtml is this:
<h2>Index</h2>
<p>Hello from our View Template!</p>
The code for Controllers/HelloWorldController.cs's Index() function is this:
// GET: /HelloWorld/
public ActionResult Index()
{
return View();
}
But when I go to http://127.0.0.1:8080/HelloWorld/, I'm gettng a 500 error. It's returning this information:
System.InvalidOperationException
Could not locate Razor Host Factory type: System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): System.Web.WebPages.Razor.
Exception Stack Trace:
at System.Web.WebPages.Razor.WebRazorHostFactory.CreateFactory (System.String typeName) [0x00030] in <filename unknown>:0
at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (System.Collections.Concurrent.TKey key, System.Func`2 valueFactory) [0x00037] in <filename unknown>:0
at System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfigCore (System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup config, System.String virtualPath, System.String physicalPath) [0x0004f] in <filename unknown>:0
at System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig (System.String virtualPath, System.String physicalPath) [0x00038] in <filename unknown>:0
at System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig (System.String virtualPath) [0x00000] in <filename unknown>:0
at System.Web.WebPages.Razor.RazorBuildProvider.GetHostFromConfig () [0x00006] in <filename unknown>:0
at System.Web.WebPages.Razor.RazorBuildProvider.CreateHost () [0x00000] in <filename unknown>:0
at System.Web.WebPages.Razor.RazorBuildProvider.get_Host () [0x00008] in <filename unknown>:0
at System.Web.WebPages.Razor.RazorBuildProvider.EnsureGeneratedCode () [0x00008] in <filename unknown>:0
at System.Web.WebPages.Razor.RazorBuildProvider.get_CodeCompilerType () [0x00000] in <filename unknown>:0
at System.Web.Compilation.BuildManagerDirectoryBuilder.GetBuildProviderCodeDomType (System.Web.Compilation.BuildProvider bp) [0x00000] in <filename unknown>:0
at System.Web.Compilation.BuildManagerDirectoryBuilder.AssignToGroup (System.Web.Compilation.BuildProvider buildProvider, System.Collections.Generic.List`1 groups) [0x0007a] in <filename unknown>:0
at System.Web.Compilation.BuildManagerDirectoryBuilder.Build (Boolean single) [0x00151] in <filename unknown>:0
at System.Web.Compilation.BuildManager.BuildInner (System.Web.VirtualPath vp, Boolean debug) [0x00019] in <filename unknown>:0
at System.Web.Compilation.BuildManager.Build (System.Web.VirtualPath vp) [0x00063] in <filename unknown>:0
at System.Web.Compilation.BuildManager.GetCompiledType (System.Web.VirtualPath virtualPath) [0x00040] in <filename unknown>:0
at System.Web.Compilation.BuildManager.GetCompiledType (System.String virtualPath) [0x00006] in <filename unknown>:0
at System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.GetCompiledType (System.String virtualPath) [0x00000] in <filename unknown>:0
at System.Web.Mvc.BuildManagerCompiledView.Render (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer) [0x0001c] in <filename unknown>:0
at System.Web.Mvc.ViewResultBase.ExecuteResult (System.Web.Mvc.ControllerContext context) [0x00080] in <filename unknown>:0
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in <filename unknown>:0
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (IList`1 filters, Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x0000b] in <filename unknown>:0
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (IList`1 filters, Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x0004f] in <filename unknown>:0

In my Web.config file, I had to set <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc...'s version tag from 5.2.0.0 to 5.2.3.0 to match my NuGet package version.

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 is ording a List of objects handled with Linq and or Sort?

Sorry if this is a duplicate. I'm having a hard time finding an answer because I get so much bloat of people asking how to sort lists in general in my search results.
Say I have a property like this:
public List<object> Hello { get; set; }
Say each element in the list is of the same nullable primitive data type.
So every element is a int? or every element is a decimal? or every element is a DateTime?, etc
What exactly happens if I invoke a Sort or OrderBy on this list? Does it sort based on the underlying type of each element or does it order by the string value of the property?
Let's check http://ideone.com/kcXmHE:
System.ArgumentException: Value does not fall within the expected range.
at System.String.CompareTo (System.Object value) [0x00000] in <filename unknown>:0
at System.Collections.Generic.Comparer`1+DefaultComparer[System.Object].Compare (System.Object x, System.Object y) [0x00000] in <filename unknown>:0
at System.Linq.SortSequenceContext`2[System.Object,System.Object].Compare (Int32 first_index, Int32 second_index) [0x00000] in <filename unknown>:0
at System.Array.qsort[Int32] (System.Int32[] keys, Int32 low0, Int32 high0, IComparer`1 comparer) [0x00000] in <filename unknown>:0
at System.Array.SortImpl[Int32] (System.Int32[] keys, Int32 index, Int32 length, IComparer`1 comparer) [0x00000] in <filename unknown>:0
at System.Array.Sort[Int32] (System.Int32[] array, IComparer`1 comparer) [0x00000] in <filename unknown>:0
at System.Linq.QuickSort`1[System.Object].PerformSort () [0x00000] in <filename unknown>:0
at System.Linq.QuickSort`1+<Sort>c__Iterator0[System.Object].MoveNext () [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[System.Object]..ctor (IEnumerable`1 collection) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.ToList[Object] (IEnumerable`1 source) [0x00000] in <filename unknown>:0
at Test.Main () [0x00000] in <filename unknown>:0
So, LINQ uses default comparer for element of list (for string value you can see System.String.CompareTo) and tries to compare with another value (of object type). And, can't do it.
If you change order of elements in initial list (http://ideone.com/foljli), you will get another stack trace:
System.ArgumentException: Object must be of type Int32.
at System.Int32.CompareTo (System.Object value) [0x00000] in <filename unknown>:0
at System.Collections.Generic.Comparer`1+DefaultComparer[System.Object].Compare (System.Object x, System.Object y) [0x00000] in <filename unknown>:0
at System.Linq.SortSequenceContext`2[System.Object,System.Object].Compare (Int32 first_index, Int32 second_index) [0x00000] in <filename unknown>:0
at System.Array.qsort[Int32] (System.Int32[] keys, Int32 low0, Int32 high0, IComparer`1 comparer) [0x00000] in <filename unknown>:0
at System.Array.SortImpl[Int32] (System.Int32[] keys, Int32 index, Int32 length, IComparer`1 comparer) [0x00000] in <filename unknown>:0
at System.Array.Sort[Int32] (System.Int32[] array, IComparer`1 comparer) [0x00000] in <filename unknown>:0
at System.Linq.QuickSort`1[System.Object].PerformSort () [0x00000] in <filename unknown>:0
at System.Linq.QuickSort`1+<Sort>c__Iterator0[System.Object].MoveNext () [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[System.Object]..ctor (IEnumerable`1 collection) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.ToList[Object] (IEnumerable`1 source) [0x00000] in <filename unknown>:0
at Test.Main () [0x00000] in <filename unknown>:0
Now, LINQ takes int32 and tries to compare with object. And fail again. Because int32 type has no method CompareTo(object)

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?

Exception thrown when using Mono+Aspose.Words running on ubuntu

I'm using Aspose.Words to convert a doc/docx file to a pdf file on ubuntu. Mono runtime has been installed. My code is below:
Document doc = new Document ("/data/upfile/test.docx");
doc.Save ("/data/upfile/test.pdf", SaveFormat.Pdf);
Somehow, when the second line of the code is executed, an error was thrown. The detail is below:
Unhandled Exception: System.ArgumentOutOfRangeException: startIndex +
length > this.length Parameter name: length at
System.String.Substring (Int32 startIndex, Int32 length) [0x00000] in
:0 at
x6c95d9cf46ff5f25.x0d299f323d241756.x3b67e683e83cab62 (System.String
xe4115acdf4fbfccc, Int32 x961016a387451f05) [0x00000] in :0 at x4adf554d20d941a6.x50e6e6d123fa4a35.x4469479613bec4d8
(Aspose.Words.Node xda5bf54deb817e37) [0x00000] in :0 at x4adf554d20d941a6.x50e6e6d123fa4a35.x7be41bff00df2c71
(Aspose.Words.Node xda5bf54deb817e37) [0x00000] in :0 at x4adf554d20d941a6.x50e6e6d123fa4a35.x699caa1974f95d1a
(Aspose.Words.Node xda5bf54deb817e37) [0x00000] in :0 at x4adf554d20d941a6.x50e6e6d123fa4a35.x21e4bd206d6231f8
(System.Object xa860e35844c20ac7) [0x00000] in :0
at x4adf554d20d941a6.x50e6e6d123fa4a35.xb5ef8a04e65b87e6
(System.String x1f25abf5fb75e795, System.Object xa860e35844c20ac7)
[0x00000] in :0 at
x59d6a4fc5007b7a4.xdeb77ea37ad74c56.xbbf9a1ead81dd3a1 (System.String
x1f25abf5fb75e795, System.Object xa860e35844c20ac7) [0x00000] in
:0 at
x59d6a4fc5007b7a4.x487cdc969fefe3d6.xbbf9a1ead81dd3a1 (System.String
x1f25abf5fb75e795, System.Object xa860e35844c20ac7) [0x00000] in
:0 at
x59d6a4fc5007b7a4.x487cdc969fefe3d6.xf3a1cfbffa44728c () [0x00000] in
:0 at
x59d6a4fc5007b7a4.x487cdc969fefe3d6.x47f176deff0d42e2 () [0x00000] in
:0 at
x59d6a4fc5007b7a4.x487cdc969fefe3d6.x83f07df6a659e05b () [0x00000] in
:0 at
x59d6a4fc5007b7a4.xcde671c53995c411.xd9db07500873ae98
(Aspose.Words.Document x3664041d21d73fdc,
x59d6a4fc5007b7a4.xdeb77ea37ad74c56 xdfde339da46db651) [0x00000] in
:0 at Aspose.Words.Document.UpdatePageLayout ()
[0x00000] in :0 at
Aspose.Words.Document.x410db0f4a89a6ef1 (Boolean x24af0daafcd8fb8c)
[0x00000] in :0 at
Aspose.Words.Document.get_xcde671c53995c411 () [0x00000] in :0 at Aspose.Words.Document.get_PageCount () [0x00000] in
:0 at
xf989f31a236ff98c.x6c74398bceb133f8.xa2e0b7f7da663553
(x28925c9b27b37a46.x8556eed81191af11 x5ac1382edb7bf2c2) [0x00000] in
:0 at Aspose.Words.Document.xf381a641001e6830
(System.IO.Stream xcf18e5243f8d5fd3, System.String xafe2f3653ee64ebc,
Aspose.Words.Saving.SaveOptions xc27f01f21f67608c) [0x00000] in
:0 at Aspose.Words.Document.Save (System.String
fileName, Aspose.Words.Saving.SaveOptions saveOptions) [0x00000] in
:0 at Aspose.Words.Document.Save (System.String
fileName, SaveFormat saveFormat) [0x00000] in :0
at MonoTest.MainClass.Main (System.String[] args) [0x00000] in
:0 [ERROR] FATAL UNHANDLED EXCEPTION:
System.ArgumentOutOfRangeException: startIndex + length > this.length
Parameter name: length at System.String.Substring (Int32 startIndex,
Int32 length) [0x00000] in :0 at
x6c95d9cf46ff5f25.x0d299f323d241756.x3b67e683e83cab62 (System.String
xe4115acdf4fbfccc, Int32 x961016a387451f05) [0x00000] in :0 at x4adf554d20d941a6.x50e6e6d123fa4a35.x4469479613bec4d8
(Aspose.Words.Node xda5bf54deb817e37) [0x00000] in :0 at x4adf554d20d941a6.x50e6e6d123fa4a35.x7be41bff00df2c71
(Aspose.Words.Node xda5bf54deb817e37) [0x00000] in :0 at x4adf554d20d941a6.x50e6e6d123fa4a35.x699caa1974f95d1a
(Aspose.Words.Node xda5bf54deb817e37) [0x00000] in :0 at x4adf554d20d941a6.x50e6e6d123fa4a35.x21e4bd206d6231f8
(System.Object xa860e35844c20ac7) [0x00000] in :0
at x4adf554d20d941a6.x50e6e6d123fa4a35.xb5ef8a04e65b87e6
(System.String x1f25abf5fb75e795, System.Object xa860e35844c20ac7)
[0x00000] in :0 at
x59d6a4fc5007b7a4.xdeb77ea37ad74c56.xbbf9a1ead81dd3a1 (System.String
x1f25abf5fb75e795, System.Object xa860e35844c20ac7) [0x00000] in
:0 at
x59d6a4fc5007b7a4.x487cdc969fefe3d6.xbbf9a1ead81dd3a1 (System.String
x1f25abf5fb75e795, System.Object xa860e35844c20ac7) [0x00000] in
:0 at
x59d6a4fc5007b7a4.x487cdc969fefe3d6.xf3a1cfbffa44728c () [0x00000] in
:0 at
x59d6a4fc5007b7a4.x487cdc969fefe3d6.x47f176deff0d42e2 () [0x00000] in
:0 at
x59d6a4fc5007b7a4.x487cdc969fefe3d6.x83f07df6a659e05b () [0x00000] in
:0 at
x59d6a4fc5007b7a4.xcde671c53995c411.xd9db07500873ae98
(Aspose.Words.Document x3664041d21d73fdc,
x59d6a4fc5007b7a4.xdeb77ea37ad74c56 xdfde339da46db651) [0x00000] in
:0 at Aspose.Words.Document.UpdatePageLayout ()
[0x00000] in :0 at
Aspose.Words.Document.x410db0f4a89a6ef1 (Boolean x24af0daafcd8fb8c)
[0x00000] in :0 at
Aspose.Words.Document.get_xcde671c53995c411 () [0x00000] in :0 at Aspose.Words.Document.get_PageCount () [0x00000] in
:0 at
xf989f31a236ff98c.x6c74398bceb133f8.xa2e0b7f7da663553
(x28925c9b27b37a46.x8556eed81191af11 x5ac1382edb7bf2c2) [0x00000] in
:0 at Aspose.Words.Document.xf381a641001e6830
(System.IO.Stream xcf18e5243f8d5fd3, System.String xafe2f3653ee64ebc,
Aspose.Words.Saving.SaveOptions xc27f01f21f67608c) [0x00000] in
:0 at Aspose.Words.Document.Save (System.String
fileName, Aspose.Words.Saving.SaveOptions saveOptions) [0x00000] in
:0 at Aspose.Words.Document.Save (System.String
fileName, SaveFormat saveFormat) [0x00000] in :0
at MonoTest.MainClass.Main (System.String[] args) [0x00000] in
:0
Any advice is appreciated. Thanks.
Often inner exceptions is a very common problem for converting words documents in PDF via Aspose.
It can be due to some reasones like:
2013 MS Word office.
Some complex elements in word
Old version of Aspose.Words.dll.
Solutions:
Try to update Aspose.Words.dll to new version. If it's still not working - write to aspose forum, and this error will be fixed in new release.
Check word document itself. may be you can find something thac call this inner exception, than try to remove it and check again. If this is acceptable of course.

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