Posts
1145
Comments
890
Trackbacks
1
January 2015 Blog Posts
the type or namespace webviewpage does not exist in system.web.mvc

When setting up a project that I knew was good, I kept getting errors like this when trying to build and couldn’t figure it out, especially since it was referencing pages in Temporary Asp.Net directories.

What resolved the issue was making sure that copy local was set to true on the system.web.mvc reference.

posted @ Thursday, January 29, 2015 8:14 PM | Feedback (0)
You can hibernate a Surface Pro 3 running Windows Technical Preview 9926

….if you create a shortcut to use the command line option, and it is otherwise enabled using powercfg.

posted @ Wednesday, January 28, 2015 1:21 PM | Feedback (0)
Note to self about LINQ queries: SingleOrDefault and FirstOrDefault are different

They are both syntactically and semantically different, so if it matters, pay attention.

And, yes, “LINQ queries” is arguably redundant. 

posted @ Wednesday, January 28, 2015 1:18 PM | Feedback (0)
A few nagging issues with Windows Technical Preview 9926 on a Surface Pro 3

I can’t say I’ve checked out all the newest features, but overall, I like it.

However, there are a couple of nagging issues that I’ve run into:

  • No hibernation.  It’s enabled in the registry, powercfg /h and all that is set, there is even a hiberfil.sys file available, but the normal trick of getting it to show up as an option when you ‘press’ the power button doesn’t work.  No hibernation option.
  • Can’t sleep.  Or, should I say, it is so sensitive that when I choose for it to sleep, just about anything seems to wake it.
  • Can’t ‘unblock’ files downloaded from the internet.  Even when the group policy is set, files will still say they need to be unblocked, and trying to do so appears to do nothing.

All in all, that’s not too bad.  And I get that snazzy new calculator.

posted @ Tuesday, January 27, 2015 2:03 PM | Feedback (0)
2-step verification: a request

To all those who implement 2-step verification (I’m looking at you, Google and Microsoft, in particular)…..

When you have step whereby you wait for the user to enter in the verification code, and underneath where they put in the code, is a checkbox which says “Don’t ask again on this computer”, and the user checks that box….

Honor that shit already.

And Microsoft, you should be ashamed, but you should really probably figure out how to get 2-step verification to work better when someone wants to add Hotmail to Outlook 2013.  I mean, seriously….

posted @ Monday, January 26, 2015 9:19 PM | Feedback (0)
Upgrading a Surface Pro 3 to Windows 10 Build 9926

First off, it works.  Slowly.  It took over 2 hours (not counting download).

Other than building a few projects, I haven’t tested month.  Icons and stuff look all different.

posted @ Friday, January 23, 2015 4:34 PM | Feedback (0)
Resetting a Surface Pro 3

So to prepare for the next release of Windows 10, and for the hell of it, I decided to reset my Surface Pro 3, which I am still in the process of doing. 

If you are going to reset a computer, it is usually a good idea to make sure you’ve backed up everything you care about.  It was only a personal database that I had recently created, but that went bye bye.

Also, when I reset, it reset to Windows 10 9841.  That I was not expecting.  I was also not expecting it to say that there were no new preview builds.  I was also not expecting it to say it couldn’t mount the 9879 iso, which for some reason required me to use Virtual CD Clone.  It did upgrade successfully.

I’m still in the middle of it, so I’ll see if there is anything else weird about it.

posted @ Tuesday, January 20, 2015 10:31 AM | Feedback (0)
Yet another sign that your software development organization might have some issues

“Someone is here from the overseas office, so even though the process is broken, can we hack the database so that it looks like we are making progress?”

posted @ Tuesday, January 13, 2015 3:34 PM | Feedback (0)
Brilliant things Kirk Herbstreit taught us during the National Championship Game

Oregon, get this, has more difficulty converting on 3rd down when they have longer to go, as opposed to when it is 3rd and 4 or less.

Ohio State was having difficulty in short yardage situations because of the push Oregon was getting from their defense, which is why they were 3 for 3 when trying to convert on 4th down.

