Debuging Excel VSTO differences between Development and Deployment - c#

I just finished writing an update to a previous VSTO add-in to 2010-Excel. It has a ribbon customization including the launching of a windows form. On my development machine it works just fine and loads the form, but in the deployed version it doesn't work. It also doesn't throw an exception anywhere that I've been able to catch, and I'm at a loss as to what I could have done that prevents the window from loading.
With out a better idea, I started putting in break points and messages boxes:
Private Sub RibbonControlPanelButton_Click(sender As Object, e As RibbonControlEventArgs) Handles RibbonControlPanelButton.Click
Environment.SetEnvironmentVariable("VSTO_LOGALERTS", 1)
Environment.SetEnvironmentVariable("VSTO_SUPPRESSDISPLAYALERTS", 0)
MsgBox("1")
Dim cp1 As New ControlPanel
MsgBox("2")
cp1.Show()
MsgBox("3")
cp1 = Nothing
MsgBox("4")
End Sub
On this test I made it to "1", so the failing is in making a New ControlPanel which is my windows form. I tried putting a similar series of notes in
Private Sub ControlPanel_Load(sender As Object, e As EventArgs) Handles MyBase.Load
But none of them make it. Therefore I know that it's not even loading. How can get more info about what's going wrong? I can't see any exceptions being recorded anywhere. My previous version still works (cp1 is made and shown), but I've tweaked so many things I'd hate to go back to it to rebuild.
I was under the misconception that if it worked on in the development environment, it would work on a nearly identical deployment environment. Is there a way to make these merge? I feel like I could debug so much faster if I could interact with the problem in VS2012, but the moment I install VS2012, the thing works...

I figured out the answer on this. While I'm not qualified to officially call this a MS bug, it seems that way.
It kept failing to make the new instance of the Win. Form, but I wasn't getting any kind of error when I was trying to launch it from the Ribbon. I changed the start-up conditions for this workbook, so that it tried to make a new instance of the Win Form then.
That's when I got an error that PowerPacks 10 could not be found. Which seemed strange, because on my Clickonce deployment, PowerPacks 10 was listed as a prerequisite. It was further confused by the fact that had previously installed the "public" version of powerpacks here, which is version 3. Somehow that passed the check of the installer, but wasn't what was needed by the program. When I DL the version from the link in the installer, which is in fact version 10, everything worked.
I've double checked and found that v10 is listed as prereq, but for some reason, it wasn't getting caught by the Clickonce installer. I think the reason that my previous versions of the program worked but the current version didn't, was a use of different kinds of lines in my forms (of all the reasons!).
Hope this can save someone else the heart ache.

Related

Visual Studio C# Error creating handle but built app runs fine

I have a winforms app (>75k lines of source code), I have just added some new functionality and a new form and I'm getting the 'can't create window handle' error but only when running inside VS. The app builds OK and when i run it as the executable it is using 597 handles, 94 GDI and 83 USER and the new form works just fine apart from my logic errors in it. So as far as I can tell; my app is well below the 10,000 limit where things start to break therefore the problem is in/with VS somewhere but I may have hold of entirely the wrong end of the stick or possibly completely the wrong stick.
I have cleaned, rebuilt, rebooted etc and it stills falls over.
I'm using Process Explorer (thats where the previous numbers came from) but can't seem to find VS in there to check what its total handle count is.
VS2017 on Win 11.
Yes, I have googled it and explored things to look at but I can't find a result that matches 'Studio falling over but the exe running fine', any help / pointers very much appreciated as I obviously can't debug the new form which does make things somewhat difficult.
The underlying issue was to do with a pop-up form being generated by the parent form during its load processes, I found that the parent hadn't been issued a handle before it was trying to show the pop-up. Before you ask... I'm capturing data from a network sensor via the pop-up, which, once the user has accepted the incoming value, feeds the data back to the parent form. I assume that in run-time everything runs faster and it doesn't hit that 'un-coupled' point. Changed the code in the instantiate/load/shown cycle it runs and all is well.
Thanks once again Hans, headache solved.

Java Access Bridge (JAB) - Cannot get valid response

I'm aware of several existing questions on this topic, but they either don't have answers, or the answers don't work for me, so I'm trying again here.
I am attempting to use the Java Access Bridge API in a WinForms C# project. Both Java Ferret and Java Monkey work fine, which tells me that the bridge is installed and at least capable of functioning. However, when I try to run isJavaWindow() in my own code, it always returns false. I've tried other solutions that have recommended placing the Windows_run() code in the form constructor, but this has no effect for me.
It's worth noting that the code below DOES work for me on my home PC, but does not work on my work PC. It also works for a coworker, but only if he runs the executable directly - if he tries to run it from Visual Studio, it doesn't work there either.
Any help would be appreciated. I've been pulling my hair out over this for several days now, and have exhausted every possibility that I've come across in Google or elsewhere.
JabApi.Windows_run();
Application.DoEvents();
string windowName = "SwingSet2";
string className = "SunAwtFrame";
IntPtr hWnd = JabApi.FindWindow(className, windowName);
//This always returns false (0), even though it's pointing to a valid Java window
if (JabApi.isJavaWindow(hWnd)==1)
{
MessageBox.Show("Java window found!");
}
I'll answer my own question here.
The issue turned out to be that I was running Visual Studio as Administrator. When I tried running VS with normal privileges, the Java Access Bridge code immediately began working as expected.
The executable itself was running into a similar issue. When I previously ran the executable outside of VS, it turned out I was running it from a location with elevated privileges. When I moved the executable to a normal location, it worked as expected.
The isJavaWinndow() method also returns false if the Access bridge dll referenced has a mismatch with the application's bit version. Make sure to reference the 64-bit dll version for your 64 bit application (or 32 bit version if otherwise).

