MonoDevelop button crash when clicked - c#

You guys have been very helpful before, therefore I ask for your assistance again.
Building a simple code. Customer plugs in information in the entries, and when they click the button, it saves in the XLS file.
public partial class MainWindow : Gtk.Window
{
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnButton2Click (object sender, System.EventArgs e)
{
ExcelFile ef = new ExcelFile();
// Loads the template file.
ef.LoadXls(#"/home/sinnich/Documents/Database.xls");
// Selects the first worksheet.
ExcelWorksheet ws = ef.Worksheets[0];
//Top informations
ws.Cells["B1"].Value = "Computer navn";
ws.Cells["C1"].Value = "Serial Nr";
ws.Cells["D1"].Value = "Låners navn";
ws.Cells["E1"].Value = "Telefon Nr";
ws.Cells["F1"].Value = "Dato for udlån";
ws.Cells["G1"].Value = "Forventet afleverings dato";
//Editable info
ws.Cells["B2"].Value = entry1;
ws.Cells["C2"].Value = entry2;
ws.Cells["D2"].Value = entry3;
ws.Cells["E2"].Value = entry4;
ws.Cells["F2"].Value = entry5;
ws.Cells["G2"].Value = entry6;
// Saves the file.
ef.SaveXls(#"/home/sinnich/Documents/Database.xls");
//Test af knappen.
label7.Text = "Overført til database";
throw new System.NotImplementedException ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
}
I get this error code when trying to run the button:
Marshaling clicked signal
Exception in Gtk# callback delegate
Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotSupportedException: Type Entry is not supported.
at GemBox.Spreadsheet.ExcelFile.a (System.Type A_0) [0x00000] in <filename unknown>:0
at GemBox.Spreadsheet.ExcelCell.set_Value (System.Object value) [0x00000] in <filename unknown>:0
at MainWindow.OnButton2Click (System.Object sender, System.EventArgs e) [0x000ba] in /home/sinnich/Projects/Rental Laptops/Rental_Laptops/MainWindow.cs:31
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <filename unknown>:0
at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0
at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0
at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000] in <filename unknown>:0
at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal)
at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data)
at Gtk.Application.gtk_main()
at Gtk.Application.Run()
at Rental_Laptops.MainClass.Main(System.String[] args) in /home/sinnich/Projects/Rental Laptops/Rental_Laptops/Main.cs:line 18
Got no clue what to do.
If I comment out the code with entry it don't crash.
Anyway how I else can get the xls files updated with editable text?

Changed the following:
ws.Cells["B2"].Value = entry1.Text;
ws.Cells["C2"].Value = entry2.Text;
ws.Cells["D2"].Value = entry3.Text;
ws.Cells["E2"].Value = entry4.Text;
ws.Cells["F2"].Value = entry5.Text;
ws.Cells["G2"].Value = entry6.Text;
Deleted the following:
throw new System.NotImplementedException ();

Related

Error In Blazor When Getting Stream of ML NET Model zip file

I have a problem with Blazor.
I tried to do what's said in the documentation about loading existing model from remote source.
(https://learn.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/save-load-machine-learning-models-ml-net)
This is what I came up with:
#page "/analyzer"
#inject HttpClient _client
<h1>Analyzer</h1>
<input class="form-control" #bind:event="oninput" #bind="InputText"/>
#if (InputText != null)
{
<h1>#InputText</h1>
}
#code {
private string _inputText, mlPrediction;
DataViewSchema modelSchema;
MLContext mlContext = new MLContext();
public string InputText
{
get
{
return _inputText;
}
set
{
_inputText = value;
GetPrediction();
}
}
private PredictionEngine<ModelInput, ModelOutput> _predictionEngine;
protected override async Task OnInitializedAsync()
{
Stream modelFile = await _client.GetStreamAsync("<MODEL.ZIP ENDPOINT>");
ITransformer trainedModel = mlContext.Model.Load(modelFile, out modelSchema);
_predictionEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(trainedModel);
}
private void GetPrediction()
{
ModelInput mlInput = new ModelInput();
mlInput.Sentiment = InputText;
ModelOutput mlOutput = _predictionEngine.Predict(mlInput);
mlPrediction = mlOutput.Prediction;
}
}
When I initialize the page, there was an error, and the only thing I understood is there is an error in line 32,
_predictionEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(trainedModel);
I could not find anyone with the same problem.
Here's the error code:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Exception has been thrown by the target of an invocation.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load the file 'Microsoft.ML.Transforms, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x296c470 + 0x000ce> in <filename unknown>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x296c470 + 0x000ce> in <filename unknown>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x296c470 + 0x000ce> in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x296c470 + 0x000f6> in <filename unknown>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) <0x296bd98 + 0x00014> in <filename unknown>:0
at Microsoft.ML.Runtime.ComponentCatalog+LoadableClassInfo.CreateInstanceCore (System.Object[] ctorArgs) <0x545e428 + 0x000dc> in <filename unknown>:0
at Microsoft.ML.Runtime.ComponentCatalog+LoadableClassInfo.CreateInstance (Microsoft.ML.Runtime.IHostEnvironment env, System.Object args, System.Object[] extra) <0x545e070 + 0x000c4> in <filename unknown>:0
at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes] (Microsoft.ML.Runtime.IHostEnvironment env, System.Type signatureType, TRes& result, System.String name, System.String options, System.Object[] extra) <0x545d848 + 0x001c8> in <filename unknown>:0
at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes,TSig] (Microsoft.ML.Runtime.IHostEnvironment env, TRes& result, System.String name, System.String options, System.Object[] extra) <0x545d488 + 0x00018> in <filename unknown>:0
at Microsoft.ML.ModelLoadContext.TryLoadModelCore[TRes,TSig] (Microsoft.ML.Runtime.IHostEnvironment env, TRes& result, System.Object[] extra) <0x5365f30 + 0x00068> in <filename unknown>:0
at Microsoft.ML.ModelLoadContext.TryLoadModel[TRes,TSig] (Microsoft.ML.Runtime.IHostEnvironment env, TRes& result, Microsoft.ML.RepositoryReader rep, Microsoft.ML.Repository+Entry ent, System.String dir, System.Object[] extra) <0x535cb38 + 0x00068> in <filename unknown>:0
at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig] (Microsoft.ML.Runtime.IHostEnvironment env, TRes& result, Microsoft.ML.RepositoryReader rep, Microsoft.ML.Repository+Entry ent, System.String dir, System.Object[] extra) <0x535c980 + 0x00038> in <filename unknown>:0
at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig] (Microsoft.ML.Runtime.IHostEnvironment env, TRes& result, Microsoft.ML.RepositoryReader rep, System.String dir, System.Object[] extra) <0x5351628 + 0x00064> in <filename unknown>:0
at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig] (Microsoft.ML.Runtime.IHostEnvironment env, TRes& result, Microsoft.ML.RepositoryReader rep, System.String dir, System.Object[] extra) <0x5351438 + 0x00034> in <filename unknown>:0
at Microsoft.ML.ModelOperationsCatalog.Load (System.IO.Stream stream, Microsoft.ML.DataViewSchema& inputSchema) <0x5243828 + 0x000a0> in <filename unknown>:0
at Deployments.Pages.SentimentAnalyzer2.OnInitializedAsync () [0x00096] in <PROJECTDIRECTORY>\Pages\SentimentAnalyzer2.razor:32
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2ecb9b0 + 0x0013a> in <filename unknown>:0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x31219d8 + 0x000b6> in <filename unknown>:0
I really have no idea what to do.
I used:
ASP.NET Core 3.1
ML.NET 1.5
.NET Standard 2.1
I found someone who seemed to have a success on similar type of project and our programs are structurally the same: https://www.luisquintanilla.me/2020/03/01/deploy-machine-learning-mlnet-models-blazor-webassembly
I hosted my ML Model both on DigitalOcean and in the wwwroot but it has the same error.
As of .NET 5 RC1 (.NET 5 or .NET 6), you can now host ML.NET machine learning models in-memory in a client-side Blazor WASM application.
My link of Blazor Server & WASM demos with ML.NET:
https://github.com/bartczernicki/Blazor-MachineIntelligence
If this is a Blazor WASM application then unfortunately ML NET is incompatible. ML NET requires a x86 which doesn't exist in WebAssembly. Therefore you must process your ML Model on the server and send the results to the client over HTTP.

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!

Reflection loading assemblies weird error (TargetInvocationException)

I tried to use this code to invoke the SpeechSynthesizer.SpeakAsync method on some string (GetVerbatim(text)):
System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom("System.Speech.dll");
System.Type type = assembly.GetType("System.Speech.Synthesizer.SpeechSynthesizer");
var methodinfo = type.GetMethod("SpeakAsync", new System.Type[] {typeof(string)} );
if (methodinfo == null) throw new System.Exception("No methodinfo.");
object[] speechparameters = new object[1];
speechparameters[0] = GetVerbatim(text); // returns something like "+100"
var o = System.Activator.CreateInstance(type);
methodinfo.Invoke(o, speechparameters);
but it is throwing this huge error:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullRe
at System.Speech.Internal.ObjectTokens.RegistryDataKey.HKEYfromRegKey (Microsoft.Win32.RegistryKey regKey) <0x43da0b0 + 0x00034> in <filename unknown>:0
at System.Speech.Internal.ObjectTokens.RegistryDataKey.RootHKEYFromRegPath (System.String rootPath) <0x43d9e08 + 0x00027> in <filename unknown>:0
at System.Speech.Internal.ObjectTokens.RegistryDataKey.Open (System.String registryPath, Boolean fCreateIfNotExist) <0x43d9bc0 + 0x0009b> in <filename unknown>:0
at System.Speech.Internal.ObjectTokens.ObjectTokenCategory.Create (System.String sCategoryId) <0x43d9b50 + 0x0001b> in <filename unknown>:0
at System.Speech.Internal.ObjectTokens.SAPICategories.DefaultDeviceOut () <0x43d9978 + 0x0002f> in <filename unknown>:0
at System.Speech.Internal.Synthesis.VoiceSynthesis..ctor (System.WeakReference speechSynthesizer) <0x43d8818 + 0x007a3> in <filename unknown>:0
at System.Speech.Synthesis.SpeechSynthesizer.get_VoiceSynthesizer () <0x43d8708 + 0x0006b> in <filename unknown>:0
at System.Speech.Synthesis.SpeechSynthesizer.SpeakAsync (System.Speech.Synthesis.Prompt prompt) <0x43d85c0 + 0x00033> in <filename unknown>:0
at System.Speech.Synthesis.SpeechSynthesizer.SpeakAsync (System.String textToSpeak) <0x43d8210 + 0x00063> in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.Cultu
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.Cultu
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) <0x188adb0 + 0x00046> in <filename unknown>:0
at ScriptLoader.Script+DMTBot.GetText (System.String text) <0x43d2128 + 0x0014f> in <filename unknown>:0
at MinecraftClient.McTcpClient.OnTextReceived (System.String text) <0x43954d0 + 0x0005e> in <filename unknown>:0

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

error when add event in MonoDevelop

when i double click on Clicked signals to add new Clicked event, it not automatic add code. it show error
i use newest version of Monodevelop and Gtk# Toolkit and Window7 platform
how to fix it ??
Try to add it manually.
Into constructor of your window class write:
yourElement.Clicked += new EventHandler(Method);
void Method(~)
{
//logic
}
Where EventHandler is a delegate type of Clicked event, and Method is a method, which have same with EventHandler signature.
This is a bug still present in MonoDevelop 3.0.1. Look below for the full stacktrace. Adding an even manually is like Arman Stepanyan described it.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotImplementedException: The requested feature is not implemented.
at MonoDevelop.Ide.TypeSystem.CodeGenerationService.GetSuitableInsertionPoint (IEnumerable`1 points, IUnresolvedTypeDefinition cls, IUnresolvedMember member) [0x0003e] in /build/buildd/monodevelop-3.0.1/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/CodeGenerationService.cs:335
at MonoDevelop.Ide.TypeSystem.CodeGenerationService.AddNewMember (ITypeDefinition type, IUnresolvedTypeDefinition part, IUnresolvedMember newMember, Boolean implementExplicit) [0x00043] in /build/buildd/monodevelop-3.0.1/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/CodeGenerationService.cs:91
at MonoDevelop.GtkCore.GuiBuilder.CodeBinder.BindSignal (Stetic.Signal signal) [0x000de] in /build/buildd/monodevelop-3.0.1/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/CodeBinder.cs:182
at MonoDevelop.GtkCore.GuiBuilder.GuiBuilderView.OnSignalAdded (System.Object sender, Stetic.ComponentSignalEventArgs args) [0x00000] in /build/buildd/monodevelop-3.0.1/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/GuiBuilderView.cs:316
at Stetic.WidgetDesigner.OnSignalAdded (System.Object sender, Stetic.ComponentSignalEventArgs args) [0x00000] in :0
at Stetic.Project+c_AnonStoreyD.<>m_17 (System.Object , System.EventArgs ) [0x00000] in :0
at Stetic.GuiDispatch.InvokeSync (System.EventHandler h) [0x00000] in :0
at Stetic.Project.NotifySignalAdded (System.Object obj, System.String name, Stetic.Signal signal) [0x00000] in :0
at (wrapper remoting-invoke-with-check) Stetic.Project:NotifySignalAdded (object,string,Stetic.Signal)
at Stetic.ProjectBackend.Stetic.IProject.NotifySignalAdded (Stetic.SignalEventArgs args) [0x00000] in :0
at Stetic.ObjectWrapper.OnSignalAdded (Stetic.SignalEventArgs args) [0x00000] in :0
at Stetic.SignalCollection.OnInsertComplete (Int32 index, System.Object value) [0x00000] in :0
at System.Collections.CollectionBase.System.Collections.IList.Add (System.Object value) [0x00000] in :0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in :0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in :0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in :0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in :0
at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] in :0
at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] in :0
at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000] in :0

Categories