If only Brent Musburger had been there…..

posted @ Monday, January 12, 2015 11:11 PM | Feedback (0)
SimpleInjector – Registering when you have a primitive in the constructor

Suppose you have a class that has something like a string parameter in its constructor, like:

public class QueryBus(string busName) : IQueryBus

If you try to register this using SimpleInjector the normal way, like this:

container.Register<IQueryBus, QueryBus>();

you will get an exception when you call container.Verify(), like this:

The constructor of type QueryBus contains parameter 'name' of type String which can not be used for constructor injection.

You can also get other errors, depending on what you are trying to do, and obviously, you can’t register a string (and if you try to do that, or other types of ‘tricks’, you will be told that it is bad design and you are a bad developer and you should give up and go into sales….or something like that).

You can instead register like this:

container.Register<IQueryBus>(() => new QueryBus("MyQueryBus"));

That will work.

posted @ Sunday, January 11, 2015 1:47 PM | Feedback (0)
Another sign that your software development organization might not be up to snuff

“Not really my problem.”

Offered up when an obvious difficulty/roadblock/issue is raised.

posted @ Thursday, January 08, 2015 12:10 PM | Feedback (0)
A sign your software deployment processes might not be as good as they could be

“Well, everything was fine except that when I copied the config file from DEV to PROD, I made a typo when changing the server setting.”

posted @ Tuesday, January 06, 2015 10:24 AM | Feedback (0)
Windows Workflow Parallel Activity – How to get things to actually run in parallel

I’ve been doing something using Windows Workflow, and it is….interesting.  Someday we will have a great way to code workflows, in the meantime, there are things like Windows Workflow.

Anyhoo, one thing that took a while to figure out is how to get a parallel activity to actually run things in, well, parallel.  By default, it actually doesn’t.  There is one thread assigned to the entire activity, and so, if any of your child activities do their work synchronously, they will not yield to any of the other child activities until they are complete.  This is, well, a little annoying.

However, it is fairly easy to get it to work properly, and the solution is to use Tasks.

So, inside your BeginExecute method, you will want to use Task.Factory.StartNew. 

Here’s some boilerplate sample code:

protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
{
// setup variables here.  note, you cannot reference 'context' inside of the task, so you need to get whatever values you need ahead of time

    List<int> inputvalues = context.GetValue(MyInts);

    Task<List<string>> worker = Task.Factory.StartNew(o =>
    {
        // imagine this runs for a while
        List<string> returnValues = new MyProcessThatProducesTheReturnValue(inputvalues);
        return returnValues;
    }, state);

    worker.ContinueWith(task => callback(task));
    return worker;
}

And then:

protected override List<string> EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
{
    var worker = result as Task<List<string>>;
    if (worker == null) throw new ArgumentException("result is null");
    return worker.Result;
}

This allows your activity to run on a separate thread in parallel.

posted @ Tuesday, January 06, 2015 10:08 AM | Feedback (0)
The OneDrive version dance

Suppose your machine reboots before you have a chance to close out all of your documents (this happens quite often when you are on a Surface Pro 3 that refuses to successfully install the latest Windows 10 Technical Preview, but I digress).  Suppose some of these are Excel documents.

When you restart Excel and try to open one of those documents, you may get the message ‘someone has updated the server version, do you want to keep your local version or the server version’, what would you choose?   This is a document that is only updated on a single machine.

You’d always choose the local version, right?  Wouldn’t it always have your latest changes?

You’d think so, but somehow, this isn’t always the case.  For the life of me, I can’t think of how this could be so (how could changes be in the cloud but not locally?  A temp version is what is being worked on locally, and you update to the cloud, but it doesn’t sync locally?), but sometimes, it is.

posted @ Monday, January 05, 2015 11:40 AM | Feedback (0)
A way to handle open generics using dynamics in Simple Injector

Now we get a little more complicated.  Note that there will be a lot of tight coupling, and I’m not talking about CQRS, and I’m sure you can do everything better in many different ways.

