Hot New iPhone Game – Gem Shock

 

title

For those of you that come to our blog regularly, you would know that we have never done a game review before. This isn’t because we don’t game or because we have anything against game reviews themselves, but it is more because games are usually so well covered by other sites that anything we would say would be totally redundant.

It is with pleasure, however, that I bring our readerships attention to a great new game that I have heard about and been playing.

Gem Shock is one of those extremely simple but yet extremely addictive games. It really reminds me of Tetris in its sheer simplicity and potential for addiction. It is great.  Manoeuvring your Gem through the electrified walls while pushing yourself to race against the clock and fighting to get that steady hand you need to win  really is stupefyingly fun!

The game is only $0.99 and is a hoot. Check it out on the itunes app store today and have a go at it…I sure haven’t regretted my purchase!

Here’s a link for the so inclined – Gem Shock:

http://itunes.apple.com/us/app/gem-shock/id463681052?mt=8

DNS Issues with Server 2008 R2

RFC 2671.  This shouldn’t mean much of anything to most of us. This RFC Code, however, can literally mean hours and hours of frustration and troubleshooting if you have created a Server 2008 R2 domain.

Developed in 1999, Extension mechanisms for DNS aka eDNS, were designed to allow for increased functionality of the DNS protocol. They were also critical to the implementation of DNS Security Extensions (DNSSEC). Nevertheless, the protocol hasn’t really caught on and there are still thousands of devices – even ones produced today – that are not really fully compliant with the standards laid out in RFC 2671.

Naturally, the Internet itself is a inter-connected network that is literally running on loads of old and obsolete equipment.  So, it comes as no surprise that there are going to be a few problems arising from the fact that Windows Server 2008 R2, when set up as a DC with the DNS role installed and set to perform recursive lookups, has this extension to DNS enabled by default.

Not everyone, fortunately, will have issues with this as there are of course DNS servers out there that will respond properly to this type of query and respond with the IP address requested. However, if you happen to be running DNS queries against one that is non-compliant, you will end up with extremely patchy Internet service for your whole domain.

To check if this is an issue for your domain, you are going to have to run a few tests.

Open network monitor, and look at the DNS queries that you are getting. If they look like the picture below, you are probably encountering this issue.

dnserror

The fix, luckily, is very simple.  Simply disable eDNS and re-enable it at some point in the future when acceptance of this protocol is a little higher.

Open up a cmd prompt and elevate it (right click on it and run it as an administrator). Then run the following command.

dnscmd /config /EnableEDNSProbes 0

This should take effect immediately.

I sincerely hope that this helps a few of you out there that are just starting to deploy Server 2008 R2 now that SP1 is out.

Cheers!

Matt

Outlook 2010 Auto Complete Cache Corruption

A while back, I had written a fairly complete article on restoring the Outlook auto complete cache and working with .NK2 files.  Well, just when we thought that we could all return home in a victorious Napoleonic march, our enemy defeated, our pals down in Redmond reminded us all of Waterloo.

Outlook 2010, has completely done away with .NK2 files and has unfortunately replaced it with a system that seems far from bulletproof. My recent experiences, along with thousands of others on the net, suggests that the new system is rather prone to corruption and cannot be easily fixed.

But first, in a bid to dispel some of the misinformation out there, let me briefly go over how the new system works.

Users first using Outlook 2010, or syncing it to an active sync device are immediately going to notice a new set of contacts called suggested contacts that has been auto created upon opening a new mail account.  Inside, they will quickly notice that it is populated with email addresses of people whom they may not even remember having contact with. One soon realizes that this is a contact list that is being generated based on emails that have been sent out and incoming emails that do not have a proper contact in Outlook.  This idea, actually, seems to make a lot of sense as it is an easily backed up way of managing all of those contacts that were previously stored in the Auto complete cache’s .NK2 file.  It would be easy to come to the conclusion that this is the same thing as the .nk2 cache and this is what populates it. This, however, is wrong.  While it does store similar information, there is in fact a new .dat file that has taken the place of the venerable .NK2 file, but now has a GUID attached to it that is,ostensibly,l generated based on characteristics of the profile.  Apparently, this file can be transferred around just as was done with .NK2 files, but you would have to rename it with the exact same corresponding GUID for it to work. Definitely, not as slick as the simple renaming it to the name of the profile as in previous versions of Outlook. This won’t, however, be an issue if you have transitioned to Exchange 2010 as the file is actually stored on the Exchange server and synced back down to the client allowing for your auto complete cache to follow you as part of a new profile on a second computer.  Again, this is a great idea if it weren’t for the apparent instability of the file itself.

