Archives For Coding

While I was reinstalling my laptop this week, I ran into some friction getting my Brick Manager development environment going again. My issue turned out to be pretty simple, and I thought I would share out how to solve the issue to help out others that follow on behind me(because I couldn’t find anything on the interwebz).

After syncing my solution down to my newly configured dev machine, there was a System.IO.FileNotFoundException thrown by the  public static Result Open(string, out Sqlite3DatabaseHandle, int, IntPtr) method within the SQLite.cs; in particular, the exception was thrown by the Sqlite3.sqlite3_open_v2() call.

SQLite exc blog post - 01

Exception details:

  • Type: System.IO.FileNotFoundException
  • Message: The specified module could not be found.
  • HRESULT: 0x8007007E


SQLite exc blog post - 03At the root of the exception was a missing SQLite extension for Visual Studio. I had the SQLite-net and SQLite-net-wp8 NuGet packages, but Visual Studio didn’t automatically link into the SQLite for Windows Phone extension (even though it was installed).

To re-add this to your VS solution, do the following steps:

  1. Open up the project’s references by secondary-clicking on the ‘References’ node in the solution explorer and selecting ‘Add Reference…’
  2. In the Reference Manager, select ‘Windows Phone SDK 8.0’
  3. Select ‘Extensions’
  4. Check the box for ‘SQLite for Windows Phone’ if it isn’t already selected. If it isn’t in the list, then you will need to install the extension (but I will assume you already know how to do that Smile)

SQLite exc blog post - 02

Once I selected the box, everything was once again copasetic and all was good in the universe once more.

Hope this helps!

This blog post starts to cover a number of interesting Windows platform development challenges that I ran into as I built out my Brick Manager app. While the code was initially written for Windows Phone, it also applies to building Windows Store apps. Given that I started the app out as a learning experiment a bit over a year ago, it’s funny that it’s taken me a year to get the first one of these out. Feel free to share your feedback below. – CRS

At the heart of my Brick Manager app is communication with the BrickSet web services. As I started using the service, I wanted to take advantage of HttpClient and the async keyword, but I ran into two challenges up front: (1) Huw uses ASMX for his web service (good luck finding a blog or StackOverflow article discussing how to wire up against one of those) and (2) the site only returns XML (while most Windows/HttpClient blogs only talk about wiring up JSON).

The logic of the XML communications eventually settled on the following pattern:

  1. Instantiate HttpClient to use for the web service communication
  2. Instantiate a CancellationToken to allow me to set a time-out
  3. Parse the result into an XElement data structure, and pass that back to the caller
  4. From the caller, pass the returned XElement into the appropriate parser

I eventually compartmentalized my service calls into a static class, which centralized all of the web service call logic into one place (which not only deduped the code, but also improved stability and perf).

For the web service communication (steps 1-3 above), this is a cleaned up version of my GetBrickSetData method:

