1. Hello!
    I've got a stupid error, which makes no sense. Have a look at this code from my plugin please:

    Code:
                    MySqlConnection connection = new MySqlConnection(connectionString);
                    connection.Open();
                    //...                MySqlCommand cmd;
                    cmd = connection.CreateCommand();
                    cmd.CommandText = command;
                    cmd.ExecuteNonQuery();
    It seems to be fine, but the compiler throws an error:
    Code:
    A local variable `cmd' cannot be used before it is declared
    This snippet is the only place in code where the 'cmd' name occurs. The code had been tested in a normal Console C# project before, and it worked perfectly. However, it causes an error in Oxide.
    Could someone explain it to me?
     
    Last edited by a moderator: Jul 1, 2018
  2. Wulf

    Wulf Community Admin

    You have initialized cmd with anything. The fix would be:

    MySqlCommand cmd = connection.CreateCommand();
     
  3. It's already initialized. Have a look on the snippet again please.
     
  4. Wulf

    Wulf Community Admin

    According to C#, it's not. ;)

    Try the code, there's no need to declare it below the uninitialized variable, just combine the lines.
     
  5. I tried it, but it doesn't fix the error :/
     
  6. Wulf

    Wulf Community Admin

    Updated code and error please? The error you showed previously is referring to that line specifically.
     
  7. The full error is:
    Code:
    Error while compiling: DataUploader.cs(42,17): error CS0841: A local variable `cmd' cannot be used before it is declared
    The updated code:
    Code:
                    MySqlConnection connection = new MySqlConnection(connectionString);
                    connection.Open();
                    //...                MySqlCommand cmd = connection.CreateCommand();
                    cmd.CommandText = command;
                    cmd.ExecuteNonQuery();
    It makes completely no sense. It has already happened to me while using oxide before.
     
  8. Wulf

    Wulf Community Admin

    The error isn't related to Oxide at all. The compiling is done by Mono's compiler, which supports up to C# 6 right now. Are you developing in an IDE? an IDE should help resolve the error, if it's missing a reference or whatever.
     
  9. I'm developing using Visual Studio Community 2017. It doesn't seem to be a missing reference, because it would throw a missing reference exception. It's quite annoying since it stops me from developing any plugins. Could you try to compile the plugin to recreate the error? Or at least try to find out what the problem is by having a look at the whole code? It's pretty short: ybin | private paste
    Thanks in advance.
     
  10. Okay, the thread can be closed. I solved it somehow, but it required changing the source of the Oxide.CSharp. Thanks for replies.
     
  11. Wulf

    Wulf Community Admin

    That would not be a solution and I don't even see how that would resolve your issue, because Oxide.CSharp doesn't even handle the compiling of the plugins; that error is from Compiler aka Mono.
     
  12. I added a reference to MySqlData dll in the CSharp source, compiled it, then added using MySqlData in the plugin and it worked. Not sure if it wouldn't work without adding the reference in source though.
     
  13. Wulf

    Wulf Community Admin

    That would not be the solution, that should be added in your plugin itself. I would suggest using Oxide's MySQL library though, not Mono's directly. If you want to add a reference to a DLL not referenced by Oxide by default, simply use a magic reference:

    At the top of your plugin:

    // Reference: DLLName
     
  14. Thanks, I didn't know about that. The Oxide's MySQL library has no documentation, has it? I couldn't find it, so I decided to use standard library instead.
     
  15. Wulf

    Wulf Community Admin

    Only what is provided on the Extensions page and GitHub repo itself. There should be a few threads here that answer some questions with it as well.