I have been able to find very little information on the causes of the issue, and nothing at all from Microsoft, but it appears that this file syncs itself back to the Exchange server upon closing Outlook. However, if for some reason, Outlook does not close cleanly, it appears to cut short the write of this data which subsequently corrupts the file. It is at this point extremely difficult to correct the situation. 

The file is located at %appdata%\Local\Microsoft\Outlook\RoamCache  and will be the file labeled Stream_Autocomplete_<GUID>.dat. As I stated, I have yet to come across anything that immediately fixes the issue in all cases, but here are a few things to try.

First, to verify that you are having the issue in question, you will a.) have an auto-complete cache that isn’t working and b.) a Stream_Autocomplete file that is 0 bytes in size and stays that way despite adding data to the autocomplete cache during a session. With this issue, your cache will work during the duration of Outlook being opened, but then when you close outlook and reopen it, all of the data is lost. 

Anyway, here are some methods that are known to work.

1. Delete the auto-cache data through the provided menu interface provided in Outlook.  To do this,

1. In Outlook 2010, Click the File menu and Select Options.

step1

2. In the Outlook Options window Click the Mail tab.

step2

3. Scroll down roughly halfway until you see Send messages. Uncheck the Use Auto-Complete List to suggest names when typing in the To, Cc, and Bcc lines box.

step3

2. The second method is to manually delete the file mentioned above. Make sure and close outlook before you do this, as it will have a lock on the file and prevent you from doing so otherwise.  This method is really the same as what happens above, but some people have actually reported that the file did not delete as it was supposed to from the GUI.

3. Rename then whole Roam Cache folder and reopen outlook.

4. Disable cached exchange mode and try methods 1,2, or 3 above and repeat until the file starts to grow in size.

And please, if anyone else has any more information on the actual root cause of this, please comment below so we can all get through this.  There are many possible culprits, but I suspect that over time we will find that it is one particular add-on or program that is causing the vast majority of cases.

Cheers!

Easy URL Rewriting With ASP.NET Routing

URL rewriting is a great way to avoid the problems typically associated with the standard .NET way of building web apps.  Take this typical URL, for example:

http://www.site.com/displaycategory.aspx?category=tools

Most ASP.NET solutions wind up having URLS that look like this.  It works, but there are problems with these types of URLs:

  • They’re long and ugly.
  • They make things look complicated and scary to typical end users.
  • They don’t let power users understand and navigate the site through modifying the URL.
  • Search engines don’t like them
  • Inner workings of your code are exposed, which could lead to security issues.
  • URLs are tied to the specific implementation

What you really want is to have that same web page handling requests, but accessed through an URL like this:

http://www.site.com/categories/tools

There are two great tools in the ASP.NET world to rewrite URLS: The IIS URL Rewrite module, and the System.Web.Routing functionality built into the framework.  Unfortunately, they both have serious drawbacks.

The URL Rewrite module snaps into IIS and lets you configure rewriting without touching any code.  It’s worth researching this tool a bit, because depending on what you’re trying to accomplish, it might suit your needs exactly.  But, it does suffer some serious drawbacks for .NET developers:

  • The URL Rewrite module must be installed on the server.
  • Visual Studio is not aware of URL Rewrite.
  • URL Rewrite doesn’t work with the ASP.NET Development Server built into Visual Studio; you have to build and debug your application through IIS.
  • You can only configure rewrites through the limited URL Rewrite scheme; you can’t write code.

