Saturday, November 11, 2017

Guest OS Web Server Access

In the latest project in my new role, I am developing with Angular 4/5 on Windows 10 hosted within Parallels on a Mac. Yes, I have a Mac now. What is the world coming to?
I needed to test some new functionality of the web app in a variety of operating systems and browsers. I figured it shouldn’t be too difficult to access the web server on the Guest OS, since the Apple mantra has always been “it just works”. Unfortunately, it didn’t just work.
There are numerous entries in the search results about trying to access the web server on the Host OS from the Guest OS, but I needed to do the opposite. I need to access the web server on the Guest OS from the Host OS. I eventually pieced together the following steps, in case you run into the same issue.

Bridged Mode Networking

To make it easier to access the Guest OS web server from not just the Host OS, but other machines, I enabled “Bridged Mode” networking for the Windows 10 virtual machine. The Windows box now gets an IP address directly from my LAN instead of being NATed through the macOS Host.

Open Port in Firewall

The application is being served on a non-standard port for HTTP, so I had to open that port in the Windows 10 firewall settings. The port to open will depend on the settings for your project.

Listen on All Interfaces

By default, Angular only listens on the localhost interface (see host option for ng serve). This may be due to the fact that in Windows, localhost is a separate network interface, but this means that, at least in Windows, Angular will not receive requests from other machines – including, but not limited to, the Host OS. I added “--host” to the ng serve command for the app to force Angular to listen on all network interfaces.


I can now access my Windows 10 Guest virtual machine from the macOS Host to test in Safari. More than that, I can also access the Windows 10 VM from other devices on my LAN including my phone for testing in a mobile browser.
If this helps you or if you have additional troubleshooting tips, leave a comment below.

Friday, November 10, 2017

A Recap

First, let me address the elephant in the room…yes, it has been quite some time since the last post. Since this is not primarily a lifestyle blog, I will not go into details, but instead offer a high-level recap. Over the past 5 years I became lead of a support team, went through 2 corporate reorganizations that involved significant team changes, moved to another city, transitioned to full-time telecommuting, and then, most recently, changed jobs.

Which brings me to today. My intent with this blog was to provide a scratch pad of issues I run into with the hope of helping others that may also be having the same or a similar problem.

In my new role, I will be creating new software rather than supporting and maintaining software that someone else wrote and I will be using newer technologies. As such, I will be back to encountering new problems to solve which means that I may be posting on a more frequent (though not necessarily regular) basis.

Monday, January 14, 2013


In working on some websites for friends, I found a need for a fairly simple CMS. These sites are mostly just collections of static content that needed a common look-and-feel. Because of the mostly static nature, I didn’t feel that a heavyweight CMS was worth the effort.

Instead, I reinvented the wheel and wrote my own. It is available as an open-source project on GitHub.

Saturday, June 30, 2012

Output Buffering and Default Settings

I recently needed to set up a new development system with Apache and PHP. The last time I configured these two programs was when PHP was at 5.2.x and the ZIP file included a php.ini-development. The most recent version of PHP is 5.4.4 and does not include a php.ini-development.

The PHP application being developed on this system offers a setting for compressing the output for client browsers that support compression. When I turned on this setting, I received this error:

ob_start(): output handler 'ob_gzhandler' conflicts with 'zlib output compression'

Nothing had changed in the PHP application. The only thing that changed was the PHP version. If I were a little less experienced, I may have thought that I found a bug in the latest version of PHP. Instead, I figured that either something had changed in the API and my implementation had been incorrect from the start, or I had something configured wrong.

I compared the php.ini from the old 5.2.x with the php.ini from 5.4.4 and found a difference in the output_buffering setting.

In 5.2.x, the php.ini-development has output_buffering set to Off. In 5.4.4, output_buffering is set to 4096. I set output_buffering to Off and I am no longer receiving the error.

Thursday, May 31, 2012

.NET Exceptions and Performance

I had an application that was performing very poorly under a fairly heavy load out in the real world. It got me thinking about doing more performance testing, both within a profiler and under simulated loads. The profiler pointed out some key flaws in the code that were quickly dispatched, but the problems still remained.

I enlisted some help to simulate more realistic loads and really stressed out the application and I started getting errors that I shouldn’t have been getting. So I thought. The code that was generating the errors wasn’t thread-safe. In an effort to reduce the number of error emails I was receiving, I surrounded the offending code with SyncLocks and the errors stopped.

A side benefit was that the performance issues went away. It was then that I discovered that exceptions can cause some performance hits due to the extra objects required.

So, if you can help it, minimize exceptions (I could in this case) and watch for thread-safety in code that may be run with multiple threads.

Thursday, March 15, 2012

