# Tuesday, June 29, 2010

Does your iPhone 4 go from full bars to no bars when you hold the lower portion? Disable the Bluetooth radio and you should see your recption return to (almost) normal.

Tuesday, June 29, 2010 6:37:00 PM (Alaskan Daylight Time, UTC-08:00)

A while back, I was tasked with solving a defect in our system. The defect was “Changes to an image can be reverted only one time.”

As I started to look into the code, I saw something like this:

  1. private Image _originalImage;
  2. private Image _image;
  4. public void Show(Image image) {
  5. _image = image;
  6. _originalImage = (Image) image.Clone();
  7. }
  9. private void Revert() {
  10. _image = _originalImage;
  11. }

Looking at the code, I suspected I knew what was wrong, but I wanted to confirm it. So I ran the app, made modifications to the image, clicked revert, made modifications to the image again, set a break point and clicked revert again. Once Visual Studio broke, I popped over to the immediate window and typed this:

Which returned: 0x1234abd0
Which also returned: 0x1234abd0

Now I knew what the issue was, the original image was getting clobbered due to a missed .Clone() on line 10. A simple _image = (Image)_originalImage.Clone(); fixed the issue.

.NET | C#
Tuesday, June 29, 2010 6:45:00 AM (Alaskan Daylight Time, UTC-08:00)
# Monday, June 28, 2010

The other day, Visual Studio 2008 kept crashing due to an issue with one of our user controls. When I opened a WinForm which contained the control, VS would initialize everything, get to an exception and crash. The exception was caused by the user control running code that it should not have in the designer. A quick search turned up this post on stackoverflow

  1. if (LicenseManager.UsageMode == LicenseUsageMode.Runtime) {
  2.   ...
  3. }

This code works in most scenarios, but failed for me. More searching turned up a post by Andre de Cavaignac

  1. public bool IsDesignerHosted {
  2.   get {
  3.     Control ctrl = this;
  4.     while (ctrl != null) {
  5.       if (ctrl.Site == null)
  6.         return false;
  7.       if (ctrl.Site.DesignMode == true)
  8.         return true;
  9.       ctrl = ctrl.Parent;
  10.     }
  11.     return false;
  12.   }
  13. }

I found that mostly worked as well. I ended up having to combine them to detect correctly 100% of the time if the control was designer hosted. I created it as an extension method, and here is the result

  1. /// <summary>
  2. /// Used to detect whether the control is being hosted on the surface of a form at design-time,
  3. /// since the DesignMode property no longer works once the control has been compiled and
  4. /// hosted on the surface of another design-time control.
  5. /// </summary>
  6. public static bool IsDesignerHosted(this Control ctrl) {
  7.   get {
  8.     while (ctrl != null) {
  9.       if (ctrl.Site == null)
  10.         return false;
  11.       if (ctrl.Site.DesignMode)
  12.         return true;
  13.       ctrl = ctrl.Parent;
  14.     }
  16.     return (LicenseManager.UsageMode == LicenseUsageMode.Designtime);
  17.   }
  18. }
C# | WinForms
Monday, June 28, 2010 5:45:00 PM (Alaskan Daylight Time, UTC-08:00)
# Sunday, June 27, 2010

After not blogging for over a year, I decided to get back in the swing of things and write more. I clicked on a link and got the dreaded 404. So I decided to investigate.

About 6-8 months ago I upgraded my server last year to Server 2008 and IIS 7. I checked that my blog loaded, but never checked any links. It turns out that IIS 7 be default blogs "+" in URLs because it can pose security issues. Well, all my blog post links have "+" in them. This broke things :(

After some digging, I figured out how to fix it. Add the following to your Web.config file
      <requestFiltering allowDoubleEscaping="True"/>

Sunday, June 27, 2010 4:02:31 PM (Alaskan Daylight Time, UTC-08:00)

Since I’m getting back into blogging, I figured I would make upgrade my version of DasBlog to v2.3, change the theme, and spruce things up! I hope all two of you enjoy the new look :)

Sunday, June 27, 2010 3:55:20 PM (Alaskan Daylight Time, UTC-08:00)
# Saturday, June 26, 2010

This morning I thought I would sit down with my Mac and play with doing .NET development for OS X. I had previously tried, but always found things to be really frustrating. All the Cocoa bindings were out of date, and the WinForms stuff looked terrible, etc. But Miguel wrote a blog post a while back indicating they are getting serious about developing a native solution for OS X.

I downloaded the experimental version of MonoDevelop 2.4 from Michael Hutchinson blog but quickly found out the experimental version of MonoDevelop (based on 2.4 RC 4) was out dated. So I upgraded to MonoDevelop 2.4, opened it, and noticed that MonoMac wasn't an available add-in in the RTM version of MonoDevelop.

So I did what any self respecting geek would do, I started digging around inside the bundle for the experimental version of MonoDevelop from Michael Hutchinson, and found the MonoMac addin hidden inside at the path MonoDevelop.app/Contents/MacOS/lib/monodevelop/Addins/MonoDevelop.MonoMac. I copied the folder to the appropriate place of the RTM version of MonoDevelop 2.4 and everything works as expected!

Download it

Download MonoDevelop, copy it to your Applications folder. then open the contents of MonoDevelop.app, and extract MonoDevelop.MonoMac to Contents/MacOS/lib/monodevelop/Addins/. Restart MonoDevelop, and now you should be able to create a new MonoMac project!


I missed two other files that updated in MonoDevelop.IPhone, download the new MonoDevelop.Addins.zip (490.49 KB) and extract it to the same place.

Saturday, June 26, 2010 3:02:05 PM (Alaskan Daylight Time, UTC-08:00)