ASP.NET Routing doesn’t suffer from these drawbacks, but while it’s far more powerful, it’s also far more complicated to set up.  It does require code changes, and when used in the traditional manner, it requires each page in your site to be rewritten to use the Routing architecture.  This means a lot of work.  But, there’s a very easy way to harness the power of Routing and use it much like you would the URL Rewrite module.

Enable routing for your application

The first thing you’ll need to do is map a page route within your application.  This is done through code.  The Global.asax class contains a method called Application_Start which is run whenever your application starts, so it’s an ideal place for this.  Find this method, and add this code:

// Register routing
System.Web.Routing.RouteCollection routes = System.Web.Routing.RouteTable.Routes;
routes.Ignore("{resource}.axd/{*pathInfo}");
routes.MapPageRoute("Generic Routing", "{page}/{*id}", "~/routing.aspx");

There are three important arguments to the MapPageRoute call: a friendly name for the route you’re adding (call it whatever you’d like), the format of the URL that’s going to be caught, and the path to the ASP.NET page you’d like to handle matching URLs.  In this example, we’re going to catch URLs of the style used as an example at the top of this page, but you could easily change this to work with an MVC pattern or anything else you need.  Of course, you’re not limited to just one mapping, but that’s all we need for this example.  The asterisk is used to indicate that the {id} part of the URL pattern could contain slashes. The call to .Ignore prevents requests to WebResource.axd from being caught by your routing.

Build your routing pages

Now, add a page called “routing.aspx” to your project, and add this code to Page_Load:

// Get routing data
string page = (string)this.RouteData.Values["page"];
string id = (string)this.RouteData.Values["id"];

// Transfer to appropriate page
if (page == "categories")
Server.Transfer(string.Format("~/displaycategory.aspx?category={0}", id));
else if (page == "titles")
Server.Transfer(string.Format("~/displaytitle.aspx?title={0}", id));

You can see what’s going on here: the code gathers the values that were used to built the URL, checks to see which page should handle the request, and then forwards the request on the the proper page.  In this example, we also remap requests to URLs like this:

http://www.site.com/titles/ExampleTitle

From this point forward, you can configure as many rewrites as you’d like through this one little bit of code.  Because this is code, though, you can modify this to suit whatever needs you may have.  If you wanted, you could even write this to draw data from an XML file so you don’t need to touch code to edit your URL mappings.

Really, this is the best of both worlds: easy to configure, drop-in URL rewriting that will work with any existing solution that doesn’t require anything to be installed, works with Visual Studio, and lets you write code wherever you need a bit more complexity.

Choosing Between C# and VB

Here’s a question most .NET developers have to deal with: C# or VB?

This can be a pretty heated debate; people love to defend the tools they love.  Once you get down to work, though, both languages are very similar.  They both have access to the same libraries and tools, they both have full support from Microsoft and enormous developer communities, and they both get the job done well.

But there are differences.  Let’s look at some of the more important ones:

C# Only: Better syntax

Let’s face it: C-style syntax is better than BASIC-style syntax.  You just can’t argue this one.  BASIC is too wordy; C lets you focus on what matters: your code.  Sure, both languages have code generation and IntelliSense and code snippets, and yes, you can come up with examples where VB code is shorter and more elegant than C#.  But for the most part, it’s pretty hard to argue that VB syntax is designed for experienced developers.

This isn’t as big a deal as you might think.  There’s no scenario where C# syntax is much faster to code in than VB syntax (assuming you have Visual Studio to back you up). But, C# is just a tiny bit faster in 500 different ways, and it adds up.  There are other factors to consider in choosing a language, of course, but this remains a very compelling argument.

C# Only: More advanced development community

VB is generally easier for new developers to pick up, and often allows faster development.  This might sound like an advantage to VB, but there’s a huge counter-argument: the C# community tends to be more advanced than the VB community, and is often more respected.  An experienced developer who prefers VB might have a hard time convincing others that VB can sometimes be a better choice, but a developer who only knows VB will be laughed right out of the room.

If you’re trying to decide on a single language to learn, don’t.  You need to understand at least half a dozen languages and technologies to get anything done in the real world: HTML, CSS, Java(script), XML, SQL, C(++), and more. And if you’re going to be a .NET developer, learn C# and VB.

