Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

MessageBox.Show in .NET 4 versus .NET 2

$
0
0

I have an odd problem with .NET COM interop where MessageBox.Show doesn't display the message box if I am using .NET 4. It works fine with .NET 2 (I am changing the setting in the VS 2012 project I have).

Background:

I have a .NET class object that I expose to COM. I have a COM MFC windows application that calls CoCreateInstance and then calls a method on the .NET object as the app is starting up (splash screen has displayed but frame has not yet displayed). I can step thru the code of my COM app and see that CoCreateInstance succeeds and so does the call to the method. I cannot debug the .NET code from the .NET project directly as my breakpoints never trip (they are enabled) when I am using .NET 4. So I put a message box call into the method I call when the COM app is starting up and one in the method I call when the COM app is shutting down. The latter method shows the box.

I have a UI that lets me release and restart the .NET object. Once I am fully up and running if I create the .NET object, the box shows. So this seems to be related to when I call MessageBox.Show. It appears that .NET 4 simply cannot display a window when I make the call? Why? Is there a windows subsystem that is not yet ready?

All I have to do to fix the issue of MessageBox.Show not doing anything is go to the project/application setting and choose .NET 2. rebuild and run and the box shows. But chaning to .NET 2 negates the reason I have the box. With the .NET 2 setting, all my breakpoints work fine. That is, I can debug the code by launching the COM app as the debug targeta and debug as normal.

I know one cannot debug two .NET frameworks at once. I can run my COM app in debug and before I call CoCreateInstance on the .NET component I can see that there is no .NET runtime loaded. It loads when I call CoCreateInstance. Hence I am also confused as to why the .NET 2 shows the box AND lets me debug fine while the .NET 4 setting allows neither.

A standard trick to debug .NET components is to add a message box and when it shows up simply debug/attachtoprocess and pick the .NET runtime I want to debug. But this inexplicable non-appearance of the message box has killed that ability when it comes to .NET 4.

What is the difference between .NET 2 and 4 when it comes to displaying a window? And what about the difference when it comes to debugging in this scenario?


R.D. Holland


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>