private static async Task<XElement> GetBrickSetData(string url) {
  using (HttpClient _client = new HttpClient()) {
    using (var _cts = new CancellationTokenSource(TIMEOUT_DEFAULT)) {
      try {
        var _result = await _client.GetAsync(url, _cts.Token);
        var _data = XElement.Parse(await _result.Content.ReadAsStringAsync());
        return _data;
      } catch (OperationCanceledException _e) {
        // Code to handle timed out exception
      } catch (System.Net.Http.HttpRequestException _e) {
        if (_e.Message.ToLower().Contains("Response status code") && _e.Message.ToLower().Contains("404")) {
          // Code to handle timed out exception
    return null;

One item that is worth calling out is the CancellationToken. I mentioned this as step 2 above, but this was a later addition to my code logic, which I added when BrickSet was undergoing a DoS attack. During that time, the app experience looked to users like it was in a perpetual unresponsive state. Adding the CancellationToken enables me to take the default 60 second timeout to something closer to 3 seconds, but the addition did require me to tease apart the typical HttpClient.GetStringAsync() call you see in code samples everywhere into the two calls above.

Once I get the data back from the above, I then have to parse apart the huge clump of XML For me, I found it easiest to use LINQ to XML to parse the data apart. In the code below, which is pulled from my method that parses the BrickSet set themes, I grab the namespace from the XML and then iterate through each elements in the “themes” node.

public static async Task<IEnumerable<Theme>> GetThemes() {
  string _url = String.Format(BRICKSET_ASMX + "/getThemes?apiKey={0}", BRICKSET_API_KEY);

  XElement _themeData = await GetBrickSetData(_url);

  //parse the results
  XNamespace _ns = _themeData.Attribute("xmlns").Value;
  var _themes = (from themes in _themeData.Elements(_ns + "themes")
                 select new Theme {
                 ThemeName = (string)themes.Element(_ns + "theme").Value,
                 Sets = int.Parse(themes.Element(_ns + "setCount").Value)
  return _themes;

In the end, [I believe that] I landed on a pretty elegant solution, but it can be a real pain to get it right. Not only do you need to really know the XML structure coming off the server, but you need to be able to handle the parsing in a bullet-proof fashion – one parsing error and the code goes bananas.

Parsing errors to keep your eye out for:

  • XML elements that need more robust parsing (e.g., turning 0 | 1 into a Boolean)
  • XML elements that are occasionally null
  • XML elements that are child nodes (and aren’t always present)
  • Optional XML elements that may or may not be there (e.g., when you’re not passing a user ID)

My code (above) gives some decent starting pointers for basic XML parsing, and I’ll dig into my travels through LINQ-to-XML-land in a future blog post.

I hope this helps!

This is a blog post that has been sitting on my laptop, all written and ready for posting, for just about two months now. I worked on the post when Jeff posted his social extension for 4th and Mayor…but shelved it when the topic died down. When talking with my colleague, Larry Lieberman, about the topic, he convinced me to dust it off and post it…and also convinced me to make an appearance on Inside Windows Phone. I hope it better explains what the team shipped with 8.1.  – CRS

With the new Windows Phone 8.1 release, a whole new class of social extensibility points are now available for developers. These new extensions begin to open up a new area of the phone to developers that were pretty closely held – the People and Photo hubs. While these new APIs add a number of highly requested social capabilities to the platform, the new extensions also seem to be a source of confusion.

As the team released the Windows Phone 8.1 preview and devs started digging into the new APIs, I started getting a number of questions on the topic (on social, in my inbox, and on the phone), and I started digging into the topic with the teams that built the features (admittedly, the topic was new to me and missing from all of my ‘what’s new in phone’ discussions so far). In my honest opinion, I found the new social capabilities in 8.1 pretty amazing.

As I haven’t seen much on the topic, I thought it was worth writing up a semi-quick blog post on the topic to explain what I found and to provide some pointers to related reference material. There’s just so much more richness to the subject than 140 characters can do it justice. Smile By the end of the post, my hope is that the new extensions points are much clearer: not only what they are (and what they aren’t), but how you can get started taking advantage of them today.

Why social?

Windows Phone has always been, at the heart, a social phone. This value proposition was the one that resonated most to me, and is central to my ‘why I love my phone’ pitch. Using the People Hub and pinned groups, my phone connects me to the people that matter most in my life (via a couple live tiles), as well as to my broader social graph. At a glance, I can get everything that matters to me in one place, regardless of its source (Facebook, Twitter, LinkedIn, email, or SMS).

wp_ss_20140701_0001The People Hub is magic. As a father of three and Seattle transplant (with all of my family back east), it makes it easy for me to share the day-to-day with my personal networks. Last month, that update was to share news of our girls taking their first steps. And I believe it goes without saying that I’m busy – and the People Hub enables me to get the low-down on my social graph without having to actually go a number of dedicated apps. Again – magic.

There were a couple limitations with this approach, however. While folks generally love the integrated experience, but wanted additional/deeper network-specific features in the native People Hub experience (e.g., to like a photo). And for our international customers, the deeply OS-integrated approach meant that the Windows Phone engineering team was then the only group that extend the integration to additional key social networks around the world.

What can be extended?

To open up the Windows Phone social hubs (the People Hub and the Photos Hub), the team built out a social extension framework to enable Windows Phone to light up anyone’s social graph. imageOver time, this approach should not only make it easy for social networks to extend the hubs, but also to bring flexibility that enables social networks to light up specialized integrations to our users.

With 8.1, there are three integration points that are opened up for app developers publishing into the Store:

  • Social broadcasting: Apps can extend the ‘Me’ card to enable the user to choice and launch an app to checks in or post a social update. As I understand it, the documentation on these is still in the works, but Jeff Wilcox publicly shared out the source code for his Social Extension for 4th & Mayor app.
  • Contact cards: Apps can still integrate with the contact cards to add and extend contacts in the phone’s address book. What is new in 8.1 is the ability to bind to the contact card using a ‘contact binding’ to place an app tile into the new ‘Connect’ pivot to contextually extend the contact. By implementing a contact binding, you provide the phone user with a way to display relevant information about that user (e.g., service username, user/gamer/karma score, relevant pictures, latest update) and provide a way to deep link into your app to immediately interact with that user.
  • Photo Hub: For services that host user photos online, you can also now integrate your app into the Photos Hub, surfacing your app as a tile on the album pivot, enabling your users to jump right into their pictures on your service. This means being able to launch off from one place, the Photos Hub, into each and every connected photo sharing service, without having to navigate in and out of each and every app, looking for that one family picture that you want to show someone.

wp_ss_20140701_0002With the new social extensions, there’s a lot that you, as an app developer, can do to enrich the social lives of your users by surfacing relevant service information in-context. And the result is win-win: for you, you get discovered and launched more often; for your user, the functionality and experience they want is always at their fingertips. Smile


And that’s not all…

Beyond these sweet new social extensions that you can use in your app, it’s worth calling out that you also have the Action Center, contextual awareness via Cortana, and all the yummy goodness of WNS and the new tile templates…with each of these topics totally worthy of a blog post unto itself.

As a developer, it’s really hard not to get excited about all of the new tools that Windows Phone 8.1 adds to an app developer’s toolkit. And as a social network user, it’s even harder to not get excited about all the innovative social experiences that developers can build using them…right there in that magical place called the People Hub.

VS Issue: Designer failing

October 27, 2013

Update: I believe I solved this issue, and this post has been refined to point to the actual issue (and not the way I treated the symptoms of the bad cache).


I was running into an issue while developing in my Windows Phone app in Visual Studio. After banging my head against the wall for several hours looking for a ‘real problem’, it turned out to be an issue in my view model.

My Issue

For any XAML pages in my project where I used the Telerik controls in my project, I received a design-time error whenever Visual Studio attempted to render the page. Funny enough, the error was different depending on which instance of Visual Studio I opened/ran the project in:

  • Visual Studio 2013: ObjectDisposedException: Cannot access a disposed object (NativeObject)
  • Visual Studio 2012: Error HRESULT E_FAIL has been returned from a call to a COM component

NativeObj Exc

This error drove me nuts for a variety of reasons:

  • The same XAML worked in other projects (e.g., Telerik sample code)
  • Creating a blank/new XAML page worked until I added any of the Telerik controls
  • Reinstalling/readding the Telerik controls didn’t do anything.
  • The stacktrace was absolutely meaningless

Funny enough, the error keeps coming back – and I’m guessing it seems to be related to having the Telerik controls open in two projects at the same time in VS2013. It looks like VS2013 changed the way it handles errors in the XAML files – I say this because the sample data XML file that I was using in VS2012 had no issues, but it reported issues in VS2013.

My Initial Solution – Cleaning the Cache

After playing with a large number of things, I tried doing an aggressive cleaning of everything related to the project:

  1. I did a ‘clean’ for every project in the solution
  2. I removed every \bin and \obj folder in the solution
  3. I cleared out the Visual Studio designer temp files
  4. I cleaned up Windows temporary files

After doing the four things above, I returned back to my project, did one more Clean (just because you always double-tap Smile) and then did a Build on my WP project. I then reopened the XAML file, and everything worked once more! Yay! However, opening it up in VS2013 caused everything to get hosed again. So, I did more digging and eventually found my issue was in how I interacted with Isolated Storage in my view model.

My Solution – Fixing my ViewModel


At the heart of the issue, I was using isolated storage settings in my view model (for storing username and a userhash), which I was then taking advantage of in my sample data xml file. And that sample data XML file was being used to render design time data in XAML via data binding. VS2013 seems to look for and throw an error in the sample data XML that VS2012 wasn’t throwing, and this is what was causing an issue above.

I added the below check around the assignment/reading of the IsolatedStorageSettings object to verify that it should go over to the isolated storage area before actually doing so:

if (!System.ComponentModel.DesignerProperties.IsInDesignTool) {
  settings.TryGetValue<string>("username", out m_username);

Using the above check prior to doing a TryGetValue, everything now works appropriately, treating not just the symptoms, but the root cause.

Hope this helps!

Parsing the WoW Armory

February 7, 2008

One of my side projects is working on a WoW Guild Roster. I’ve been doing a lot of work over the past couple months with Visual Studio 2008, although I’ve been stuck with ASP.NET v2 since DNN won’t be supporting v3.5 until DNN v5. One of the features that has me really excited within .NET v3.5 is LINQ.

So, while I was playing with LINQ, I decided ‘what would the code look like if I were to query WoW character data from the WoW Armory? So…I sat down and wrote a quick query of character information.

1 XDocument _charSheet; 2 3 System.Net.WebClient _wc = new System.Net.WebClient(); 4 _wc.QueryString.Add("r", this.Realm); 5 _wc.QueryString.Add("n", this.CharName); 6 _wc.Headers.Add("user-agent", "MSIE 7.0"); 7 System.Xml.XmlTextReader _reader = new System.Xml.XmlTextReader(_wc.OpenRead(ArmoryCharSheet)); 8 9 _charSheet = XDocument.Load(_reader); 10 IEnumerable<XElement> _charInfoEl = _charSheet.Root.Descendants("characterInfo"); 11 if (_charInfoEl.Count() < 1) { 12 MessageBox.Show("No descendants at <characterInfo>"); 13 } else if (_charInfoEl.Count() > 1) { 14 MessageBox.Show("Multiple descendants at <characterInfo>"); 15 } 16 17 var _charInfo = from item in _charInfoEl.Descendants("character") 18 select new { 19 Battlegroup = item.Attribute("battleGroup").Value, 20 CharURL = item.Attribute("charUrl").Value, 21 Class = item.Attribute("class").Value, 22 ClassID = item.Attribute("classId").Value, 23 Faction = item.Attribute("faction").Value, 24 FactionID = item.Attribute("factionId").Value, 25 Gender = item.Attribute("gender").Value, 26 GenderID = item.Attribute("genderId").Value, 27 GuildName = item.Attribute("guildName").Value, 28 GuildURL = item.Attribute("guildUrl").Value, 29 LastModifiedString = item.Attribute("lastModified").Value, 30 Level = item.Attribute("level").Value, 31 Name = item.Attribute("name").Value, 32 Prefix = item.Attribute("prefix").Value, 33 Race = item.Attribute("race").Value, 34 RaceID = item.Attribute("raceId").Value, 35 Realm = item.Attribute("realm").Value, 36 Suffix = item.Attribute("suffix").Value 37 }; 38 IEnumerable<XElement> _profsEl = _charInfoEl.Descendants("professions"); 39 var _profs = from item in _profsEl.Descendants("skill") 40 select new { 41 Key = item.Attribute("key").Value, 42 Name = item.Attribute("max").Value, 43 Max = item.Attribute("name").Value, 44 Value = item.Attribute("value").Value 45 }; 46 IEnumerable<XElement> _baseStatsEl = _charInfoEl.Descendants("baseStats"); 47 var _baseStats = from item in _baseStatsEl.Descendants() 48 select new { 49 Stat = item.Name.ToString(), 50 Base = item.Attribute("base").Value, 51 Effective = item.Attribute("effective").Value, 52 Element = item 53 }; 54

I was quite impressed by the brevity of the code needed to get this. I still want to go back and clean up the web request to use some of WCF’s new capabilities, but I think the LINQ aspects of the code really speaks for itself. The code that it currently takes in .NET v2 to crawl/navigate the XML files was much much larger.

So I’m taking this week off for vacation. But it’s not too much relaxation.

One thing that I finally got around to was getting my laptop configured to start developing for the WoW guild that I help webmaster for on the side. It’s something that I’ve been meaning to do for a long time, but I’ve just not gotten around to doing. And the funny thing about developing for DotNetNuke is that it requires about 4-6 hours just to get things set up – it’s not for the faint of heart.

So what’s the wrinkle this time? I’m running on Vista – which means a lot of base assumptions are shot to hell. And I thought I would outline the lessons learned today here for those who are planning on doing the same:

Why install the WAPs? I’m going the WAP route because I want something that’s easier to deploy. I tried using the DNN Starter Kit path (which I guess is the officially recommended development method as suggested by Microsoft), but DNN is just too large, and I need to go back to the packaged zip file/manifest anyway, so it seemed like a large waste of time, to be honest.

I then went and created the projects for the existing code:

  • Created a solution in the root of my new IIS directory (per the Blank Module guidelines)
  • Created a new project in the ‘Desktop Modules’ folder and created an ‘App_Code’ and a ‘Desktop Modules’ subfolder in the directory. These subfolders contained all the same stuff the other folders did.
  • I then had to clean up the ascx files by ‘Convert[ing] to Web Application’, which creates the Designer code-behind. If you don’t do this, it will essentially toss an error for each and every declared item in the ascx file. [Tangent: The last time I played with a self-contained module, I spent 5 hours cleaning this up by declaring the variables in the ascx.cs code behind, only to find new issues when I moved it into the starter kit]
  • Add it in by hand and added in the database entries

Now I’m finally starting to look at working code again!