C# Only: Unsafe code

The .NET world is wonderful, but sometimes you need to drop back to the frightening world of direct memory management.  You can usually accomplish the same tasks in VB through managed code, and even in the pre-.NET world, VB could still read and write to locations in memory directly, but there’s no getting around the fact that C# is a better choice if you can’t imagine a world without pointers.

C# Only: Checked / Unchecked

C# also lets you control exactly when overflows and underflows are caught and when they’re ignored.  In the managed world, it’s pretty tough to argue that overflow can actually be useful, but there’s a lot of legacy code – and legacy developers – out there who depend on things working they way they always have.

C# Only: Iterators

C# also lets you work with iterators.  Sure, VB knows how to iterate, but C# has a bit of extra power and flexibility here.  Check this out:

public IEnumerator<string> GetEnumerator()
{
foreach (string s in strings)
{
yield return s;
}
}

Iterators essentially let a function return values in the middle of the function.  This is a great tool, and one that’s hard to get used to not having when coding under VB.

C# Only: Refactoring

Only C# includes refactoring support build right into the IDE.  These are a collection of extra tools and commands that make development easier and faster, and C# developers are often shocked to learn that VB doesn’t include these features.  True, there are enhanced refactoring add-ins available for both languages that do a better job than what’s built into the C# IDE, but you can’t beat having something ready to go right out of the box.

VB Only: Handles and WithEvents

In C#, you have to hook up events through code.  Sure, there’s designer support available, but it makes for a more complicated project.  In VB, the Handles keyword does all this work for you.  When it comes to creating a UI for your application, this is a really big deal and makes VB developers significantly more productive: things are simpler, and you just don’t have to write as much code.  When it comes to writing business logic and other UI-less code, this doesn’t really matter very much.

VB Only: With

VB offers the With structure.  Not only is this convenient, it also improves performance.  Take this bit of C# code:

