December 2015 Blog Posts
Postman Rocks

Love it.  API development made easy (or easier, at least).

posted @ Thursday, December 31, 2015 10:57 AM | Feedback (0)
Separated at Birth? Shawn Wildermuth and Patton Oswalt

Their voices anyway.  Watching his Pluralsite course on Asp.Net 5 MVC 6, and it’s uncanny.

posted @ Thursday, December 31, 2015 9:32 AM | Feedback (0)
Are you targeting the full .NET framework and the CoreCLR? Please stop

“Well, the CoreCLR can’t process images or send email, but there should be 3rd party NuGet packages to take care of this.  And this way, if you every need to move from Windows to OSX, it will be seamless.”

Oh.  My.  God. 

No, people.  Lowest common denominator programming is wrong.  WRONG. WRONG. WRONG.

posted @ Tuesday, December 29, 2015 9:51 AM | Feedback (0)
Everything above the .NET layer is a NuGet Package

Yeah, that should go well.

posted @ Tuesday, December 29, 2015 9:49 AM | Feedback (0)
Running async processes in console programs

Dude, it is:


posted @ Monday, December 28, 2015 11:15 AM | Feedback (0)
Deploying an Asp.Net 5 MVC 6 RC 1 WebApi to IIS

I’d worked through some of the issues with WebApi 2 before, so it was largely the same, with a couple of differences due to the half-baked implementations.  I certainly hope it gets better.

