
patrick_c#
Hello, i tried to program my EZ Robot with C# under Ubuntu 15.04.
using System; using EZ_B;
public class HelloWorld { public static void Main() { Console.WriteLine("Enter IP of EZ-Robot"); string ip = Console.ReadLine(); Console.WriteLine("IP: "+ip ); Console.WriteLine("trying "+ ip); Console.WriteLine("trying to connect with " +ip);
//connecting
EZB _ezb = new EZB();
_ezb.Connect(ip);
Console.WriteLine("connecting...");
if (_ezb.IsConnected)
{
Console.WriteLine("[+] EZB connected at ip: " + ip);
}
else
{
Console.WriteLine("[-] EZB NOT connected at ip: " + ip);
}
}
}
Thats my code, but if i execute it...
patrick@patrick-X781X-X782X:~/ezrobot$ mono bsp.exe Unknown heap type: #GUlD
Unknown heap type: #Blop
Enter IP of EZ-Robot 192.168.1.1 IP: 192.168.1.1 trying 192.168.1.1 trying to connect with 192.168.1.1 Missing method .ctor in assembly /home/patrick/ezrobot/EZ_B.dll, type System.Runtime.CompilerServices.ExtensionAttribute Can't find custom attr constructor image: /home/patrick/ezrobot/EZ_B.dll mtoken: 0x0a00000a
Unhandled Exception: System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'EZ_B'. at HelloWorld.Main () [0x00000] in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'EZ_B'. at HelloWorld.Main () [0x00000] in :0
There must be a mistake with the "ez.Connect" command....
Thanks for help, Patrick.
There is no mistake, as it compiles and runs fine on my test. I would recommend using the universl bot library instead, as it also provides you access to the source code.
My problem is solved
"EZB _ezb = new EZB();" must stand before void main
But now I have this issue:
dmcs -r:EZ_B.dll bsp.cs bsp.cs(16,9): error CS0120: An object reference is required to access non-static member `HelloWorld._ezb' Compilation failed: 1 error(s), 0 warnings
in Line 16 is "_ezb.Connect("192.168.1.1");"
As you can imagine, it's difficult to assist when I only see a small fragment of the project. If you insist on moving forward with the mono library, please post your project or complete code and we'll get you running
Are you also using Linux? Which compiler do u use? How do you compile it? Thanks for your time
using System; using EZ_B;
public class HelloWorld { EZB _ezb = new EZB(); //this stands now before ""void main"
public static void Main() { Console.WriteLine("Enter IP of EZ-Robot"); string ip = Console.ReadLine(); Console.WriteLine("IP: "+ip ); Console.WriteLine("trying "+ ip); Console.WriteLine("trying to connect with " +ip);
//connecting
_ezb.Connect(ip); Console.WriteLine("connecting..."); if (_ezb.IsConnected) { Console.WriteLine("[+] EZB connected at ip: " + ip); } else { Console.WriteLine("[-] EZB NOT connected at ip: " + ip); }
} }
in simple form:
using System; using EZ_B;
public class HelloWorld { EZB _ezb = new EZB();
}
console output:
patrick@patrick-X781X-X782X:~/ezrobot$ dmcs -r:EZ_B.dll bsp.cs bsp.cs(12,9): error CS0120: An object reference is required to access non-static member `HelloWorld._ezb' Compilation failed: 1 error(s), 0 warnings
This is because the MAIN() is declared as static. The error message explains it. It says, an object is required to access a non-static member, and gives you the object, which is _ezb.
An error is written text to explain what the issue is. The error says the object _ezb is non-static but is being called from a static method.
As you can see, the method Main() is static, and the variable ez_b isn't.
Either make the _ezb static, or make Main() not static. I'm not sure if you can make Main() not static, but try and let me know
. Otherwise, make _ezb static.
Here's a document i found for you that discusses the difference between static and non-static declaration: http://www.c-sharpcorner.com/uploadfile/abhikumarvatsa/static-and-non-static-methods-in-C-Sharp/
Thanks for answering,
if i make the main void non static .... public void Main() .....
there is an error: error CS5001: Program
bsp.exe' does not contain a static
Main' method suitable for an entry pointso I think void main must be static.
Then i tried to make _ezb static:
using System; using EZ_B;
public class HelloWorld { static EZB _ezb = new EZB();
public static void Main() { Console.Clear(); Console.WriteLine("Enter IP of EZ-Robot"); string ip = Console.ReadLine(); Console.WriteLine("IP: "+ip ); Console.WriteLine("[+] trying "+ ip); Console.WriteLine("[+] trying to connect with " +ip);
//connecting
Console.WriteLine("connecting..."); _ezb.Connect(ip); Console.WriteLine("[+] connecting process finished"); Console.WriteLine("wating for result...");
if (_ezb.IsConnected) { Console.WriteLine("[+] EZB connected at ip: " + ip); }
else { Console.WriteLine("[-] EZB NOT connected at: " + ip); }
} }
it compiled
but if I execute it....
patrick@patrick-x781x-x782x:~/ezrobot$ mono bsp.exe Unknown heap type: #GUlD
Unknown heap type: #Blop
got wrong token: 0x6d22a7bf
Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for HelloWorld ---> System.TypeInitializationException: An exception was thrown by the type initializer for EZ_B.EZB ---> System.BadImageFormatException: Bad method token 0x6d22a7bf on image /home/patrick/ezrobot/EZ_B.dll. --- End of inner exception stack trace --- at HelloWorld..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for HelloWorld ---> System.TypeInitializationException: An exception was thrown by the type initializer for EZ_B.EZB ---> System.BadImageFormatException: Bad method token 0x6d22a7bf on image /home/patrick/ezrobot/EZ_B.dll. --- End of inner exception stack trace --- at HelloWorld..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- patrick@patrick-x781x-x782x:~/ezrobot$
In Visual Studio under Windows it worked perfectly...
If i get this running, I will make a Tutorial on your Website to help other users