Here’s the deal.  I wanted a specific way to handle (pun intended) processing commands and events that wasn’t so manual.  Often times, you create a command, it gets handled, one and only one type of event is created (or an exception is thrown), and then that gets handled.

In which case, I wanted something like this:

Command –> Command Handled –> Command is automatically responded to by an event –> event is handled

When I say “command is automatically responded to by an event”, I mean something like this:

public interface RespondsTo<T> where T : Command.Command { }

public interface RespondsTo<T, TReturnValue> where T : Command<TReturnValue> { }

And this:

public class Event : IEvent, RespondsTo<Command.Command>

public class Event<TReturnValue> : IEvent, RespondsTo<Command<TReturnValue>, TReturnValue>

And this:

public interface IEventBaseBus
    {
        void Dispatch<TEvent>(TEvent @event) where TEvent : Event;
        void Dispatch<TEvent, TReturnValue>(TEvent @event) where TEvent : Event<TReturnValue>;
        void Process<TCommand>(TCommand command) where TCommand : Command.Command;
        void Process<TCommand, TReturnValue>(TCommand command) where TCommand : Command<TReturnValue>;
    }
  

A few notes.  Events never return values, but they can record the returned value of the command they are tied to.  And they are tied to specific commands.  Events don’t just materialize from nothing, or randomly, but from specific things.  This only works if you have halfway decently defined events (so no ProductChangedEvent).  And, more often than not, the properties on your events just come from the command anyway, so you can typically do a lot of auto-mapping (whether you use AutoMapper or not) between them.

So, once a command is handled, it is placed on the event bus for processing, and then, something like this happens:

public void Process<TCommand>(TCommand command) where TCommand : Command.Command
        {
            var regs = _container.GetAllInstances<RespondsTo<TCommand>>();

            foreach (var r in regs)
            {
                Type t = r.GetType();
                dynamic obj = Activator.CreateInstance(t, new object[] { command });
                if (obj is Event)
                {
                    Dispatch(obj);
                }
            }

            return;
        }

You register things in your event bus in largely the same way listed before.  You need the dynamic stuff because you need to be able to dispatch something of type Event.  The registrations give you all those things that respond to the right command, and then get dispatched so that they can be handled:

public void Dispatch<TEvent>(TEvent @event) where TEvent : Event
        {  
            var regs = _container.GetAllInstances<Handles<Event>>();

            foreach (var r in regs)
            {
                r.Handle(@event);
            }
        }

Dealing with commands that have return values is similar.  Processing them is nearly identical:

public void Process<TCommand, TReturnValue>(TCommand command) where TCommand : Command<TReturnValue>
        {
            var regs = _container.GetAllInstances<RespondsTo<TCommand, TReturnValue>>();

            foreach (var r in regs)
            {
                Type t = r.GetType();
                dynamic obj = Activator.CreateInstance(t, new object[] { command });
                if (obj is Event<TReturnValue>)
                {
                    Dispatch<Event<TReturnValue>, TReturnValue>(obj);
                }
            }

        }

But the dispatch code is a bit more complicated:

public void Dispatch<TEvent, TReturnValue>(TEvent @event) where TEvent : Event<TReturnValue>
        {
            Type t = @event.GetType().UnderlyingSystemType;
            Type trv = typeof(TReturnValue);

            Type type = typeof(Handles<,>).MakeGenericType(t, trv);

            var regs = _container.GetAllInstances(type);           

            foreach (var r in regs)
            {
                dynamic hnd = r;
                dynamic objEvent = Convert.ChangeType(@event, t);
                hnd.Handle(objEvent);
            }
        }

In order to get the exact registrations that you need, you have to make sure that you get the proper implementations, the closed type, not the open type.

No doubt all of this could be done in 3 or 4 lines of Ruby (or JavaScript), but this serves my current purposes.

posted @ Thursday, January 01, 2015 6:37 PM | Feedback (0)