It’s soooooo obvious!

While using the Newtonsoft Json.Net library I received the error

"Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property."

When attempting to generate a schema for some types that were created that have circular references. My types were created in EntityFramework database first strategy, so I didn’t want to figure out how to hack the T4 generator to add the Json attribute, and I didn’t quite understand what it mean by using the “UndefinedSchemaIdHandling property”. I suppose it might seem obvious to the author as when I searched the interwebs for an example, this was one of the first results

http://json.codeplex.com/workitem/22569

His response was pretty much recursive error output.

if (user.hasError)
{
  print(error);
  while (user.doesNotUnderstandsError) 
  {
    print(error);
  }
}

Now, unfortunately, I was in that loop for a little bit, looking at the method overloads, thinking about maybe a partial class to add the attribute, staring at the message expecting some epiphany and looked online with no success. It clearly must have been obvious to everyone else besides me, because I couldn’t find any articles on it. So I downloaded the source code for the library, read through the logic until I got to the method that leveraged a public property on the generator class itself, in which you can how you want to handle the undefined schema Id.

So in case any other developers out there, not quite as dumb as I am, still are not able to figure out that error from the exception message alone. Here is a easy code snippet to move past this problem.

JsonSchemaGenerator schemaGenerator = new JsonSchemaGenerator();
schemaGenerator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName;

var result = schemaGenerator.Generate(typeof(MyComplicatedRecursiveTypeWithNoIds));

Happy coding!

SysWOW64 burns a few hours

My latest adventure involves me setting a profile for Powershell to import a module so that I can use a custom script without manually loading it each time. So run off to find that the environment variable is $profile.allusersallhosts. It maps to a file “C:\Windows\SysWOW64\WindowsPowerShell\v1.0\profile.ps1”, so I open up Notepad++, place my import statements in there and life should be good!

However, it’s not working. Not only is it not working, when I go into that folder the file isn’t showing. I have literally no clue where it’s saving so I use SysInternals ProcMon and watch Notepad++ to see the resources it’s using. Turns out that since notepad++ is built as a 32bit application, anytime it looks for the folder c:\windows\system32, some magical internal windows thing routes it to c:\windows\syswow64. So even though Notepad++ shows the folder to be system32, it actually isn’t.

In the end the solution was to use notepad.exe or any other 64bit editor that won’t discreetly change the folder on you and lead you on a wild goose chase.

Happy Coding!

 

 

IIS Express misdirection

So I maintain multiple branches, one for on-going development and the other for production support. Although Git has a feature to switch branches, it does some magic in the background which moves files and require you either to stash your changes or commit, which can be inconvenient, so instead I have the branches checked out to multiple directories.

This normally works well, unless you use IIS Express for debugging your web solutions. It turns out that IISExpress maintains an “applicationhost.config” file in MyDocuments\IISExpress\config folder. Now this nasty booger seems to know how to change the file selectively, typically when I really don’t want it to.

So as I was making a bug fix today, it managed to switch it automatically as I changed branches and life was good. After that, I go back to my enhancement branch and start cranking away. A few hours later when I’m ready to debug, I launch the app and then I notice funky artifacts in the behavior. I seem to have lost my changes! Or did I?

It was the config file. In it, you’ll find a section that would look similar to the following.

 

<sites>
  <site name="Awesome.App.Services" id="1541412810">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
      <virtualDirectory path="/" physicalPath="D:\ProductionBranch\Awesome.App.Services" />
    </application>
    <bindings>
      <binding protocol="https" bindingInformation="*:44301:localhost" />
    </bindings>
  </site>
  <site name="Awesome.App.MvcClient" id="1541412811">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
      <virtualDirectory path="/" physicalPath="D:\ProductionBranch\Awesome.App.MvcClient" />
    </application>
    <bindings>
    <binding protocol="https" bindingInformation="*:44302:localhost" />
    </bindings>
  </site>
  ....
</sites>

 

Now, when you work off another branch it theoretically should change automatically for you, saving you from murdering the people near you. However, it likes to only work sometimes and thus you have to change it back manually. After I changed it back, IIS ran from the correct location reflecting my current changes.

Bleeding edge vs Cutting edge

So after returning from Code camp NYC, I got back to the office with a bunch of new toys that I absolutely had to integrate as part of our solution. I started messing around a web framework called “Hot Towel”, which includes “Bootstrap”, “Durandal”, “RequireJS” and “Toastr”. Out of the box, it compiles and the demo thing works great, however the demo is not feature rich, so immediately I’m off for documentation on how to do the next things.

1. Do something after the view is composed
2. Make multiple columns with Bootstrap and the div tag

So starting on the first problem with DurandalJS, I’ve written a framework over Microsoft Prism before, so I understood a lot of the goals of Durandal and I was following the documentation of where to place a function, such that when the view is attached it will fire a function. All over the interwebs, I found the function “viewAttached” and write such a method in my view model to no avail. I stepped through the code and was ready to roll up my sleeves and step through the Durandal code.

However, before I do, something tells me it’s got to do something with the name of the method. So I decided to look up the available methods in a view model and discovered my hunch was correct. There was a breaking change in the official 1.0 release of Durandal that changed the method name from “viewAttached” to just “attached”.

So after the pain of dealing with the Durandal version number, I had another painful distraction of making Telerik ListView control correctly function in acquiring item selected.

Hours after I deal with that, I start digging into the next issue of multiple columns with bootstrap. I’ve followed the documentation and it’s just simply not working. I’m messing with the debugging tools in IE, Firefox, Chrome and Opera, not exactly seeing why the css is not working like the examples on the bootstrap site.

http://getbootstrap.com/examples/grid/

I then finally waded through some magical stackoverflow link to find someone commenting about http://bootply.com/. Where I’m able to test and experiment. However, the class attribute names don’t match the documentation. Surely something is wrong with bootply… then I see it… again!!! literally 4 hours after the previous issue, I still wasn’t smart enough to check it.

The version number was off and there were breaking changes. Breaking changes that altered the class attribute names. Sure enough I update bootstrap and I’m off on my way with working divs.

My lesson learned is that when working on these latest and greatest technologies, make sure to double check versions when looking up articles as breaking changes can really hurt you and consume mountains of time.

Fighting Git with many tools

So I decided to create a branch in Git to implement a nice new feature and after about a week or so, I get to a section of code that was shared with my cohort and course changes were made that I wanted. So I figured, “This is what Git is good at, right?”

In theory yes, but still coming from Subversion it took a lot of pain and many tools to figure out how to get it working.

I attempted to “Rebase” from subversion unsuccessfully many times as when conflicts were discovered, the progress bar just kept spinning and spinning and spinning. So while testing I corrupted my local code base… many times over. I literally cloned from the safe point about 4 times before I finally got it right.

I used the Git/Git-bash tool to initiate the rebase doing

git checkout MyAwesomeBranchOrSoIThought
git rebase master

Now it would stop midway and mention to fix the conflicts before resuming… well.. the bash utility is, in my opinion, not the best visual merge tool, so I went to the TortoiseGit to resolve the conflicts. After each conflicted file was resolved, I then went back to Git-bash and ran

git rebase –continue

All the way until it finally completed and then sure enough it finally made it all the way through. Once that was done, I went back into VS, where we use Microsoft’s TFS Git provider to sync the last change set.

Painful, but hopefully the UI tools mature to the point where I no longer have to go back to Git-bash.

Javascript is Evil – Curly brace indentation

So I’m building a little DurandalJS SPA (single page app) test site tonight and while building the view model I do what I’ve typically done in the past when I run into Java curly brace convention, which is to plop that sucker down to the next line a la default VS C# convention.

Little did I realize that it was going to bite me in the booty and give me a crazy run around.

My view Model originally

return
{
    displayName: 'Cats',
    cats: ko.observableArray([])
};

The version that works in js

return {
    displayName: 'Cats',
    cats: ko.observableArray([])
};

¿c wut I did there?

Who in hell would be as so evil to seriously make that a difference and why has JS become the dominant language of the web? Unfortunately the question is rhetorical and it’s reason for success is numerous, but seriously the language is nasty. Once I get my sample running, I’m going to go investigate Typescript and Coffeescript. I’m such a web newb.

Wix Windows Service – Start on install

So I was building a wix setup project for a windows service and kept running into a wall while getting the service to start after a successful install. It kept giving me an error “Verify that you have sufficient privileges to start system services”. I searched through nearly 50 articles that led me on a wild goose chase of the issue being related to actual permissions, dual service control tags, the wait attribute and hacks inside the service installer code behind. To actual solution was ridiculously simple, the error was just too obscure to identify the root cause.

My wxs file had the following contents

<ServiceInstall
  Id="ServiceInstaller"
  Type="ownProcess"
  Vital="yes"
  Name="Ninjacrab Awesome Service"
  DisplayName="Ninjacrab Awesome Service"
  Description="The super awesome service"
  Start="auto"
  Account="LocalSystem"
  ErrorControl="ignore"
  Interactive="no"
  />
<ServiceControl
  Id="StartService"
  Name="NinjacrabAwesomeService"
  Start="install"
  Stop="both"
  Remove="uninstall"
  Wait="yes"
  />

Not sure how it caught my eye, but I noticed the name was different

<ServiceInstall
  Id="ServiceInstaller"
  Type="ownProcess"
  Vital="yes"
  Name="Ninjacrab Awesome Service"
  DisplayName="Ninjacrab Awesome Service"
  Description="The super awesome service"
  Start="auto"
  Account="LocalSystem"
  ErrorControl="ignore"
  Interactive="no"
  />
<ServiceControl
  Id="StartService"
  Name="Ninjacrab Awesome Service"
  Start="install"
  Stop="both"
  Remove="uninstall"
  Wait="yes"
  />

Sure enough this fixed the problem and I went on my merry way.