You need to do these things:

  1. Install the Http Platform Handler

    You will need to go here and download the relevant 1.2 or higher handler.  Out of curiosity, does anyone run 32-bit anymore?  I installed the 64 bit one.

  2. Update your web.config

    Even when you get other things set up, you may find that you can’t PUT or DELETE.  On the web you will see things about doing things with WebDav and other stuff, but you need to update the web.config in the wwwroot to handle this properly.  Yes, apparently, web.config still does things, even if it ignores connection strings and app settings.  Here’s mine:

    <?xml version="1.0" encoding="utf-8"?>
        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="true">
          <remove name="WebDAVModule"/>
            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Allow-Headers" value="Content-Type" />
            <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
          <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
        <httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>

  3. Create an unmanaged code application pool

    You should know how to do this.  Create a new app pool, but tell it ‘no managed code’ since the new framework handles all that.

  4. File publish your application

    Pick a location, and file publish your app there.  I certainly hope that publishing to a web site will be implemented again, since if you have to set up a remote server, you have to file publish locally, and then copy it.  Oh, and you may need to turn off your site when publishing after the site set up, since it isn’t currently smart enough to handle existing file locks like the previous web publishing worked in Visual Studio.

    This is where Microsoft just keeps screwing up the basic.  Hanselman thinks it’s cool to move code from a PC to a MAC, since it’s way RAD KEWL and all that.  As if anyone is going to be developing .NET for OSX (I mean, odd developers like me might, but not web sites.  There are no OSX servers (none that matter).  But that ginormous group of existing folk that want to publish a site to IIS?  Is that a priority?  Nah.  But I digress .

  5. Wire it up

    Create your site in IIS.  Point it to the wwwroot folder where you published it (if you needed to copy it, you should copy over approot and wwwroot even though you point to wwwroot.  I don’t know why, I’m sure David Fowler can explain it).  Use the application pool you created.

    You should be good to go.
posted @ Sunday, December 27, 2015 11:22 PM | Feedback (0)
Using EF 6 with Asp.Net 5 MVC 6

Just an aside, but Microsoft’s naming conventions are getting absolutely comical.

Anyhoo….Microsoft appears to hate connection strings now.  With UWP and now with Asp.Net 5 MVC 6, they just don’t make things easy at all.

Since EF 7 is woefully undeveloped, and even when it RTMs, it won’t be ready for prime-time, I was trying to get an existing EF 6 infrastructure to work with WebAPI in the new Asp.Net 5 MVC 6 world (yes, I’m going to keep typing it out).  Since code changes are fun, there were various changes that needed to be made to take a WebApi 2 application itself and convert it (lots of changing IHttpActionResult to IActionResult…why?  Why not?).  And, dear Microsoft, why do I need to AddMvc and then UseMvc?  Really?

But when it came to reusing EF 6, there were additional challenges.  The built in auto-wiring fantastic joy stuff only works with EF 7.  You can reference EF 6 from NuGet, that’s not a problem.

But (he repeats himself), Asp.Net 5 MVC 6 doesn’t like web.config anymore.  There is one that sits in wwwroot (what the heck is it for, he wonders), but you can’t put connection strings in.  I mean, you can, but they are ignored.   Instead, Asp.Net 5 MVC 6 likes you to put things in appsettings.json and do stuff with it in startup.cs, but that doesn’t work well when you need to new up a DataContext in your controller.

I name my DataContext things like “InfrastructureConnectionSettings”, and I create the connection strings off of a Data Model such that they look like this in web.config:

<add name="InfrastructureConnectionSettings" connectionString="metadata=res://*/Infrastructure.csdl|res://*/Infrastructure.ssdl|res://*/Infrastructure.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=myServer;initial catalog=myDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient"/>

And then, my controller will have a private DataContext like this:

private InfrastructureConnectionSettings db = new InfrastructureConnectionSettings();

And then I can do things like:

return db.ErrorLogs.Take(3).OrderByDescending(x => x.DateCreated);

But, if you try to run this in Asp.Net 5 MVC 6, it will tell you it can’t find an entry for “InfrastructureConnectionSettings” in the application configuration file.  Which is true, because there isn’t one.

Instead, you need to create a new partial class with a constructor like this:

public InfrastructureConnectionSettings(string connectionString): base(connectionString)

And then in your controller you can do something like this (to test):

private InfrastructureConnectionSettings db = new InfrastructureConnectionSettings("metadata=res://*/Infrastructure.csdl|res://*/Infrastructure.ssdl|res://*/Infrastructure.msl;provider=System.Data.SqlClient;provider connection string='data source=myServer;initial catalog=myDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework';");

And, note here that there are actual single quotes instead of %quot around the connection string itself.  It sucks to have to put in any connection string information inside the controller (even pulling from configuration in each controller is bad), but at least it works.

 So, how to do it slightly (and only slightly) better?

Define a class:

public class AppSettings
       public string InfrastructureConnectionSettings { get; set; }

Do these things in startup.cs:


And now, in your controller, do this:

public ErrorLogController(IOptions<AppSettings> appSettings)
            db = new InfrastructureConnectionSettings(appSettings.Value.InfrastructureConnectionSettings);

And put your values in appsettings.json like this:

  "AppSettings": {
    "InfrastructureConnectionSettings": "metadata=res://*/Infrastructure.csdl|res://*/Infrastructure.ssdl|res://*/Infrastructure.msl;provider=System.Data.SqlClient;provider connection string='data source=myServer;initial catalog=myDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework';"

And there you go.  What used to be a simple entry in your web.config, recreated in 17 steps or so.  Because web.config isn’t testable.  Brilliant.

posted @ Friday, December 25, 2015 11:59 PM | Feedback (0)
Asp.Net 5 MVC 6: Why AddMvc() and UseMvc()?

This is one of those things that strikes me wrong about the whole new shiny system.  It’s a bit of a shame when they redo everything from scratch and get such basic things wrong (“we got rid of web.config.  why?  To make configuration more difficult!!!”)

There is a ‘Pay As You Go’ notion that they like to talk about in their discussions.  The idea, not entirely stupid, is that you need to explicitly state how you want things to be, so to speak, so as not to end up with a bunch of framework (and other) code that you don’t need and never use.

Well and good.  Except, it is a framework.  It has its own black magic Dependency Injection system so that things ‘just work’, so why wouldn’t you be able to say UseMvc() and have it just work?

A StackOverflow post suggests a misguided (borderline incoherent) approach to Separation of Concerns.

What’s going to happen, of course, is that everyone is going to use the non-empty template and strip out the controllers and views, and leave in a whole bunch of cruft that will never be used, completely defeating the purpose.  Of course, what do you expect when you have to configure the system to serve static files?  That is just gratuitous.

posted @ Friday, December 25, 2015 10:34 PM | Feedback (0)
Excel: How to get the cell value from a different worksheet and incremented


posted @ Friday, December 25, 2015 10:13 PM | Feedback (0)
General Tso’s Chicken

Was invented in the US.

Just saying.

posted @ Monday, December 21, 2015 9:37 AM | Feedback (0)
“A phone that may replace your tablet and become your PC”


posted @ Friday, December 18, 2015 3:49 PM | Feedback (0)
This is the year of Linux on the desktop

Only two weeks left.

posted @ Friday, December 18, 2015 10:43 AM | Feedback (0)
“Let’s build the data using the API”

Translation:  blah, blah, blah

posted @ Wednesday, December 09, 2015 3:17 PM | Feedback (0)
Let’s hear it for Open Live Writer

It’s like Windows Live Writer.  But open source.  Wheeeee!!!!!!!!!!!!!!!!!!!!!!!!

posted @ Wednesday, December 09, 2015 12:22 PM | Feedback (0)