I have been embedding mono in a basic c++ application, and have run into an issue with printing any numbers but 0 from the c# script causes my c++ program to crash
I created the following c# code
using System;
using Arc.Entity;
namespace ExampleApp
{
public class PlayerMovement : Entity
{
public void Start()
{
float test = 1.0f;
Console.WriteLine("Hello Start Method: {0}", test);
}
public void Update()
{
translate.x += 1.0f;
Console.WriteLine("Translation: ({0}, {1})", translate.x, translate.y);
}
}
}
Which simply prints a float to the console, and I load the dll file thats created in Visual Studio For Mac with the following code.
C++
#include <iostream>
#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/debug-helpers.h>
int main(int argc, const char * argv[]) {
mono_set_dirs("/Library/Frameworks/Mono.framework/Versions/6.10.0/lib", "/Library/Frameworks/Mono.framework/Versions/6.10.0/etc");
MonoDomain* domain = mono_jit_init("Scripting_Engine");
MonoAssembly* assembly = mono_domain_assembly_open(domain, "/Desktop/ScriptingMacOSX/Build/Products/Debug/ExampleApp.dll");
MonoImage* image = mono_assembly_get_image(assembly);
if (!image)
{
std::cout << "Image Not Created" << std::endl;
} else {
std::cout << "Image Created" << std::endl;
}
MonoClass* scriptClass = mono_class_from_name(image, "ExampleApp", "PlayerMovement");
if(!scriptClass) {
std::cout << "Class Not Created" << std::endl;
} else {
std::cout << "Class Created" << std::endl;
}
MonoObject* scriptObject = mono_object_new(domain, scriptClass);
if(!scriptObject) {
std::cout << "Object Not Created" << std::endl;
} else {
std::cout << "Object Created" << std::endl;
}
mono_runtime_object_init(scriptObject);
void* iter = nullptr;
MonoMethod* method;
// Mono Methods
MonoMethod* startMethod = nullptr;
MonoMethod* updateMethod = nullptr;
std::string methodName = "Start";
while((method = mono_class_get_methods(scriptClass, &iter)))
{
if (strcmp(mono_method_get_name(method), "Start") == 0)
{
startMethod = method;
}
if (strcmp(mono_method_get_name(method), "Update") == 0)
{
updateMethod = method;
}
}
mono_runtime_invoke(startMethod, scriptObject, nullptr, nullptr);
while (true) {
mono_runtime_invoke(updateMethod, scriptObject, nullptr, nullptr);
}
return 0;
}
This Process works fine as long as the test variable in the c# script is a zero. As soon as it is non-zero, it produces the following error.
System.TypeInitializationException: The type initializer for 'Sys' threw an exception. ---> System.DllNotFoundException: System.Native assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) Interop+Sys.LChflagsCanSetHiddenFlag()
at Interop+Sys..cctor () [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
--- End of inner exception stack trace ---
at System.Number.DoubleToNumber (System.Double value, System.Int32 precision, System.Number+NumberBuffer& number) [0x000b2] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Number.FormatSingle (System.Text.ValueStringBuilder& sb, System.Single value, System.ReadOnlySpan`1[T] format, System.Globalization.NumberFormatInfo info) [0x000d1] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Number.TryFormatSingle (System.Single value, System.ReadOnlySpan`1[T] format, System.Globalization.NumberFormatInfo info, System.Span`1[T] destination, System.Int32& charsWritten) [0x00015] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Single.TryFormat (System.Span`1[T] destination, System.Int32& charsWritten, System.ReadOnlySpan`1[T] format, System.IFormatProvider provider) [0x0000a] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Text.StringBuilder.AppendFormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args) [0x00308] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.String.FormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args) [0x00023] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.String.Format (System.IFormatProvider provider, System.String format, System.Object arg0) [0x00008] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.IO.TextWriter.WriteLine (System.String format, System.Object arg0) [0x00007] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.IO.TextWriter+SyncTextWriter.WriteLine (System.String format, System.Object arg0) [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
at (wrapper synchronized) System.IO.TextWriter+SyncTextWriter.WriteLine(string,object)
at System.Console.WriteLine (System.String format, System.Object arg0) [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
at ExampleApp.PlayerMovement.Start () [0x00007] in <6b3c479fe6974a38b024c98ff963d353>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Sys' threw an exception. ---> System.DllNotFoundException: System.Native assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) Interop+Sys.LChflagsCanSetHiddenFlag()
at Interop+Sys..cctor () [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
--- End of inner exception stack trace ---
at System.Number.DoubleToNumber (System.Double value, System.Int32 precision, System.Number+NumberBuffer& number) [0x000b2] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Number.FormatSingle (System.Text.ValueStringBuilder& sb, System.Single value, System.ReadOnlySpan`1[T] format, System.Globalization.NumberFormatInfo info) [0x000d1] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Number.TryFormatSingle (System.Single value, System.ReadOnlySpan`1[T] format, System.Globalization.NumberFormatInfo info, System.Span`1[T] destination, System.Int32& charsWritten) [0x00015] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Single.TryFormat (System.Span`1[T] destination, System.Int32& charsWritten, System.ReadOnlySpan`1[T] format, System.IFormatProvider provider) [0x0000a] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Text.StringBuilder.AppendFormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args) [0x00308] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.String.FormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args) [0x00023] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.String.Format (System.IFormatProvider provider, System.String format, System.Object arg0) [0x00008] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.IO.TextWriter.WriteLine (System.String format, System.Object arg0) [0x00007] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.IO.TextWriter+SyncTextWriter.WriteLine (System.String format, System.Object arg0) [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
at (wrapper synchronized) System.IO.TextWriter+SyncTextWriter.WriteLine(string,object)
at System.Console.WriteLine (System.String format, System.Object arg0) [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
at ExampleApp.PlayerMovement.Start () [0x00007] in <6b3c479fe6974a38b024c98ff963d353>:0
I have been looking into it, and I am thinking it might be a linking error.
What I have linked
libmonosgen-2.0.a
As I said above, this works fine for a zero as the value of the variable, so I think the above library is the only thing I need linked
Any Help would be much appreciated
Related
I am getting an exception I have no clue how to debug. It is thrown on the following line:
var serializer = new XmlSerializer(typeof(Universe));
System.Configuration.ConfigurationErrorsException has been thrown
Error Initializing the configuration system.
What is the configuration system, where is it getting initialized and what does it have to do with the XmlSerializer?
The full exception:
System.Configuration.ConfigurationErrorsException: Error Initializing the configuration system. ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section <runtime> (/MyPath/Projects/Stars/Stars/Stars.Desktop/bin/Debug/net471/Stars.Desktop.app/Contents/MonoBundle/Stars.Desktop.exe.config line 3)
at System.Configuration.ConfigInfo.ThrowException (System.String text, System.Xml.XmlReader reader) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ConfigInfo.cs:77
at System.Configuration.SectionGroupInfo.ReadContent (System.Xml.XmlReader reader, System.Configuration.Configuration config, System.Boolean overrideAllowed, System.Boolean root) [0x0011f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/SectionGroupInfo.cs:330
at System.Configuration.SectionGroupInfo.ReadRootData (System.Xml.XmlReader reader, System.Configuration.Configuration config, System.Boolean overrideAllowed) [0x00007] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/SectionGroupInfo.cs:273
at System.Configuration.Configuration.ReadConfigFile (System.Xml.XmlReader reader, System.String fileName) [0x000ce] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/Configuration.cs:572
at System.Configuration.Configuration.Load () [0x00043] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/Configuration.cs:532
at System.Configuration.Configuration.Init (System.Configuration.Internal.IConfigSystem system, System.String configPath, System.Configuration.Configuration parent) [0x0005d] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/Configuration.cs:138
at System.Configuration.Configuration..ctor (System.Configuration.InternalConfigurationSystem system, System.String locationSubPath) [0x00056] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/Configuration.cs:96
at System.Configuration.InternalConfigurationFactory.Create (System.Type typeConfigHost, System.Object[] hostInitConfigurationParams) [0x0000d] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/InternalConfigurationFactory.cs:41
at System.Configuration.ConfigurationManager.OpenExeConfigurationInternal (System.Configuration.ConfigurationUserLevel userLevel, System.Reflection.Assembly calling_assembly, System.String exePath) [0x000ea] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ConfigurationManager.cs:119
at System.Configuration.ClientConfigurationSystem.get_Configuration () [0x0000e] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ClientConfigurationSystem.cs:49
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.get_Configuration () [0x0001f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ClientConfigurationSystem.cs:52
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ClientConfigurationSystem.cs:61
at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ConfigurationManager.cs:159
at System.Configuration.PrivilegedConfigurationManager.GetSection (System.String sectionName) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/misc/PrivilegedConfigurationManager.cs:24
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/DiagnosticsConfiguration.cs:171
at System.Diagnostics.DiagnosticsConfiguration.Initialize () [0x0002a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/DiagnosticsConfiguration.cs:209
at System.Diagnostics.DiagnosticsConfiguration.get_SwitchSettings () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/DiagnosticsConfiguration.cs:29
at System.Diagnostics.Switch.InitializeConfigSettings () [0x00013] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/Switch.cs:272
at System.Diagnostics.Switch.InitializeWithStatus () [0x00046] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/Switch.cs:211
at System.Diagnostics.Switch.get_SwitchSetting () [0x0000a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/Switch.cs:144
at System.Diagnostics.BooleanSwitch.get_Enabled () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/BooleanSwitch.cs:39
at System.Xml.Serialization.TempAssembly.LoadGeneratedAssembly (System.Type type, System.String defaultNamespace, System.Xml.Serialization.XmlSerializerImplementation& contract) [0x00015] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System.Xml/System/Xml/Serialization/Compilation.cs:164
at System.Xml.Serialization.XmlSerializer..ctor (System.Type type, System.String defaultNamespace) [0x0007e] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System.Xml/System/Xml/Serialization/XmlSerializer.cs:198
at System.Xml.Serialization.XmlSerializer..ctor (System.Type type) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System.Xml/System/Xml/Serialization/XmlSerializer.cs:177
at Stars.SaveManager.SaveLoader.SaveUniverse (Stars.Game.Universe universe) [0x0005d] in /MypPath/Projects/Stars/Stars/Stars/SaveManager/SaveLoader.cs:39
You have an error in app.config file. There is a problem with the section runtime. Be sure it is declared in and has valid structure and values.
Here the Inner exception message gives the hint
System.Configuration.ConfigurationErrorsException: Unrecognized configuration section <runtime>
I'm trying to do a desktop application which communicates with an API REST, then I decided to do it with MonoDevelop in my xubuntu. I tried to Create a Uri from string with the constructor but, when the object Uri is created, it appears in my MonoDevelop debugger:
stationUri {System.Uri}
System.Uri AbsolutePath System.NullReferenceException: Object
reference not set to an instance of an object AbsoluteUri
System.NullReferenceException: Object reference not set to an
instance of an object Authority System.NullReferenceException:
Object reference not set to an instance of an object DnsSafeHost
System.NullReferenceException: Object reference not set to an
instance of an object Fragment System.NullReferenceException:
Object reference not set to an instance of an object Host
System.NullReferenceException: Object reference not set to an
instance of an object HostNameType System.NullReferenceException:
Object reference not set to an instance of an object
urlConParametros https://api.thingspeak.com/channels/***/fields/4.json?api_key=***&results=2 string
Because of security reasons I didn't show the full URL.
And the respective code associated with this error:
public string GetResponse_GET(string url, Dictionary<string, string> parameters)
{
try
{
//Concatenamos los parametros, OJO: antes del primero debe estar el caracter "?"
string parametrosConcatenados = ConcatParams(parameters);
string urlConParametros = url + "?" + parametrosConcatenados;
string responseFromServer = null;
Uri stationUri = new Uri(urlConParametros);
if(!stationUri.IsWellFormedOriginalString())
{
System.Console.WriteLine("Url VacĂa");
}
else
{
System.Net.HttpWebRequest wr = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(stationUri);
wr.Method = "GET";
wr.ContentType = "application/x-www-form-urlencoded";
System.IO.Stream newStream;
// Obtiene la respuesta
System.Net.WebResponse response = wr.GetResponse();
// Stream con el contenido recibido del servidor
newStream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(newStream);
// Leemos el contenido
responseFromServer = reader.ReadToEnd();
// Cerramos los streams
reader.Close();
newStream.Close();
response.Close();
}
return responseFromServer;
}
catch (System.Web.HttpException ex)
{
if (ex.ErrorCode == 404)
throw new Exception("Servicio Remoto No Encontrado: " + url);
else throw ex;
}
}
private string ConcatParams(Dictionary<string, string> parameters)
{
bool FirstParam = true;
string Parametros = null;
if (parameters != null)
{
Parametros = "";
foreach (KeyValuePair<string, string> param in parameters)
{
if(!FirstParam)
Parametros+="&";
Parametros+= param.Key + "=" + param.Value;
FirstParam = false;
}
}
return Parametros == null ? String.Empty : Parametros.ToString();
}
If I run completely the code, throws the next stackTrace associated (I removed the sensitive data):
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.NullReferenceException: Object reference not set to an instance of an object
at System.Net.WebRequest.Create (System.Uri requestUri) [0x00000] in :0
at MainWindow.GetResponse_GET (System.String url, System.Collections.Generic.Dictionary`2 parameters) [0x0002b] in /home//MonoDevelop Projects///MainWindow.cs:92
at MainWindow.showAct (System.Object sender, System.EventArgs e) [0x0003f] in /home//MonoDevelop Projects///MainWindow.cs:34
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) [0x00038] 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) [0x00053] in :0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in :0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x0010d] in :0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x0000b] in :0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in :0
at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00067] in :0
at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x0000c] 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) [0x00086] in :0
at GLib.ExceptionManager.RaiseUnhandledException (System.Exception e, Boolean is_terminal) [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
at Gtk.Application.gtk_main () [0x00000] in :0
at Gtk.Application.Run () [0x00000] in :0
at .MainClass.Main (System.String[] args) [0x00012] in /home//MonoDevelop Projects///Program.cs:13
I don't know why can't establish correctly the Uri from string... Then if I pass the incorrect Uri to create the WebRequest throws an error too...
Does anyone know what I am doing wrong here.
Thank you so much for the help, I solved it copying cs files and creating an empty proyect C# in monodevelop and putting the old files in the new project and reloading references, then new Uri(string) works... Before I created the project as gtk#2.0 and now like empty and works... I dnt know the reason...
check to make sure that query string does not contain any characters that are not url friendly otherwise you need to url encode it. To avoid having to encode it yourself you can use the UriBuilder class when contructing the url
var uriBuilder = new UriBuilder(uri);
uriBuilder.Query = ConcatParams(parameters);
Uri stationUri = uriBuilder.Uri;
//if NOT well formed
if(!stationUri.IsWellFormedOriginalString()) { //Note the `!` exclamation mark
//...code removed for brevity
} else {
//...code removed for brevity
}
It will url encode any values as necessary.
I update my Unity from 5.2 to 5.6, this is success. But after update, i can't open file script. This is Error
The file '/Users/vietbac/Desktop/New Unity Project 1/Assets/NewBehaviourScript.cs' could not be opened. Error while loading style :Default
System.IO.IOException: Error while loading style :Default --->
System.TypeInitializationException: An exception was thrown by the
type initializer for System.Drawing.KnownColors --->
System.TypeInitializationException: An exception was thrown by the
type initializer for System.Drawing.GDIPlus --->
System.DllNotFoundException:
/Applications/Unity/MonoDevelop.app/Contents/MacOS/../Frameworks/Mono.framework/Versions/2.10.12/lib/libgdiplus.dylib
at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup
(ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
at System.Drawing.GDIPlus..cctor () [0x00000] in :0
--- End of inner exception stack trace --- at System.Drawing.KnownColors..cctor () [0x00000] in :0
--- End of inner exception stack trace --- at System.Drawing.ColorConverter.StaticConvertFromString
(ITypeDescriptorContext context, System.String s,
System.Globalization.CultureInfo culture) [0x00000] in :0 at System.Drawing.ColorConverter.ConvertFrom
(ITypeDescriptorContext context, System.Globalization.CultureInfo
culture, System.Object value) [0x00000] in :0 at
System.ComponentModel.TypeConverter.ConvertFrom (System.Object o)
[0x00000] in :0 at
System.ComponentModel.TypeConverter.ConvertFromString (System.String
text) [0x00000] in :0 at
System.Drawing.ColorTranslator.FromHtml (System.String htmlColor)
[0x00000] in :0 at
Mono.TextEditor.Highlighting.ColorScheme.GetColorFromString
(System.String colorString) [0x001c0] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/ColorScheme.cs:578
at Mono.TextEditor.Highlighting.ColorScheme.SetChunkStyle
(System.String name, System.String weight, System.String foreColor,
System.String backColor) [0x00038] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/ColorScheme.cs:514
at Mono.TextEditor.Highlighting.ColorScheme.ReadStyleTree
(System.Xml.XmlReader reader, Mono.TextEditor.Highlighting.ColorScheme
result, System.String curName, System.String curWeight, System.String
curColor, System.String curBgColor) [0x000b8] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/ColorScheme.cs:599
at
Mono.TextEditor.Highlighting.ColorScheme+c__AnonStorey32.<>m__43
() [0x000e0] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/ColorScheme.cs:625
at
Mono.TextEditor.Highlighting.XmlReadHelper+c__AnonStorey19.<>m__D
(Mono.TextEditor.Highlighting.ReadCallbackData data) [0x00000] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/XmlReadHelper.cs:55
at Mono.TextEditor.Highlighting.XmlReadHelper.ReadList
(System.Xml.XmlReader reader, ICollection1 endNodes,
Mono.TextEditor.Highlighting.ReaderCallbackWithData callback)
[0x0008b] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/XmlReadHelper.cs:91
at Mono.TextEditor.Highlighting.XmlReadHelper.ReadList
(System.Xml.XmlReader reader, ICollection1 endNodes,
Mono.TextEditor.Highlighting.ReaderCallback callback) [0x0000d] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/XmlReadHelper.cs:54
at Mono.TextEditor.Highlighting.XmlReadHelper.ReadList
(System.Xml.XmlReader reader, System.String endNode,
Mono.TextEditor.Highlighting.ReaderCallback callback) [0x00000] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/XmlReadHelper.cs:50
at Mono.TextEditor.Highlighting.ColorScheme.LoadFrom
(System.Xml.XmlReader reader) [0x00018] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/ColorScheme.cs:615
at Mono.TextEditor.Highlighting.SyntaxModeService.LoadStyle
(System.String name) [0x0003c] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs:111
--- End of inner exception stack trace --- at Mono.TextEditor.Highlighting.SyntaxModeService.LoadStyle
(System.String name) [0x00053] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs:113
at Mono.TextEditor.Highlighting.SyntaxModeService.GetColorStyle
(System.String name) [0x0002c] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs:83
at Mono.TextEditor.TextEditorOptions.GetColorStyle () [0x00000] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorOptions.cs:492
at MonoDevelop.SourceEditor.StyledSourceEditorOptions.GetColorStyle ()
[0x00000] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/StyledSourceEditorOptions.cs:192
at Mono.TextEditor.TextArea.OptionsChanged (System.Object sender,
System.EventArgs args) [0x00038] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/TextArea.cs:685
at Mono.TextEditor.TextArea.set_Options (ITextEditorOptions value)
[0x00066] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/TextArea.cs:157
at Mono.TextEditor.TextEditor.set_Options (ITextEditorOptions value)
[0x00000] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/TextEditor.cs:414
at MonoDevelop.SourceEditor.ExtensibleTextEditor..ctor
(MonoDevelop.SourceEditor.SourceEditorView view) [0x00028] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtensibleTextEditor.cs:75
at MonoDevelop.SourceEditor.SourceEditorWidget..ctor
(MonoDevelop.SourceEditor.SourceEditorView view) [0x00077] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorWidget.cs:284
at MonoDevelop.SourceEditor.SourceEditorView..ctor () [0x000ca] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs:189
at MonoDevelop.SourceEditor.SourceEditorDisplayBinding.CreateContent
(FilePath fileName, System.String mimeType,
MonoDevelop.Projects.Project ownerProject) [0x00000] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorDisplayBinding.cs:94
at MonoDevelop.Ide.Gui.LoadFileWrapper.Invoke (System.String fileName)
[0x00033] in
/home/builduser/buildslave/monodevelop/build/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Workbench.cs:1182
I'm running Arch Linux with the following version of mcs:
>mcs --version
Mono C# compiler version 4.0.4.0
And the following version of dbus-sharp
>pacman -Ss dbus-sharp
extra/dbus-sharp 0.8.1-1 [installed] C# implementation of D-Bus
extra/dbus-sharp-glib 0.6.0-1 [installed] C# GLib implementation of D-Bus
This is my test program, based on the example code found here: https://gist.github.com/Ummon/4317268
I'm just trying to access the settings of the currently active connection, which should be returned as a 'Dict of {String, Dict of {String, Variant}}' as I've checked in the d-feet tool for the org.freedesktop.NetworkManager.Settings.Connection interface
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using DBus;
namespace NetworkManagerDictTest {
public class MyTest {
[Interface("org.freedesktop.NetworkManager.Settings.Connection")]
public interface IConnection {
IDictionary<string, IDictionary<string, object>> GetSettings();
}
readonly static string BUS_NAME = "org.freedesktop.NetworkManager";
public static void Main(string[] argv) {
org.freedesktop.DBus.Properties NetworkManagerProps = Bus.System.GetObject<org.freedesktop.DBus.Properties>(BUS_NAME, new ObjectPath("/org/freedesktop/NetworkManager"));
ObjectPath[] activeConnections = NetworkManagerProps.Get(BUS_NAME, "ActiveConnections") as ObjectPath[];
if (activeConnections.Length > 0) {
org.freedesktop.DBus.Properties ActiveConnectionProperties = Bus.System.GetObject<org.freedesktop.DBus.Properties>(BUS_NAME, activeConnections[0]);
ObjectPath ActiveConnectionPath = ActiveConnectionProperties.Get("org.freedesktop.NetworkManager.Connection.Active", "Connection") as ObjectPath;
Console.WriteLine("Using connection path: " + ActiveConnectionPath);
IConnection connection = Bus.System.GetObject<IConnection>(BUS_NAME, ActiveConnectionPath);
Console.WriteLine("Connection Object ok");
IDictionary<string, IDictionary<string, object>> settings = connection.GetSettings();
Console.WriteLine(settings);
}
}
}
}
Compilation went without errors nor warnings:
mcs Test.cs -r:/usr/lib/mono/dbus-sharp-2.0/dbus-sharp.dll -r:/usr/lib/mono/dbus-sharp-glib-2.0/dbus-sharp-glib.dll
However my program crashes during execution with the following output:
>mono Test.exe
Using connection path: /org/freedesktop/NetworkManager/Settings/0
Connection Object ok
Unhandled Exception:
DBus.Protocol.MessageReader+PaddingException: Read non-zero byte at position 28 while expecting padding. Value given: 200
at DBus.Protocol.MessageReader.ReadPad (Int32 alignment) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadStruct (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadValue (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadDictionary[String,IDictionary`2] () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest+IConnectionProxy.GetSettings () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest.Main (System.String[] argv) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: DBus.Protocol.MessageReader+PaddingException: Read non-zero byte at position 28 while expecting padding. Value given: 200
at DBus.Protocol.MessageReader.ReadPad (Int32 alignment) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadStruct (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadValue (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadDictionary[String,IDictionary`2] () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest+IConnectionProxy.GetSettings () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest.Main (System.String[] argv) [0x00000] in <filename unknown>:0
What can I do to work around this problem? Am I making a mistake when working with the DBus? It seems that all the method calls up to GetSettings went without issues. I've also encountered a similar problem while trying to fix a bug in another project where dbus-sharp would throw an exception when calling GetSettings. Could this be an issue of dbus-sharp instead?
Taking a look at the source code it seems that dbus-sharp infers the return type directly from the signature of the declared method. Unfortunately it doesn't check if I'm using a parent class or interface of Dictionary, eventually it tries to read a DBus struct because of a fallback case which causes the exception as DBus structs are 8 byte padded while dicts use 4 bytes
Replacing all the IDictionary types with Dictionary worked fine and solved my problem.
I am c# beginner and trying to read a binary file to calculate the frequency of the symbols inside the binary file. (Frequency is the number of time the symbols repeats).
In my first step I took I kept the data type of "symbol" read as "int" and code worked fine.
But now I wanted to make this symbol of generic type (I mean <T> type).
The code compiles with out any error in ubantu terminal.
But when I execute using "mono filename.exe BinaryFile.bin" This binary file is read at sole argument. Please see at last that how i got this Binary file toto.bin.
The error is :
hp#ubuntu:~/Desktop/Internship_Xav/templatescplus$ mono test.exe toto.bin
Unhandled Exception: System.ArgumentException: Destination array is not long enough to copy all the items in the collection. Check array index and length.
at System.BitConverter.PutBytes (System.Byte* dst, System.Byte[] src, Int32 start_index, Int32 count) [0x00000] in <filename unknown>:0
at System.BitConverter.ToInt64 (System.Byte[] value, Int32 startIndex) [0x00000] in <filename unknown>:0
at shekhar_final_version_Csharp.Huffman`1[System.Int64]..ctor (System.String[] args, System.Func`3 converter) [0x00000] in <filename unknown>:0
at shekhar_final_version_Csharp.MyClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: Destination array is not long enough to copy all the items in the collection. Check array index and length.
at System.BitConverter.PutBytes (System.Byte* dst, System.Byte[] src, Int32 start_index, Int32 count) [0x00000] in <filename unknown>:0
at System.BitConverter.ToInt64 (System.Byte[] value, Int32 startIndex) [0x00000] in <filename unknown>:0
at shekhar_final_version_Csharp.Huffman`1[System.Int64]..ctor (System.String[] args, System.Func`3 converter) [0x00000] in <filename unknown>:0
at shekhar_final_version_Csharp.MyClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
hp#ubuntu:~/Desktop/
My full code to do so is (narrowed code):
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Final
{
public class A < T > where T: struct, IComparable < T > , IEquatable < T >
{
public class Node
{
public T symbol;
public Node next;
public int freq;
} public Node Front;
public A(string[] args, Func < byte[], int, T > converter)
{
int size = Marshal.SizeOf(typeof (T));
Front = null;
using(var stream = new BinaryReader(System.IO.File.OpenRead(args[0])))
{
while (stream.BaseStream.Position < stream.BaseStream.Length)
{
byte[] bytes = stream.ReadBytes(size);
T processingValue = converter(bytes, 0);
Node pt, temp;
pt = Front;
while (pt != null)
{ Console.WriteLine("check1");
if (pt.symbol.Equals(processingValue))
{
pt.freq++;
break;
}
Console.WriteLine("Symbol : {0} frequency is : {1}", pt.symbol, pt.freq);
temp = pt;
pt = pt.next;
}
}
}
}
} //////////////////////////////////////////////////
public class MyClass
{
public static void Main(string[] args)
{
A < long > ObjSym = new A < long > (args, BitConverter.ToInt64);
}
}
}
I think the problem is created while creating object of type Huffman in public class MyClass. Could some one please help me how to get a rid of this problem by giving a solution (any piece of code would be highly appreciated)? Thanks.
If the size of the file is not a multitude of 8 bytes (64 bits), the last ReadBytes() will result in a byte[] smaller than 8 bytes, causing ToInt64() to fail.