Unshelving with Merge Conflicts

My team at work uses mercurial for source control. One of the concepts in the mercurial is a “shelf” where you can place partially completed work while you take care of synchronizing your local repository with another repository. You don’t always have to place items on the shelf, but some operations in mercurial require a clean local repository.

A coworker recently placed some items on his shelf and then synchronized his repository. When he went to “unshelve” his changes, there was a conflict. The (redacted) error text read “Unshelve Abort patching file <filename.ext> Hunk #<number> FAILED at <number> <number> out of <number> hunks FAILED – saving rejects to file <filename.ext>.rej”. He had been working on one of the files that had also been updated during the synchronize. Technically, the original shelving operation was unnecessary as mercurial is intelligent enough to merge conflicting files. The shelving was done, however, and he still needed his changes that were on the shelf.

The ultimate solution was the revert the repository back to the point of the shelving, then proceed with the synchronization without shelving.

There may be another way to tell the shelf that the conflicts have been resolved and it can continue (like with hg transplant --continue). If you know of a way to do this, feel free to let me know.

Friday, December 23, 2011

Appending elements while iterating an XMLNodeList

In a unit test, I had created a populated XMLNodeList and wanted to make sure that the elements were added in a certain spot within the (same parent) XMLDocument after the code under test was finished. I don't remember many of the minute details, but the code would iterate the XMLNodeList and copy the node to the document. The iteration kept failing, however.

After stepping through the code in debug mode, I found that the original XMLNodeList would get emptied out while iterating. If you want to keep the XMLNodeList intact, you need to clone the current node and push the clone into the document.

Wednesday, December 21, 2011

ASP.NET UpdatePanel and PageRequestManagerParserErrorException

I have a page that contains an UpdatePanel that gets updated every 2 seconds to poll for information from the server. With a certain combination of the application running, the UpdatePanel would not refresh in Internet Explorer, but worked fine in Firefox. I finally tracked it down to the UpdatePanel throwing a PageRequestManagerParserErrorException when the data was coming back from the server. There is plenty of information out there about common reasons why this exception is thrown. However, none of those suggestions are valid for my particular need, which is why I can post about it here.

The data coming back from the server included non-displayable characters. Firefox handled this gracefully by displaying a little glyph in the place of the non-displayable characters. Internet Explorer choked on the non-displayable characters. Since I have some control over the data that gets sent to the view, I intercept the non-displayable characters and change them to ‘?’. Now both Internet Explorer are handling the refreshing correctly.

Thursday, November 17, 2011

XML Elements From Different Documents

A coworker and I were working on a feature that required manipulating XML through the .NET XML DOM. Per our standard operating procedure, we were using test-driven development. We were updating an existing piece of code to do something different so we were working within an existing design that made use of direct calls to the XMLDocument object.

We went through a few iterations of red, green, refactor and finally arrived at an implementation that should have worked. Our test had an instance of XMLDocument that was creating nodes that we were sending into the code. But the code had its own XMLDocument that it was using to build the final XML structure. We kept getting an error with the message "The node to be inserted is from a different document context."

After searching around, we eventually found that the XMLDocument is very selfish in which nodes it allows to be added. If you attempt to add a node within an instance of XMLDocument that was not the originating instance of that node, you will receive the same error.

The solution in our case was to pull the XMLDocument instance creation out of the piece of code under test and pass it in as a modifiable parameter.

Thursday, July 7, 2011

Redirecting to Different Controllers in ASP.NET MVC

Last year, we started using ASP.NET MVC at work and are still learning its intricacies. About a month ago, I needed to put in a button that redirected to another part of the application. I have sanitized the details because they aren't germane. The button was located on a page controlled by a different controller than the page I wanted to redirect to. I tried the following 3 incorrect snippets before seeing the error, which is corrected in the last snippet.

<HttpPost()> _
<ActionName("Index")> _
<HandlesButton("redirectingaction")> _
Public Sub RedirectToOtherController()
End Sub
<HttpPost()> _
<ActionName("Index")> _
<HandlesButton("redirectingaction")> _
Public Sub RedirectToOtherController()
End Sub
<HttpPost()> _
<ActionName("Index")> _
<HandlesButton("redirectingaction")> _
Public Sub RedirectToOtherController()
  RedirectToAction("NewAction", "OtherController")
End Sub

Can you spot the difference? Some of our MVC actions perform operations on the server with no need for a return value. But the redirect needs a return value to switch views. So I needed to have a function with a return statement.

<HttpPost()> _
<ActionName("Index")> _
<HandlesButton("redirectingaction")> _
Public Function RedirectToOtherController() As ActionResult
  Return RedirectToAction("NewAction", "OtherController")
End Function