C# Cant find object reference when using terminal.gui









up vote
0
down vote

favorite












Ive been playing around with some server/client stuff and though id try using terminal.gui, and for some reason that i dont understand its acting up. i have 2 scripts; one to handle the backend stuff and one to handle the user interface/interraction.



script1:



using UI;

namespace ServerTest

public class Server

static void Main()

UI.UI.main();
StartServ();
RecieveConn.Start();
MngSockets.Start();





script 2:



using ServerTest;
using Terminal.Gui;

namespace UI

public class UI

static Window win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");
public static void main()

Application.Init();
win.Add(new Label(0, 0, "asd"));

Application.Run(win);





This gives me the error:



System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'UI.UI' threw an exception.
Source=Server
StackTrace:
at UI.UI.main() in C:UsersThisPcDesktopConsoleApp2ConsoleApp2ui.cs:line 29
at ServerTest.Server.Main() in C:UsersThisPcDesktopConsoleApp2ConsoleApp2Program.cs:line 23

Inner Exception 1:
NullReferenceException: Object reference not set to an instance of an object.


Though, if i do this it works:



using ServerTest;
using Terminal.Gui;

namespace UI

public class UI

public static void main()

Window win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");

Application.Init();
win.Add(new Label(0, 0, "asd"));

Application.Run(win);





but then i cant use the win variable in other functions...
Thanks in advance =)










share|improve this question





















  • The short answer is that the static constructor is likely running too early - before Application has been initialized.
    – mjwills
    Nov 11 at 23:06










  • makes sense... thanks alot! =)
    – Asperix
    Nov 11 at 23:12














up vote
0
down vote

favorite












Ive been playing around with some server/client stuff and though id try using terminal.gui, and for some reason that i dont understand its acting up. i have 2 scripts; one to handle the backend stuff and one to handle the user interface/interraction.



script1:



using UI;

namespace ServerTest

public class Server

static void Main()

UI.UI.main();
StartServ();
RecieveConn.Start();
MngSockets.Start();





script 2:



using ServerTest;
using Terminal.Gui;

namespace UI

public class UI

static Window win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");
public static void main()

Application.Init();
win.Add(new Label(0, 0, "asd"));

Application.Run(win);





This gives me the error:



System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'UI.UI' threw an exception.
Source=Server
StackTrace:
at UI.UI.main() in C:UsersThisPcDesktopConsoleApp2ConsoleApp2ui.cs:line 29
at ServerTest.Server.Main() in C:UsersThisPcDesktopConsoleApp2ConsoleApp2Program.cs:line 23

Inner Exception 1:
NullReferenceException: Object reference not set to an instance of an object.


Though, if i do this it works:



using ServerTest;
using Terminal.Gui;

namespace UI

public class UI

public static void main()

Window win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");

Application.Init();
win.Add(new Label(0, 0, "asd"));

Application.Run(win);





but then i cant use the win variable in other functions...
Thanks in advance =)










share|improve this question





















  • The short answer is that the static constructor is likely running too early - before Application has been initialized.
    – mjwills
    Nov 11 at 23:06










  • makes sense... thanks alot! =)
    – Asperix
    Nov 11 at 23:12












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Ive been playing around with some server/client stuff and though id try using terminal.gui, and for some reason that i dont understand its acting up. i have 2 scripts; one to handle the backend stuff and one to handle the user interface/interraction.



script1:



using UI;

namespace ServerTest

public class Server

static void Main()

UI.UI.main();
StartServ();
RecieveConn.Start();
MngSockets.Start();





script 2:



using ServerTest;
using Terminal.Gui;

namespace UI

public class UI

static Window win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");
public static void main()

Application.Init();
win.Add(new Label(0, 0, "asd"));

Application.Run(win);





This gives me the error:



System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'UI.UI' threw an exception.
Source=Server
StackTrace:
at UI.UI.main() in C:UsersThisPcDesktopConsoleApp2ConsoleApp2ui.cs:line 29
at ServerTest.Server.Main() in C:UsersThisPcDesktopConsoleApp2ConsoleApp2Program.cs:line 23

Inner Exception 1:
NullReferenceException: Object reference not set to an instance of an object.


Though, if i do this it works:



using ServerTest;
using Terminal.Gui;

namespace UI

