• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1786
  • Last Modified:

Application.EnableVisualStyles(); throws exception

Hi,

I have a winform app, it uses MDI, when I try and run the app exe manualy - not using vs2005 debuging,
it crashes out in the main method whn it reaches Application.EnableVisualStyles();

'$exception.Message' threw an exception of type 'System.OutOfMemoryException'

I am using 2 external ddls but these work fine in the debug environment and i dont think this is the issue(the are only called later in the app...

thanks
0
deanvanrooyen
Asked:
deanvanrooyen
  • 10
  • 9
  • 6
  • +1
2 Solutions
 
topdog770Commented:
0
 
topdog770Commented:
Here's the same information, basically

http://www.kbalertz.com/Feedback_897298.aspx
0
 
deanvanrooyenAuthor Commented:
thanks!
still get an error, I tried the manifest and it didnt work, then tried

      Application.EnableVisualStyles();
      Application.DoEvents();
error:
SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.

this is weird, it works when i run debug within vs2005

the only thing here is that solution you put in the links is for an error:
'System.Runtime.InteropServices.SEHException'

mine is
OutOfMemoryException

I have googled for 20 minutes without luck...

I have an mdi form with a toolbox that has loads toolStripButtons with images and I think that this might be causing the issue..
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
topdog770Commented:
Are you calling Application.EnableVisualStyles() before Application.Run ?

It seems like calling the visual styles before everything else is important...  

Oh! I've seen something before where enabling the visual styles messed with the images I had assigned to a toolbar... can't recall the what or why.. at the moment...
0
 
topdog770Commented:
Have you already seen this posting?

It claims memory issues using EnableVisualStyles and Application.DoEvents

http://www.dotnet247.com/247reference/msgs/44/220711.aspx

0
 
davidlars99Commented:
just an addition to this thread - EnableVisualStyles() has always had issues on my PC... no matter what trick I use!
0
 
topdog770Commented:
For some reason, I can't get it to fail now.. still very simple dialogs, but order doesn't seem to effect it at all.

0
 
deanvanrooyenAuthor Commented:
hi topdog

this is my prorgam.cs file

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Cross_Contry_Inspections
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Cross_Contry_Inspections.UI.Forms.MDIMainParent());
        }
    }
}

standard stuff, thanks for your imput and it has pointed me into some more or right direction - I will th epost open for a bit longer to see if any else knows how to solve this is issue otherswise I will allocate the points accordingly
0
 
topdog770Commented:
Does it work for you the way is it?

If not.. what happens if you create a new form and do something like Application.Run( new Form1()) ?  

I'm guessing ( no great brain wave here ) that it's something specific to form you are using, the MDI, etc etc

It'd be great if we could eliminate suspects and figure out what is causing the problem, save lots of us more future headache  too :)
0
 
vo1dCommented:
under which os are you working?
and which productversion has your comctl32.dll in Windows\System32 folder got?
0
 
vo1dCommented:
and one more question, what happens if you create a clean new windows app with a blank form?
still got the exception?
0
 
deanvanrooyenAuthor Commented:
hi topdog770  and vo1d


just tried it with a blank form with 1 lable controll - this is fine and no error!!!

I am going to investigate a bit more and post back up, thanks for this bit of sense

my system VS 2005, windows xp home :(
comctl32.dll - 5.82.2900.2180

thanks
0
 
deanvanrooyenAuthor Commented:
just as a quick mention,

how can EnableVisualStyles error out when it it called before my Application.Run is called
               
                Application.EnableVisualStyles();
               
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Cross_Contry_Inspections.UI.Forms.MDIMainParent());
                //Application.Run(new Cross_Contry_Inspections.UI.Forms.Test()); //this works ok
0
 
vo1dCommented:
i think, the error is in your mdimainform, not in the EnableVisualStyles() method.
when is the exception thrown, on Application.EnableVisualStyles(); or
Application.Run(new Cross_Contry_Inspections.UI.Forms.MDIMainParent());
?
0
 
topdog770Commented:
one to thing to check.. make sure your code isn't calling enablevisualstyles from any where else
0
 
deanvanrooyenAuthor Commented:
hi,

I ran through it,

the Application.EnableVisualStyles();  for some reason calles the MDIMainParent()  InitializeComponent();

I then used a message box in MDIMainParent.Designer.cs to check every line to see where it was crashing,
afterthe check this is the line that is causing the problem:
            this.newToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("newToolStripMenuItem.Image")));
           
any idea?
0
 
vo1dCommented:
remove that image from teh resource file and set the Image property of newToolStripMenuItem not to any image.
does your form works then?
if so, select the image you wanted again and start the application.
0
 
