Announcement

Collapse
No announcement yet.

How to get PluginFunction to return array of classes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get PluginFunction to return array of classes

    What do you do to return the array of CalendarEvents? Whenever I try to return anything but arrays of value variables from a plugin I get the error Object reference not set to an instance of an object when the returned value goes back to the script.

    Best regards
    Guahtdim

  • #2
    Windows or linux
    Can u post what you are doing in the script
    Cheers,
    Bob
    Web site | Help Desk | Feature Requests | Message Board

    Comment


    • #3
      Originally posted by Blade View Post
      Windows or linux Can u post what you are doing in the script
      I'm interested too. If I have an instance of a class I want to return from PluginFunction - I was sure it's not possible because it's allocated in the plugin process memory space. And my tests seem to work only if I return string (or int, or double).

      But looking at your plugins, like BLData or BLOnkyo - they do return class instances which intrigues me. Can you please explain the magic?

      Comment


      • #4
        You should be able to return it as an Object()
        Cheers,
        Bob
        Web site | Help Desk | Feature Requests | Message Board

        Comment


        • #5
          Originally posted by Blade View Post
          should be able to return it as an Object()
          Yeah, magic word should. Very basic test code below. All objects are returned as "object" anyway.
          Just to verify if I return TST.Name - it works. But returning an instance doesn't. And logically - I can't see how it could work. The instance is allocated in the plugin memory space. You can't return a pointer to internal process memory. You can only return basic objects (i.e. strings) as it knows how to serialise/deserialise them. But that's my theory and your plugins prove it wrong. But I couldn't find any other examples how to achieve it. So you are the only hope.

          Code:
              [Serializable]
              public class Test
              {
                  public string Name;
                  public Test(string Name)
                  {
                      this.Name = Name;
                  }
              }
          Code:
              public static Test TST = new Test("XXXX");
          
              public override object PluginFunction(string functionName, object[] parameters)
              {
                  return TST;
              }

          Comment


          • #6
            I don't understand how in your examples you return
            Code:
            object result = hs.PluginFunction()
            and then do
            Code:
            result.Name
            You can do it in Python, but in .NET you have to cast the object to class instance first?

            Comment


            • #7
              Thank you but I solved it myself. Posting here was a good round of rubber ducking.

              I am trying to make a plugin that are return an array of classes by calling PluginFunction from a script.

              But I made the following mistakes:
              * Not marking the returning class with Serializable
              * Running the plugin remote.
              * Having the returned class in a dll and not the running exe-file.

              As soon as I fixed that I could get the returned objects correctly into the scripts.

              Thanks Blade for fast reply and making me stop and think ;-)

              Comment


              • #8
                Originally posted by Guahtdim View Post
                * Not marking the returning class with Serializable
                * Running the plugin remote.
                * Having the returned class in a dll and not the running exe-file.
                Can you please elaborate a bit, you got me curious.
                1. In my test I did mark the class Serializable.
                2. By remote - do you mean on another computer? I'm running mine in debugger, but on the same computer. Does it qualify as remote?
                3. Having the returned class in a dll and not the running exe-file. That I don't understand, what do you mean?

                Comment


                • #9
                  Originally posted by bsobel
                  Alex, all your comments about pointers and address space show an lack of understanding of .net and .net remoting.
                  Bill, I think it shows more lack of HS documentation and support.
                  I suggest you read up on .net remoting, a base understanding here should make it more obvious what HomeSeer has done
                  I think that HS documentation should make it more obvious how to use what they have done. And if documentation sucks - then some advice from somebody why knows how to get it going might help. But directing to do some reading - just a waste of time and could be avoided.

                  Comment


                  • #10
                    Originally posted by Guahtdim View Post
                    * Running the plugin remote.
                    Yeah I worked it out too, I was running in debugger, after copying the exe to HS it now works. A decent explanation in the documentation could save us some time, uh? But I'm glad we worked it out.

                    Comment


                    • #11
                      Originally posted by bsobel
                      object didn’t represent a class in that thread
                      What do you mean? Bill what's your experience in S/W engineering?

                      Comment


                      • #12
                        I'm in SW for more than 30 years, you can have a look at Linkedin (updated about 9 years ago) and I do have "basic .NET understanding". And when I reply in forums - I try to provide real help, not "general advice".

                        Comment


                        • #13
                          Originally posted by bsobel

                          Alex, all your comments about pointers and address space show an lack of understanding of .net and .net remoting.
                          .
                          all this started with this. Seriously, I do not understand.

                          alexbk66 Clearly state he does not understand, and asked for help.

                          You do feel competition because he makes plugins that looks like yours? Talking about you CV was necessary too ? wtf.
                          It is not the first time I see your attacks on this forum.


                          Honestly, Bsobel, all your plugins are buggy as hell. And you ask a premium price for them. A little introspection wouldn't hurt.

                          Before posting on the forum.. please take a look at your personals (ego) issues.

                          Comment


                          • #14
                            Originally posted by Stevoangel View Post
                            all this started with this. Seriously, I do not understand.
                            It actually started from
                            Alex you might want to reread the question.
                            and
                            for scripting he will need to stay with simply objects
                            Because the original question was how to return a "complex" object. And I tried to help not because I need it, just out of interest. And we did find the solution.
                            But the comment "need to stay with simply objects" shows that Bill doesn't actually know how to do it.


                            Comment


                            • #15
                              Originally posted by alexbk66 View Post
                              It actually started from and
                              Because the original question was how to return a "complex" object. And I tried to help not because I need it, just out of interest. And we did find the solution.
                              But the comment "need to stay with simply objects" shows that Bill doesn't actually know how to do it.
                              Alex, again, "But the comment "need to stay with simply objects" shows that Bill doesn't actually know how to do it." As I have stated (and restated) simply return the object. The framework takes care of serialization. The issue is not how to return the object the issue becomes how to have the right libraries available to the script to deserialize them and then use it. The code needed for the class definition needs to be available to the script and much more configuration is needed to make the script work, so that is why I recommended unless you have a very special case, to stay with .net privatives such as list, map, set, etc. This allows the return to be directly used by scripts without all the configuration, which is easier for the vast majority of users.

                              But if you really want to return a complex object, do it. Just configure the code path for the script to have access to some shared library that has the type definition. Those files need to be copied to other machines if you are running the script remotely.

                              Comment

                              Unconfigured PHP Module

                              Collapse

                              Working...
                              X