public class UI

public static void main()

Window win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");

Application.Init();
win.Add(new Label(0, 0, "asd"));

Application.Run(win);





but then i cant use the win variable in other functions...
Thanks in advance =)










share|improve this question













Ive been playing around with some server/client stuff and though id try using terminal.gui, and for some reason that i dont understand its acting up. i have 2 scripts; one to handle the backend stuff and one to handle the user interface/interraction.



script1:



using UI;

namespace ServerTest

public class Server

static void Main()

UI.UI.main();
StartServ();
RecieveConn.Start();
MngSockets.Start();





script 2:



using ServerTest;
using Terminal.Gui;

namespace UI

public class UI

static Window win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");
public static void main()

Application.Init();
win.Add(new Label(0, 0, "asd"));

Application.Run(win);





This gives me the error:



System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'UI.UI' threw an exception.
Source=Server
StackTrace:
at UI.UI.main() in C:UsersThisPcDesktopConsoleApp2ConsoleApp2ui.cs:line 29
at ServerTest.Server.Main() in C:UsersThisPcDesktopConsoleApp2ConsoleApp2Program.cs:line 23

Inner Exception 1:
NullReferenceException: Object reference not set to an instance of an object.


Though, if i do this it works:



using ServerTest;
using Terminal.Gui;

namespace UI

public class UI

public static void main()

Window win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");

Application.Init();
win.Add(new Label(0, 0, "asd"));

Application.Run(win);





but then i cant use the win variable in other functions...
Thanks in advance =)







c# .net visual-studio user-interface






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 21:59









Asperix

12




12











  • The short answer is that the static constructor is likely running too early - before Application has been initialized.
    – mjwills
    Nov 11 at 23:06










  • makes sense... thanks alot! =)
    – Asperix
    Nov 11 at 23:12
















  • The short answer is that the static constructor is likely running too early - before Application has been initialized.
    – mjwills
    Nov 11 at 23:06










  • makes sense... thanks alot! =)
    – Asperix
    Nov 11 at 23:12















The short answer is that the static constructor is likely running too early - before Application has been initialized.
– mjwills
Nov 11 at 23:06




The short answer is that the static constructor is likely running too early - before Application has been initialized.
– mjwills
Nov 11 at 23:06












makes sense... thanks alot! =)
– Asperix
Nov 11 at 23:12




makes sense... thanks alot! =)
– Asperix
Nov 11 at 23:12












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Thx mjwills for the answer...



just do



using ServerTest;
using Terminal.Gui;

namespace UI

public class UI

static Window win = null;
public static void main()

win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");

Application.Init();
win.Add(new Label(0, 0, "asd"));

Application.Run(win);








share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253669%2fc-sharp-cant-find-object-reference-when-using-terminal-gui%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    Thx mjwills for the answer...



    just do



    using ServerTest;
    using Terminal.Gui;

    namespace UI

    public class UI

    static Window win = null;
    public static void main()

    win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");

    Application.Init();
    win.Add(new Label(0, 0, "asd"));

    Application.Run(win);








    share|improve this answer
























      up vote
      0
      down vote



      accepted










      Thx mjwills for the answer...



      just do



      using ServerTest;
      using Terminal.Gui;

      namespace UI

      public class UI

      static Window win = null;
      public static void main()

      win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");

      Application.Init();
      win.Add(new Label(0, 0, "asd"));

      Application.Run(win);








      share|improve this answer






















        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        Thx mjwills for the answer...



        just do



        using ServerTest;
        using Terminal.Gui;

        namespace UI

        public class UI

        static Window win = null;
        public static void main()

        win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");

        Application.Init();
        win.Add(new Label(0, 0, "asd"));

        Application.Run(win);








        share|improve this answer












        Thx mjwills for the answer...



        just do



        using ServerTest;
        using Terminal.Gui;

        namespace UI

        public class UI

        static Window win = null;
        public static void main()

        win = new Window(new Rect(0, 0, Application.Top.Frame.Width, Application.Top.Frame.Height), "MyApp");

        Application.Init();
        win.Add(new Label(0, 0, "asd"));

        Application.Run(win);









        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 23:02









        Asperix

        12




        12



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253669%2fc-sharp-cant-find-object-reference-when-using-terminal-gui%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands