Java Access Bridge (JAB) - Cannot get valid response - c#

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).

Related

Working application launched from C# fails

I have C# application acting as a scheduler. It runs various applications successfully. One of these applications (VB6) fails halfway through the job. If I execute this VB6 application directly with the exact same parameters, it completes successfully. The scheduler runs other VB6 applications successfully. Does anybody know what could cause this? What in the environment changes when you launch an application (VB6 exe) from within another application (C#)? Maybe there is an expert that can point me to something to help solve this?
I am adding more logging to the VB6 application and currently the error points to a routine executing SQL commands, but I have other applications executing the same code with no problem. At this stage I am stumped.
The following might be different
user account / user rights
working directory
environment variables
I suggest inspecting the VB6 application with Process Explorer and comparing against a working version.
OK, I found the problem. I started by rolling back the VB6 code two versions and proved that it worked. I then added small pieces of the new code and checking every time if it still works. I did not add back all the code (some were just cosmetic) and it is now working with the new functionality. It has taken a LOT of hours and it will take a lot more to determine what caused the original error, so I decided to take the win, because I cannot afford more hours.

Debuging Excel VSTO differences between Development and Deployment

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.

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 is the ASP.NET/Visual Studio Web Development Server so slow?

(xkcd)
I know that compiling nowadays is much faster than it was before. Yet, for me, it seems that compiling and especially running/debugging ASP.NET projects with the Visual Studio Web Development Server is incredibly slow.
Since the beginning of last summer, I've been working heavily on ASP.NET MVC projects. Of course, the best way to debug them is by using the web server that comes with Visual Studio. When doing that, I get horrendously slow loading times. Chrome dev tools typically report that loading one of my pages had a 3 minute wait time, followed by a short loading time.
I've seen these two questions, but they don't help. While I do most of my debugging work in Chrome, the same happens in IE.
Has anyone else had this problem before? If so, any tips?
Also, I doubt that the problem lies with the speed of my machine. This computer is really fast running Windows 7 and Visual Studio 2010, so I don't see why ASP.NET debugging should be so slow.
UPDATE: In his answer below, Jon Skeet suggested attempting to identify whether the problem is being caused by the environment or by the code itself. I created a brand new MVC project and ran it. The first test appeared to be much faster. However, after testing it a few more times, it's safe to say that the first test was an anomaly - usually, it takes as long as my big project (2 - 3 minutes). Thus, this is a problem with the environment. Thanks in advance for any help!
UPDATE #2: It's been a while since I updated this question. Here are some details I've gathered since my last update:
This delay is occuring on both of my development machines, both running Windows 7 and Visual Studio 2010
This delay is happening for all my MVC2 and MVC3 projects (but I haven't experimented with plain ASP.NET yet)
Plain/vanilla MVC projects experience the same delay as MVC projects with big codebases
Disabling IntelliTrace did not help
Disabling IPv6 did not help
I haven't found a solution for this problem, so I've been stuck with huge wait times. Does anyone know how to solve this?
There's no reason why it should take 3 minutes to start debugging something unless you've got something really strange going on.
I suggest you launch the debugger, try to navigate to a page and then just break into the debugger while it's loading. See where you're losing time. Maybe you're making some call on startup which is failing, but taking minutes to do so.
I've never experienced anything like what you're describing, which suggests it's either in your environment or in your code - and if it's a generally fast computer, that suggests it's somewhere in the code.
If you create a brand new MVC project and debug into that, does that take a long time?
You might also want to run Wireshark when you start debugging - see whether something in your app is trying to fetch a network resource of some description without you realising it.
This is due to the IPv6 DNS problem within Firefox and can be fixed by setting the network.dns.disableIPv6 setting to true within the about:config
Slow DNS response - Firefox on localhost and Visual Studio or Cassini
This is actually a known performance issue with MVC, caused by throwing a ton of exceptions internally on startup. If you have IntelliTrace turned on, this will wreck havoc with it. Try disabling IntelliTrace and see if that improves it at all.
Source: http://connect.microsoft.com/VisualStudio/feedback/details/535799/debugging-mvc-is-very-very-slow
Check out if this helps:
http://blogs.msdn.com/b/mahuja/archive/2008/07/08/resolving-very-slow-symbol-loading-with-vs-2008-during-debugging.aspx
I met the same problem these days, working under Win7, VS2010, and developing a Silverlight solution with 10+ projects. It takes about 3 minutes to launch IE, and waits 3 minutes to get back VS after closing IE. I overcame the problem by trying different ways. But the only valuable method:
Unload all projects not for debug
Start debug the solution (it works normal )
Reload other projects
VS works normal here. (VS works normal)
It seems the problem is just related with the VS environment on my side. It has nothing to do with ASP.NET Development Server or IIS.
I was having the same problem. It ended up being a problem with ColdFusion being installed on my local machine (as painful as it is for me to admit). ColdFusion puts Handler Mappings named AboMapperCustom-* that were causing the latency. I uninstalled ColdFusion because I no longer need it (thank God). Another solution could be to remove each AboMapperCustom entry through the web.config. Example:
<handlers>
<remove name="AboMapperCustom-15397" />
<remove name="AboMapperCustom-20358" />
<remove name="AboMapperCustom-47286" />
</handlers>
Make sure the 5-digits following AboMapperCustom- match those in your local IIS Handler Mappings.
HTH
On Visual Studio 2012 + Win10 x64, i've noticed that if you
go to the taskbar and find the asp.net dev server there,
right click it and do a "show details"
close the box (NOT 'stop', just close via 'x')
then the server loads almost instantly

Categories