deanvanrooyenAuthor Commented:
if I comment out the line
this.newToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("newToolStripMenuItem.Image")));

it runs ok untill it hits the next menu item image - so I geuss if I remove all the images from the menu items it will work but this is not my desrired solution

in the CLR debugger this is the error thrown by the line by the designer.cs of the mdiparent :
this.newToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("newToolStripMenuItem.Image")));

error:
CLR debugger

An unhandled exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll

            Source      "mscorlib"      string
+            StackTrace      '$exception.StackTrace' threw an exception of type 'System.OutOfMemoryException'      string {System.OutOfMemoryException}

+            TargetSite      {System.Reflection.Assembly nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.Assembly, System.Threading.StackCrawlMark ByRef, Boolean, Boolean)}      System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}


-            Non-Public members            
            _COMPlusExceptionCode      -532459699      int
            HResult      -2147024882      int

My question is also why do i not get the error in while running it wthin VS2005 degug?
0
 
topdog770Commented:
Hmm... the easiest part first:  The debugger is more lax about its memory management and loosely packs things.

The release or non-ide driven exe has significantly tighter boundaries.

0
 
vo1dCommented:
maybe because you have setuped to run that app in the vshost process?
remove all your image, make a clean, rebuild your solution and then select again your images you need.
that application, was it a fresh new build of vs2005 or did it come from vs2003?
0
 
deanvanrooyenAuthor Commented:
it a fresh new build of vs2005

I removed the first image, then set a different image and it still crashed out
0
 
vo1dCommented:
maybe your resurce file is corrupted.
can you remove all images and just insert 1 for a first try?
0
 
topdog770Commented:
I haven't come up with anything more definitive yet, either.  

I've seen some code samples that demonstrate memory leaks with the resource components.. but haven't found a direct link between enabling visual styles and resources.

In your code, what is resources? and how are you adding the images.. can you post the relevant code snippets?

I've created a small mdi app, and using an embedded image via GetManifestResourceStream there doesn't seem to be a problem.  I'm thinking we may have narrowed things down to some issue between where / how you are pulling in the images and the additional layer of activity caused EnableVisualStyles
0
 
deanvanrooyenAuthor Commented:
hi,

I have moved the full project onto another machine and manualy run the exe from the debug directory and it is fine, this means that I am only getting the issue on my dev pc when i run  the exe by double clicking it manauly. the dev pc is win xp home, 512mb intel celeron. my other pc is a laptop, xp pro 1 gb ram.

please remember that this error that is crashing it out is not realy from me adding images - i added a menu strip to the form and it is the default file > new button's image.

this.newToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("newToolStripMenuItem.Image")));

I have searched for newToolStripMenuItem and it pops up in mdimainparent.resx which looks like an xml file -  it is rather large but this is the code for newToolStripMenuItem.Image

  <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  <data name="newToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
    <value>
        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
        YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAYZJREFUOE+tk1sz
        QmEUho3xl/wIv8NPceHCHRpnSckhxw5ToUiUXRmVZCqko3albKXax1d7m+z2GDJ4Z9Z8F9+sZ613re/r
        6/urlnbOsGL2QW/xS6fOREBr9EKz64F6242FTRfmNo4ws+bAlP4AKp0dk1obJpatkGprjef4jQaHht8B
        K2aiZz4vCGgxPOh21Jos4ukKPgA/6aADeGkwKFdbSoA4g44G+gfQK+IpCqFEUe5g3uD60gLLCWi2WDzX
        aJCVBlKFGkSAJ5SXAdOrDgnQq3L3/b73QQaIa+mWwAM0y6Pe9vtE0ciXGrjP1RBNVnEZK+M8UsSWIyED
        xH12xPPCt514wiSOL/LQmKKfAZzol+ZA1RkUq01kyDoSGQqRuwoCNyWchUg4A4+we3NQrYeVAK5duSEN
        i5GHlaYQvn2CP1qCO1iA05+HzZuF6TSDMc2FEvDyyrT9kSAiBZxcZnFIpGBxJyWvemsM6r1rTBuuMK4P
        YnQxgJFZnxIgvqrfxF//4f/kvwF500+ahhL/CwAAAABJRU5ErkJggg==
</value>


thanks for your help so far
0
 
deanvanrooyenAuthor Commented:
i have had no luck but the points are split for effort...
0
 
topdog770Commented:
Thanks, dean.. I wish we'd been able to provide more direct assistance.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 10
  • 9
  • 6
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now