Anyway to deal with weird errors while my .net program running?

I made a program, which works fine on my PC without any errors, it also works fine on some office PCs, but it crashes without any describable error on customer's PC and some others.
Crashes are completely random, sometime it may crash and sometimes not.
Crashes are not related with any actions, sometimes it may crash when they just look at the program and wait for crash.
Customers send me this beautiful screens and want me to solve this.
There you see common error reporting dialog, but not info about Exception.
My program uses Unity Web Player running in WebBrowser control. It's always run in background on the hidden tab which becomes visible when needed.
Any ideas how to handle such errors?
I think you should first ensure that the environment at your place and that of your customers are identical.
Maybe there're dll or other programs installed at your place (Unity web player as you mentioned for example) or anything in your Registry that may differ.
Else there's no point in getting error on one PC and not on another.
Make sure all dll are well deployed
Check your registry,
Ensure that all related programs are well installed

"Unable to start program" error for web project

I have a Silverlight project that we use internally that I wrote - and since we've not had any need to work on it, it's been a while since I've opened the project. I opened it up this morning and everything is fine in terms of building, but whenever I try to debug I get the following error:
Unable to start program "http://mymachinename/mywebsite/index.aspx"
Of course, running it in Firefox works fine but no symbols are loaded. Running without debugging still throws the same error but IE loads up anyway...
Navigating to the website in IE works fine - SL app opens up, loads data etc etc, all looks good
I've Googled this all morning (usually quite good at finding info) and been through all the questions on SO and I can't figure out what's going on - there doesn't seem to be any messages in the event log, there are no messages in any VS output window, the w3wp just terminates immediately after starting (probably due to there being an error trying to open IE). I've tried reinstalling IE, cleaning/rebuilding, using local dev server, creating a new web project, turning on/off settings in IE9 etc etc
Nothing seems to make a difference - anyone got any experiences of this and has fixed it without doing one of the things I've already done? Any other suggestions?
Thanks in advance!
UPDATE
Just to be clear in case anyone asks - I get this problem when creating a new web project - i.e. everything I said I'd tried (above) didn't change the behaviour. It showed the same error no matter what I'd done so far (that includes a NON SL web project)
I've also tried attaching the debugger to w3wp that is running (the standard IIS process) and I can't seem to get it to debug (no symbols are loading), but that might be another issue altogether. I'm going to look at that next and maybe if I figure that out it might lead to fixing this issue
UPDATE 2
Debugging in Firefox works - I attached to w3wp with no success, then realising my stupidity (SL being a client side app!) I attached to the plugin-container.exe that FF runs its plugins in. This works. I can probably do the same for IE and just attach to IE, but why won't it start up from VS?! hair pull
UPDATE 3
Just in case anyone asks, the default browser is set to IE in VS. Also I've managed to debug by attaching to IE, it just won't start IE from within VS - annoying but I can live with it for now. If anyone does have a suggestion though, feel free...
For anyone's information in case they have this same problem, it ended up being that the port I was running my site on was also running a SharePoint site!
I created a new site on port 81 and used that for dev - not sure what setting on the other site caused the issue but it ended up working on port 81.

Why are button clicks slow in VS 11, and how to fix it?

Here is a simple test application (in F#, but I checked and the same problem occurs in C#):
let but = new Button(Content = "click me")
but.Click.Add(fun e -> printfn "clicked")
[<STAThread>]
do (new Application()).Run(new Window(Content = but))
When running this in VS 11 preview (no matter which .NET version), the "clicked" message appears ~0.5 seconds after clicking. The same happens in C#. When I go to the folder where the project is stored and run the .exe outside of VS then the message appears instantly after clicking. Apparently the debugging instrumentation is slowing this particular case down tremendously. Why is this and what can be done about it?
I cant say for sure, but my past experience with developer previews is that they have monitoring and tracing code that is running and submitting feedback to microsoft. This has caused slowdowns for me before in other previews (cant remember if button clicks were affected). You might submit feedback to microsoft though to ensure they know about it.
Or...
I don't have VS v.11, but similar bug happeneds in VS 2010.
Go to: Debug->Options and Settings->Debug->General, select: "Break when exceptions cross AppDomain...".
If debugger stops now on these exceptions, it means, that the old bug is not fixed. It's Visual Studio bug, so everything works fine when running .exe.

Categories