System.Text.StringBuilder sb = new StringBuilder();
sb.AppendLine("FileName: " + System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
sb.AppendLine("Memory size: " + System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleMemorySize.ToString());
sb.AppendLine("Entry point: " + System.Diagnostics.Process.GetCurrentProcess().MainModule.EntryPointAddress);
sb.AppendLine(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileVersionInfo.IsDebug.ToString());

And now look at it under VB:

Dim sb = New System.Text.StringBuilder
With System.Diagnostics.Process.GetCurrentProcess.MainModule
sb.AppendLine("File name: " + .FileName)
sb.AppendLine("Memory size: " + .ModuleMemorySize)
sb.AppendLine("Entry point: " + .EntryPointAddress)
sb.AppendLine("Debug: " & .FileVersionInfo.IsDebug)
End With

That’s just less code.  Less code is easier to write, read, and maintain.

This example might be a little contrived:  in the real world, you’d just declare a new variable (and give it a short name).  My point, though, is that with VB, you don’t have to do this.

VB Only: My

The My class is pure convenience.  There’s nothing under My that can’t be found elsewhere in the framework, but it makes it very easy to access a lot of calls in the framework that were previously difficult to find and use.  Have a look at this:

Try
If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
My.Computer.Network.DownloadFile("http://server.com/data.xml", "C:\")
Else
My.Computer.Network.DownloadFile("http://server.com/data.xml", My.Computer.FileSystem.SpecialDirectories.Desktop)
End If
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
Catch ex As Exception
My.Application.Log.WriteException(ex)
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
End Try

C# can do all this, of course, but it’s going to take more code.  That said, a lot of the functionality under My is just there to help beginners find what they’re looking for.  There are a few things here that are invaluable (such as the My.Settings class), but generally, C# developers won’t miss this too much.

VB Only: XML / Date Literals

Date literals have been around in VB forever, and while it’s debatable how often you should be hardcoding dates in code, it’s still nice to have the option (although it’s too bad the illogical American MM/dd/yyyy format is used).  XML literals, on the other hand, are a huge leap forward.  Once you work with XML in VB for a while, going back to C# will be pretty painful.  Have a look at this code, for example:

Dim allScreens = From s In Screen.AllScreens
Select <Screen>
<Device><%= s.DeviceName %></Device>
<Width><%= s.Bounds.Width %></Width>
<Height><%= s.Bounds.Height %></Height>
<BitsPerPixel><%= s.BitsPerPixel %></BitsPerPixel>
</Screen>

Dim document = <?xml version="1.0" encoding="utf-8"?>
<Screens>
<%= allScreens %>
</Screens>

document.Save("screens.xml")

That’s insanely, ridiculously simple.  And the IntelliSense support here is amazing; you really have to try it to understand how beneficial this is.  If you work with XML much, this is a really compelling reason to pick VB over C#.

VB Only: Late-binding and COM

This is another big one.  VB allows developers to use late-binding.  Essentially, this means a developer can call a member on a variable declared simply as Object.  At run-time, the compiler looks at the object, and if the call makes sense, it runs.  If it doesn’t make sense, an error occurs.  In the theoretical world of pure managed code and beautifully designed classes, using such a feature would be considered poor code.  In the real world, though, it’s nice to have this option available.  And where it really makes a world of difference is when you’re working with COM objects.  Again, let’s compare.  Here’s some VB code that automates Microsoft Word a bit:

With CreateObject("Word.Application")
With .Documents.Add()
.Range.Text = Clipboard.GetText()
.SaveAs2("clipboard.docx")
.Close()
End With
.Quit()
End With

And here’s the same code in C# (brace yourself!):

object app = Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application"));
app.GetType().InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty, null, app, new object[1] { true });
object docs = app.GetType().InvokeMember("Documents", System.Reflection.BindingFlags.GetProperty, null, app, null);
object doc = docs.GetType().InvokeMember("Add", System.Reflection.BindingFlags.InvokeMethod, null, docs, null);
object range = doc.GetType().InvokeMember("Range", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
range.GetType().InvokeMember("Text", System.Reflection.BindingFlags.SetProperty, null, range, new object[1] { Clipboard.GetText() });
doc.GetType().InvokeMember("SaveAs2", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[1] { "clipboard.docx" });
doc.GetType().InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
app.GetType().InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, app, null);

As you can see, working with COM in this fashion is really, really painful under C#.  In fact, only through reflection is this even possible!  This has been improved somewhat with the recent addition of the dynamic type in C# 4.0, if you’re able to take advantage of the latest version.

VB Only: Implicit Conversions

In C#, all type conversions must be performed explicitly.  In VB, most simple conversions are performed automatically by the compiler.  This means you can add 2 and 2.0, and it means you don’t need to type .ToString() anywhere near as often.  It can save a lot of time, but can also cause bugs if the conversion wasn’t expected.  Note that you don’t want to give this feature to new developers; they will only get themselves into trouble with it.  It’s great to have conversions done implicitly, but only if you already understand what’s going on under the hood.

VB Only: Better IntelliSense and Error List

In VB, the IDE is much faster at updating IntelliSense, the Error list, and other tools.  Under C#, you often need to rebuild your project to update the Error list and certain other features.  And, IntelliSense is just all-around better under VB.  This might not seem like a drastic difference, but it saves you a second or two countless times a day.  You’ll certainly notice this when moving between the languages frequently.

Other Differences

I think that’s about it for major features available in only one language.  There are a plethora of other small arguments to make, but none that really have much of an overall impact on choosing a language.  There are, of course, many other major differences that don’t really have a clear advantage one way or the other.  Namespaces are handled differently.  VB offers project-level Imports, while C# is better at helping you manage file-level ‘using’ statements.  C# offers static classes, while VB offers Modules.  Commenting works differently.

Recommendations

There is one area where C# is really the only sensible choice:

  • Unsafe code

There are three areas where VB has a clear advantage over C#:

  • Working with COM (although C# 4.0 narrows the gap)
  • Working with XML
  • Developing UI

Outside of these areas, it all comes down to personal preference.  C# has the better syntax and a more advanced community, while VB offers a range of features and aids not available to C#.

But remember: it’s not about the tool.  It’s about what you do with it.


Copyright © 2010 Paul Guenette and Matthew Sleno.