tags:

views:

1289

answers:

3

Hey Everyone, I've run into a bit of a nutty issue.

For this Window:

<Window x:Class="Host.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowStyle="ToolWindow" Top="-5000" Left="-5000" Width="0" Height="0"
        ShowInTaskbar="False"
        Loaded="Window_Loaded"
        />

The "Cannot set Visibility or call Show or ShowDialog after window has closed." Exception is being thrown between the .ctor, and Window_Loaded. This Only happens when it is run stand alone, not with VS. the .ctor is as follows:

    public MainWindow()
    {
        InitializeComponent();
        MessageBox.Show("1");
    }

The Exception does not occur when the MessageBox is not there, the app just closes right after start up if it is not there, but it still doesn't make it to the Window_Loaded handler. It doesn't throw any exceptions from my code, it's coming from the app trying call Window.VerifyCanShow() from PresentationFramework.dll.

Any Ideas?

A: 

From the exception that you posted, somehow somewhere the window is being closed. I can't tell from the code that you posted.

Once a window has been closed, you have to re-allocate it to "show" it again. you can hide it and then show it again w/o any problems, though. I am sure there is a good reason for this, but darned if I know. Anyhow, that is what the exception is yelling about.

It could be your Left and Right positions that make it close (-5000 pixels) in combination with your width and height (0 pixels).

Muad'Dib
I'm not closing/hiding any windows, this happens before the main window even shows.
scmccart
A: 

I suspect something might be wrong with your Main method. It is usually found within Program.cs. Post it so we can see if anything is wrong there.

configurator
A: 

No, the whole problem was me being really, really stupid. My singleton code was seeing the VShost.exe running when I had VS open, and killing the app.

scmccart