Results 1 to 14 of 14

Thread: Why are my VB.NET programs not working on Windows 7?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Location
    Massachusetts
    Posts
    205

    Question Why are my VB.NET programs not working on Windows 7?

    I do a lot of programming in VS 2010 on my Windows XP Pro PC. Recently I tried testing my software on a Windows 7 Home PC. For some reason, all of the controls on my forms are slightly misplaced. I also get a bunch of unhandled exceptions I don't get on my pc. For example, one exception said it couldn't access a registry key. Another said it couldn't find the part of a path (it didnt specify which path). What's up? Why is it doing this? My Win XP PC tricks me into thinking my apps are bug free. Guess not. Any response would be appreciated.

  2. #2
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Re: Why are my VB.NET programs not working on Windows 7?

    Are you doing WinForms or WPF development?

    -Max
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

  3. #3
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485

    Re: Why are my VB.NET programs not working on Windows 7?

    Just wanna share my experience which is similar to yours, where my development OS was WinXP + dotNET 2.0 and I had my program running in Win7 for the first time.

    Everything seems to work fine except for 1 minor thing, which was related to multimedia. I used the Windows Media Player object to playback my sound and somehow, the volume control in my program was not executed properly, hence I was not able to set the volume to zero (a way to mute it aside from setting it to mute. It was a workaround I used cause mute = true doesn't meet my requirements, somehow.)

    Perhaps it was WPF development since it's reliant on DirectX.

  4. #4
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: Why are my VB.NET programs not working on Windows 7?

    Quote Originally Posted by RadXPictures View Post
    I do a lot of programming in VS 2010 on my Windows XP Pro PC. Recently I tried testing my software on a Windows 7 Home PC. For some reason, all of the controls on my forms are slightly misplaced. I also get a bunch of unhandled exceptions I don't get on my pc. For example, one exception said it couldn't access a registry key. Another said it couldn't find the part of a path (it didnt specify which path). What's up? Why is it doing this? My Win XP PC tricks me into thinking my apps are bug free. Guess not. Any response would be appreciated.
    Most of these can't be resolved without knowing how you're doing what you're doing.

    Displacement is most likely due to screen resolutions. Anchor and dock your controls.

    Not being able to access specific registry keys is most likely due to UAC access. If you're writing keys for your app, write them in HKCU. If you're accessing keys in HKLM, you'll need to prompt for UAC access.

    The path problem depends on what you're doing.

    Again, we need to see how you're doing these things to solve them. There's not a one button solution to fix these issues.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Location
    Massachusetts
    Posts
    205

    Question Re: Why are my VB.NET programs not working on Windows 7?

    Quote Originally Posted by Max Peck View Post
    Are you doing WinForms or WPF development?

    -Max
    Yeah I'm using WinForms. Idk... I thought that Win7 was in the same resolution. One big question tho is I kept getting the error, "The form referred to itself during construction from a default instance, which led to infinite recursion." What does this mean? I don't get it on my XP machine..

  6. #6
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: Why are my VB.NET programs not working on Windows 7?

    Quote Originally Posted by RadXPictures View Post
    Yeah I'm using WinForms. Idk... I thought that Win7 was in the same resolution. One big question tho is I kept getting the error, "The form referred to itself during construction from a default instance, which led to infinite recursion." What does this mean? I don't get it on my XP machine..
    The resolution has nothing to do with the OS. Well, not inherently anyway. It has to do with what the resolution for each monitor is set at. But if if you anchor and dock your controls, you'll be fine.

    As for the error, we're not going to get anywhere if we don't know how you're accomplishing your tasks.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  7. #7
    New Member
    Join Date
    Apr 2011
    Location
    India
    Posts
    8

    Re: Why are my VB.NET programs not working on Windows 7?

    Quote Originally Posted by Max Peck View Post
    Are you doing WinForms or WPF development?

    -Max
    i am using win forms!!

  8. #8
    New Member
    Join Date
    Apr 2011
    Location
    India
    Posts
    8

    Re: Why are my VB.NET programs not working on Windows 7?

    Quote Originally Posted by RadXPictures View Post
    I do a lot of programming in VS 2010 on my Windows XP Pro PC. Recently I tried testing my software on a Windows 7 Home PC. For some reason, all of the controls on my forms are slightly misplaced. I also get a bunch of unhandled exceptions I don't get on my pc. For example, one exception said it couldn't access a registry key. Another said it couldn't find the part of a path (it didnt specify which path). What's up? Why is it doing this? My Win XP PC tricks me into thinking my apps are bug free. Guess not. Any response would be appreciated.
    yeah you write!
    that hapen with me and my bruteforce program gave 20 errors similarly.. but i already made a backup before!! so i got it back.

    alot bugs on vb 2010

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Why are my VB.NET programs not working on Windows 7?

    Quote Originally Posted by RadXPictures View Post
    Yeah I'm using WinForms. Idk... I thought that Win7 was in the same resolution. One big question tho is I kept getting the error, "The form referred to itself during construction from a default instance, which led to infinite recursion." What does this mean? I don't get it on my XP machine..
    You didn't change the code any? This one seems to occur when you tinker with some of the initialization code to access a control directly during construction. I have never seen it myself, so I'm not certain about the cause, it just appears to come from that based on questions people have posted here.
    My usual boring signature: Nothing

  10. #10
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Why are my VB.NET programs not working on Windows 7?

    I'm not going to venture a guess as to why it works on XP and not Windows 7. The answer is probably something far beyond your control like, "The 32-bit JIT generates the instructions in this order, while the 64-bit JIT generates them in this order." You've got an error message that describes the problem, and fixing the problem will be more productive than figuring out why it happens. I don't know why everyone ignores error messages when they are posted; they describe what's happening in detail!

    Here's the error message again:
    "The form referred to itself during construction from a default instance, which led to infinite recursion."
    I've seen this before. It's easy to fix, but only if you know what it is.*I'm going to discuss all of the concepts.

    First, what is "infinite recursion"? Recursion is a situation where a method calls itself. It's a form of looping that can be useful for creating simple solutions to certain problems. For example, this is a recursive method for postorder traversal of a binary tree:
    Code:
    Sub PrintTree(ByVal currentNode as TreeNode)
        If currentNode Is Nothing Then
            Return
        End If
    
        PrintTree(currentNode.Left)
        PrintTree(currentNode.Right)
        Console.WriteLine(currentNode.Value)
    End Sub
    It doesn't matter if you don't know what a binary tree or postorder traversal is. The important part is to note how PrintTree() calls itself. You might expect this to make an infinite loop, but this algorithm ensures recursion will stop eventually. Eventually, a node where Left and Right are Nothing will be reached; in that case PrintTree() doesn't call itself and the recursion ends.

    Sometimes recursion isn't so obvious. You're going to have to understand a bit more before the error message can be explained.

    What's the "default instance" mentioned in the error message? If you ask someone and their answer doesn't involve profanity to the tune of "the worst idea ever" you should consider that programmer a poor source of advice in the future. It's that bad. In 7 years of activity on VB .NET forums, I have *never* seen a post with a code snippet that included a default instance where the default instance wasn't the problem.

    The VB .NET compiler automatically generates a property for every form you add to your project. This property is called the "default instance" of the form. It's easy to see why it was introduced to help beginners; compare code that uses it to code that doesn't:
    Code:
    Public Sub ShowOptionsDialogWithDefaultInstance()
        OptionsDialog.Show()
    End Sub
    
    Private _optionsDialog As OptionsDialog
    Public Sub ShowOptionsDialog()
        If _optionsDialog Is Nothing
            _optionsDialog = New OptionsDialog()
        End If
    
        _optionsDialog.Show()
    End Sub
    The default instance ensures an easy way to reference a form and get an instance of it if one doesn't exist. Unfortunately, there are many situations where it does something you might not expect. You're in one of them. The default instance is implemented much like the code above:
    Code:
    Public Property OptionsDialog() As OptionsDialog
        Get
            If _somePrivateOptionsDialog Is Nothing Then
                _somePrivateOptionsDialog = New OptionsDialog()
            End If
    
            Return _somePrivateOptionsDialog
        End Get
        Set(ByVal value As OptionsDialog)
            _somePrivateOptionsDialog = value
        End Set
    End Property
    I can think of at least 5 ways to get yourself into trouble with this, but I'll focus on the one that leads to infinite recursion. You now know enough to understand why the recursion's there.

    Somewhere in the code that creates your form, you reference the default instance. It could be something really obvious, like in your own Sub New():
    Code:
    Sub New()
        InitializeComponent()
    
        Form1.Text = "I am form 1"
    End Sub
    Let's focus on that. Suppose it's called from code like this:
    Code:
    Form1.Show()
    How does recursion happen? Let's think about it. From the start, Form1 is nothing. So here's the process we go through; lines that start with "*" are the compiler's thoughts:
    Code:
    Form1.Text = "I am form 1"
    * I need to assign a string to the Text property of Form1. What is Form1?
        * Ahh, it's a property. I'll call Get_Form1():
            If _somePrivateForm1 Is Nothing
            * Yep, it's Nothing.
                _somePrivateForm1 = New Form1()
            * I need to call the constructor, I'll call it:
            Sub New()
                ...
                Form1.Text = "I am form 1"
            * I need to assign a string to the Text property of Form1. What is Form 1?
                * Ahh, it's a property. I'll call Get_Form1():
                    If _somePrivateForm1 Is Nothing
                    ...
    There you go. Calling the default instance property tries to construct the form, but since the constructor *also* calls the default instance you end up in a loop. The best part about this problem is with a little more work you can create code that works sometimes and fails others; this is an even worse trap. The most merciful thing the default instance can do to you is fail instantly so you can blame it right away.

    It's your job to figure out where along the creation of the form you end up calling the default instance. Replace the form name with "Me" in that case. Better yet, when setting a property *never* use the default instance *ever*. It will just lead to you asking "Why doesn't my textbox change?" later. Even better, *never* use the default instance. It is a snare that entangles and confuses new developers. It looks easy and for very simple scenarios it will work, but when you make a tiny mistake you cause problems that it takes an expert's understanding to decipher. It is a very foolish feature and you can thank the wailing and crying from VB6 users for Microsoft's decision to unleash this mistake upon a new generation of developers. I feel this decision was as irresponsible and led to as many consequences as offering heroin to a ten-year-old.
    Last edited by Sitten Spynne; Apr 11th, 2011 at 10:50 AM.

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Why are my VB.NET programs not working on Windows 7?




    That whole post is excellent. I now see why I have never encountered the error first hand, as I never used the default instances (except, technically, the startup form, I suppose). However, I must caution people to ignore this one incorrect statement:

    Quote Originally Posted by Sitten Spynne View Post
    What's the "default instance" mentioned in the error message? If you ask someone and their answer doesn't involve profanity to the tune of "the worst idea ever" you should consider that programmer a poor source of advice in the future.
    Profanity is not an essential component when on a forum such as this one where profanity is censored out. Of course, the more eloquent members will come up with a phrase dripping with disdain, as can be seen at the end of that post. I almost went off on such a rant, too, but avoided it this time.
    My usual boring signature: Nothing

  12. #12
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Why are my VB.NET programs not working on Windows 7?

    Eh, it was hyperbole meant to imply that people who know what they're doing understand how difficult it is to *not* get in trouble with a default instance. Using default instances is walking through a minefield with a blindfold on. It's not hard to avoid their use, and when the solutions that don't use them fail it's easier to diagnose what's wrong. Anyone who learned it the hard way probably has colorful thoughts about what should happen to the guy that invented them. On the other hand, anyone suggesting their use probably includes the phrase "GIT R DONE" in their description. At least that's what my mind adds

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Why are my VB.NET programs not working on Windows 7?

    You, sir, are on a roll today!
    My usual boring signature: Nothing

  14. #14
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Re: Why are my VB.NET programs not working on Windows 7?

    Quote Originally Posted by loverboy4u View Post
    alot bugs on vb 2010
    I'm using VS2008 and see no reason to upgrade. I've used it in all 3 recent environments (XP, Vista and 7). Unless they come out with some "gotta have it feature" that I just can't live without my product will be based on it for quite awhile methinks.

    -Max
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width