Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Creating object stops execution of entire function

Creating object stops execution of entire function

Scheduled Pinned Locked Moved C#
questioncomhelplounge
18 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ __DanC__

    MyObject is a public class from an external class library, I am setting both vars and adding event delegates in the Init() function. I am executing it as you describe above but it will only step in if the 'new MyObject()' line is not there. With the line 'MyObject obj = new MyObject()' in the code when I step into that function all debug buttons are greyed out apart from stop, pause and restart and it does not step into the function, however if I comment out the ' = new MyObject()' it does step into the function and executes the DoSomething() and DoSomethingElse(). I do not change anything other than commenting out the ' = new MyObject()' to make it step into the code.

    Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

    L Offline
    L Offline
    Luc Pattyn
    wrote on last edited by
    #4

    Hi, who is calling Init ? some constructor ? is it a first time call ? has MyObject class already been called (hence compiled by JIT) ? Any chance MyObject can not be found at run-time (separate DLL maybe ?). Please show code for MyObject (at least: members and constructor). :)

    Luc Pattyn [My Articles] [Forum Guidelines]

    _ 1 Reply Last reply
    0
    • L Luc Pattyn

      Hi, who is calling Init ? some constructor ? is it a first time call ? has MyObject class already been called (hence compiled by JIT) ? Any chance MyObject can not be found at run-time (separate DLL maybe ?). Please show code for MyObject (at least: members and constructor). :)

      Luc Pattyn [My Articles] [Forum Guidelines]

      _ Offline
      _ Offline
      __DanC__
      wrote on last edited by
      #5

      Init is being called by the Start event of the main class for the app. It is a first time call. MyObject has not been called before but I have left the app for 10 mins and it is still hung so I would think it unlikely it was the JIT compiler. I would expect to see an exception if the class could not be found rather than the app hanging but the class is in a referenced DLL next to the app. I cannot show the code for MyObject as it is a third-party .NET assembly.

      Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

      N 1 Reply Last reply
      0
      • _ __DanC__

        Init is being called by the Start event of the main class for the app. It is a first time call. MyObject has not been called before but I have left the app for 10 mins and it is still hung so I would think it unlikely it was the JIT compiler. I would expect to see an exception if the class could not be found rather than the app hanging but the class is in a referenced DLL next to the app. I cannot show the code for MyObject as it is a third-party .NET assembly.

        Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

        N Offline
        N Offline
        Nissim Salomon
        wrote on last edited by
        #6

        Hi did you try using a try / catch block in order to catch exception ???

        _ 1 Reply Last reply
        0
        • N Nissim Salomon

          Hi did you try using a try / catch block in order to catch exception ???

          _ Offline
          _ Offline
          __DanC__
          wrote on last edited by
          #7

          I have a try...catch block inside the Init() function to catch the exception but the problem is that the execution does not enter the Init() functio if that line exists so therefore no exception is thrown.

          Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

          N 1 Reply Last reply
          0
          • _ __DanC__

            I have a try...catch block inside the Init() function to catch the exception but the problem is that the execution does not enter the Init() functio if that line exists so therefore no exception is thrown.

            Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

            N Offline
            N Offline
            Nissim Salomon
            wrote on last edited by
            #8

            use the try catch before the call to the init function

            _ 1 Reply Last reply
            0
            • N Nissim Salomon

              use the try catch before the call to the init function

              _ Offline
              _ Offline
              __DanC__
              wrote on last edited by
              #9

              I should have mentioned, I have also wrapped the Init() in a try...catch but again, nothing, no exception, nothing, just a hung application.

              Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

              N L 2 Replies Last reply
              0
              • _ __DanC__

                I should have mentioned, I have also wrapped the Init() in a try...catch but again, nothing, no exception, nothing, just a hung application.

                Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

                N Offline
                N Offline
                Nissim Salomon
                wrote on last edited by
                #10

                OK sorry Can you give more details about the MyObject class ???? and the environment that your application running ??? thanks

                _ 1 Reply Last reply
                0
                • N Nissim Salomon

                  OK sorry Can you give more details about the MyObject class ???? and the environment that your application running ??? thanks

                  _ Offline
                  _ Offline
                  __DanC__
                  wrote on last edited by
                  #11

                  The environment is Visual Studio 2003, .NET 1.1, Windows XP. The MyObject class is a third-party assembly containing lots of system calls, I understand that the problem could well be within the assembly and not my code and therefore out of my reach to fix but I would like to understand how a problem in a DLL assembly could stop the debugger entering the calling function, I could understand if it hung on the constructor of the MyObject class but I cannot see how it could hang on the calling function.

                  Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

                  N H 2 Replies Last reply
                  0
                  • _ __DanC__

                    I should have mentioned, I have also wrapped the Init() in a try...catch but again, nothing, no exception, nothing, just a hung application.

                    Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #12

                    OK, now what is MyObject class supposed to do ? any idea what would be inside its constructor ? have you other apps that use MyObject successfully ? :)

                    Luc Pattyn [My Articles] [Forum Guidelines]

                    _ 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      OK, now what is MyObject class supposed to do ? any idea what would be inside its constructor ? have you other apps that use MyObject successfully ? :)

                      Luc Pattyn [My Articles] [Forum Guidelines]

                      _ Offline
                      _ Offline
                      __DanC__
                      wrote on last edited by
                      #13

                      The MyObject implements a set of delegates which attach to system events allowing them to be handled by a .NET 1.1 application which they would otherwise not be able to do. I have no idea what would be in the constructor unfortunately but on further testing I have found that a call to a static function within the class prodcues the same result so I am confident it is an issue with the assembly but that still doesn't get me any closer to why the entire function does not execute.

                      Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

                      L 1 Reply Last reply
                      0
                      • _ __DanC__

                        The environment is Visual Studio 2003, .NET 1.1, Windows XP. The MyObject class is a third-party assembly containing lots of system calls, I understand that the problem could well be within the assembly and not my code and therefore out of my reach to fix but I would like to understand how a problem in a DLL assembly could stop the debugger entering the calling function, I could understand if it hung on the constructor of the MyObject class but I cannot see how it could hang on the calling function.

                        Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

                        N Offline
                        N Offline
                        Nissim Salomon
                        wrote on last edited by
                        #14

                        I run into some problems with the debugger (crushes,hangs and so on) usually while doing some system programming, the solution to that in most cases was just restart. you can try one of the following: 1.try to debug on another machine (check that you don't have problem in your environment) 2.use the System.Diagnostics.Debugger.Break(); command in order to force break. 3 use the sos debug extension in order to examine the runtime steps at execution 4 restart your computer and try again

                        1 Reply Last reply
                        0
                        • _ __DanC__

                          The MyObject implements a set of delegates which attach to system events allowing them to be handled by a .NET 1.1 application which they would otherwise not be able to do. I have no idea what would be in the constructor unfortunately but on further testing I have found that a call to a static function within the class prodcues the same result so I am confident it is an issue with the assembly but that still doesn't get me any closer to why the entire function does not execute.

                          Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

                          L Offline
                          L Offline
                          Luc Pattyn
                          wrote on last edited by
                          #15

                          OK, sounds like there is a problem with a static initializer in MyObject. I can see two ways forward now: - contact the author - try figuring out what is in the initializer using Reflector. I assume you are on .NET 2.0 or 3.x; you might want to try MyObject inside a .NET 1.1 project, just to see if it works for you; the simplest invocation of MyObject should be sufficient. BTW I am not impressed by a "third party" that calls its stuff "MyObject". Good luck !

                          Luc Pattyn [My Articles] [Forum Guidelines]

                          _ 1 Reply Last reply
                          0
                          • L Luc Pattyn

                            OK, sounds like there is a problem with a static initializer in MyObject. I can see two ways forward now: - contact the author - try figuring out what is in the initializer using Reflector. I assume you are on .NET 2.0 or 3.x; you might want to try MyObject inside a .NET 1.1 project, just to see if it works for you; the simplest invocation of MyObject should be sufficient. BTW I am not impressed by a "third party" that calls its stuff "MyObject". Good luck !

                            Luc Pattyn [My Articles] [Forum Guidelines]

                            _ Offline
                            _ Offline
                            __DanC__
                            wrote on last edited by
                            #16

                            It's not called MyObject, I just used that to demonstrate the problem ;) I would be equally unimpressed if it were :-D It is currently in .NET 1.1, the assembly and my project are both 1.1. I've contacted the author and waiting on a reply. The question I was asking more than what could be wrong with the assembly as I realise it is the assembly causing the problem is how that problem could cause my function not to be executed even before any calls are made to the assembly, I would expect it to fail at the point of referencing the assembly but at least execute the function calls above it.

                            Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

                            L 1 Reply Last reply
                            0
                            • _ __DanC__

                              It's not called MyObject, I just used that to demonstrate the problem ;) I would be equally unimpressed if it were :-D It is currently in .NET 1.1, the assembly and my project are both 1.1. I've contacted the author and waiting on a reply. The question I was asking more than what could be wrong with the assembly as I realise it is the assembly causing the problem is how that problem could cause my function not to be executed even before any calls are made to the assembly, I would expect it to fail at the point of referencing the assembly but at least execute the function calls above it.

                              Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

                              L Offline
                              L Offline
                              Luc Pattyn
                              wrote on last edited by
                              #17

                              __DanC__ wrote:

                              I would expect it to fail at the point of referencing the assembly but at least execute the function calls above it.

                              I understand that is what would be expected, but when you reach the Init() method, the first thing that happens is the JIT compiles it; so it wonders about the MyObject class, it must locate it, and at some point in time, also statically initialize it. I am not sure exactly when that is supposed to happen; it must be deterministic of course, and I know the exact order is surprisingly complex; long time ago I suffered from a bug in that area, dont recall whether it was in 1.0 or 1.1 tho. I think it is safe to assume static constructors get executed at the start of the calling method (your Init), since the JIT in general must cope with a complex flow graph and multiple references to the class, so it cannot always (and hence does not even try to) predict which one will occur first, hence it will go for early initialization. You could proof this true or false by pushing the MyObject stuff and following code inside Init() one level deeper... :)

                              Luc Pattyn [My Articles] [Forum Guidelines]

                              1 Reply Last reply
                              0
                              • _ __DanC__

                                The environment is Visual Studio 2003, .NET 1.1, Windows XP. The MyObject class is a third-party assembly containing lots of system calls, I understand that the problem could well be within the assembly and not my code and therefore out of my reach to fix but I would like to understand how a problem in a DLL assembly could stop the debugger entering the calling function, I could understand if it hung on the constructor of the MyObject class but I cannot see how it could hang on the calling function.

                                Chat | Text Messaging | Games | www.uzeddit.com - Coming soon!

                                H Offline
                                H Offline
                                Hesham Yassin
                                wrote on last edited by
                                #18

                                turn MyObject class to a static one, if you cannot, i think i had the same problem with DirectX, where i tried to identify a class which contains a directX identifications. it threw me a bizzar exception. and what i did is putting a breakpoint and run the program pressing F10, at first, it threw me an exception but thenit ran normally. try that. it's so fool but you don't encounter this exception in *.exe file!

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups