Reflection loading assemblies weird error (TargetInvocationException) - c#

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

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.

Google API-change, results in a MONO error: Invalid IL code in System.Net.Http.HttpClientHandler:.ctor (): method body is empty

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.

System.TypeLoadException when I try to convert JArray to an object in a thread

I have a C# code that converts a JArray object jsonArray (JSON.Net) to a list of objects jsonList (List< MyClass >):
List<MyClass> jsonList = jsonArray.ToObject<List<MyClass>> ();
The code above works fine when I run it on the main thread, but if I put the same code inside a different thread, like this:
Thread t = new Thread(delegate() {
List<MyClass> jsonList = jsonArray.ToObject<List<MyClass>> ();
});
t.Start();
I get the following error message: "System.TypeLoadException has been thrown. A type load exception has occurred".
Does anybody have any idea why this is happening? The full stack trace is below. Thanks in advance!
System.TypeLoadException: A type load exception has occurred. at
Newtonsoft.Json.Utilities.ThreadSafeStore2[System.Type,System.Type].AddValue
(System.Type key) [0x00000] in <filename unknown>:0 at
Newtonsoft.Json.Utilities.ThreadSafeStore2[System.Type,System.Type].Get
(System.Type key) [0x00000] in :0 at
Newtonsoft.Json.Serialization.JsonTypeReflector.GetAssociatedMetadataType
(System.Type type) [0x00000] in :0 at
Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute]
(System.Type type) [0x00000] in :0 at
Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute]
(ICustomAttributeProvider attributeProvider) [0x00000] in :0 at
Newtonsoft.Json.Utilities.ThreadSafeStore2[System.Reflection.ICustomAttributeProvider,Newtonsoft.Json.JsonContainerAttribute].AddValue
(ICustomAttributeProvider key) [0x00000] in <filename unknown>:0 at
Newtonsoft.Json.Utilities.ThreadSafeStore2[System.Reflection.ICustomAttributeProvider,Newtonsoft.Json.JsonContainerAttribute].Get
(ICustomAttributeProvider key) [0x00000] in :0 at
Newtonsoft.Json.Serialization.CachedAttributeGetter1[Newtonsoft.Json.JsonContainerAttribute].GetAttribute
(ICustomAttributeProvider type) [0x00000] in <filename unknown>:0 at
Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonContainerAttribute
(System.Type type) [0x00000] in <filename unknown>:0 at
Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonObjectAttribute
(System.Type type) [0x00000] in <filename unknown>:0 at
Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract
(System.Type objectType) [0x00000] in <filename unknown>:0 at
Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract
(System.Type type) [0x00000] in <filename unknown>:0 at
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.GetContractSafe
(System.Type type) [0x00000] in <filename unknown>:0 at
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize
(Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean
checkAdditionalContent) [0x00000] in <filename unknown>:0 at
Newtonsoft.Json.JsonSerializer.DeserializeInternal
(Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000]
in <filename unknown>:0 at
Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader
reader, System.Type objectType) [0x00000] in <filename unknown>:0 at
Newtonsoft.Json.Linq.JToken.ToObject (System.Type objectType,
Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in <filename
unknown>:0 at Newtonsoft.Json.Linq.JToken.ToObject (System.Type
objectType, Boolean isNullable) [0x00000] in <filename unknown>:0 at
Newtonsoft.Json.Linq.JToken.ToObject (System.Type objectType)
[0x00000] in <filename unknown>:0 at
Newtonsoft.Json.Linq.JToken.ToObject[List1] () [0x00000] in :0 at GuiaTV.AgoraController.GetJSON () [0x00015] in
/Users/vegidio/Documents/Dev/Xamarin/GuiaTV/GuiaTV/Controllers/AgoraController.cs:24
at GuiaTV.AgoraScreen.m__2 () [0x0000d] in
/Users/vegidio/Documents/Dev/Xamarin/GuiaTV/GuiaTV/Views/AgoraScreen.cs:43
at System.Threading.Thread.StartInternal () [0x0001d] in
/Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/Thread.cs:697
It seems you are developing a touch based applicationfor this you need the latest edition of NewtonSoft for Mono Touch.Get it from here.
If you are building it for a modern UI its very easy follow the Win 8 templates or use a Task to initiate the thread.
Try putting in a Try,Catch,Finally block to get the exception details.
If you set a breakpoint on
List<MyClass> jsonList = jsonArray.ToObject<List<MyClass>> ();
and hover that breakpoint to look at the inner exception, what does it say?
The reason I ask is because a TypeLoad exception will either throw a null or give you a message on the inner exception that could help you a little more than this stack trace.

MonoDevelop button crash when clicked

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

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