Windows Process Activation Service Could Not Be Started

I began today by starting a different post about publishing an app to localhost. Things soon went sideways. That post will have to wait while I peel back this onion:

Localhost can't be reached

When I open up IIS, I can see that the Default Site and the DefaultAppPool are stopped. No problem, let’s start them.

App Pools Cannot Be Started

You knew it wasn’t going to be that simple, right? From an admin command prompt:

Now, WAS and IIS are both installed, so I follow the recommendation from to go ahead and reinstall them, but save yourself the restart. That didn’t do it.

Windows FeaturesI’m not eager to Regedit based on a StackOverflow answer, but it’s simply removing a file and Scott Hanselman’s foray into PerfMon lead me to several errors, but they did not get me closer to a resolution. I’ve reinstalled WAS once, so I deleted NanoSetup.

WAS Parameters

Now the App Pool can be started, but we’re missing one last step to turn on the DefaultSite.

Manage Website Start

W3SVC Is Stopped

One more Admin Command Prompt later and we’re there.

Now, we can navigate to localhost in the browser.

Welcome IIS

Retrieving Items from a List in a Model

Let’s look at how you would get the List<Book> Books from the Author model. We’ll use Author’s Detail View and then extract that to a Partial View. A common error is to get a null pointer exception here:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

This is fixed by adding Virtual to the Books property. Now, when we go to the Author’s Detail page, the Books property is instantiated and the list can be displayed.

List Books

Using the Code First Approach with Entity Framework

Using Entity Framework, we can take a Code First Approach developing the data models and allow EF to translate the model classes into database tables. The properties of classes become the attributes of the tables. Defining an ID for a class will result in a primary key and referencing that ID from another class will create a foreign key relationship. The first step is to import EF to the application.

Import Entity Framwork


It will be useful to create Controllers and Views from the Models. With a DbContext Model in place: run build, then enable migrations from the PM Console, add an initial migration and run update-database. At this point, EF creates the database in LocalDb. See the initial create file in the Migrations folder for the operations run on update. Repeat with add-migration [name] whenever the models change and update-database.

Connect LocalDb

Further control can be gained by defining the connection string in the Web.config file and modify the Configuration.cs. For example, seeding the database with preliminary data. The connection string is also the place to attach the DB if you want to see it in the App_Data folder. It will appear after building and executing the app.

App Data mdf

Storing Values in App.config

Storing values in the App.config file will allow others to update values without needing to access the source code and rebuilding the project. For example, when delivering a solution to another team which may need to change variables such as url, username or emails, then building the project with this in mind and retrieving values from App.config will allow them to easily make those changes.

  1. Add references and using statements to System.Configuration
  2. Add a key value pair to App.config
  3. Get the value with ConfigurationManager.AppSettings
  4. Edit the key value pair from the XML file MyApp.exe.config

On editing the config file, there will be no need to recompile the executable, but the values will be updated.

Add References

Using Configuration



Sending Email from .NET using Gmail SMTP

I automate lots of jobs to run daily. Mostly just getting Task Scheduler to run a bat file or python script and I can just check from my desktop if something failed and re-run it. However, if I am in .NET and something is going to run from another server that I won’t necessarily be able to access whenever I want, receiving an email that a job succeeded or failed would be nice. I am hoping for a more permanent solution, but in pinch, a gmail account will work.


Connect to Oracle Data Source from .NET – A Console App

In order to connect to an Oracle database from .NET, use the Oracle.ManagedDataAccess package, otherwise called ODP.NET. It can be downloaded with NuGet by searching “oracle.”


You can get started easily with defining a connection string. Later, you can put this into App.Config with different Data Sources for Testing and Production environments. Don’t forget the using statement.



Python: Problem Set 11

Problem 11 is a weighting digraph problem, finding your way across campus given building numbers and sidewalks connecting them. In order to tackle this type of problem, I did use some outside tutorials on graph problems and depth-first search from TopCoder and the websites.

Part one involves finding the shortest path using a brute force method. One key to solving this is to keep from going into an infinite loop with cycles through the same nodes over and over. My chosen method is to look for the next node in the path I’ve already taken. This way [path] does double duty as my result and keeps track of nodes visited.

I banged my head on the dynamic programming portion of the problem long enough that I have to wrap this up without taking into account path weights. First, all hops are measured equally. Think number of airport connections made on a trip, but ignores miles flown. Second, I simply could not keep track of the current shortest distance as a break/continue condition without passing it as an argument when I recursed. There may not be anything wrong with this per se, but it is outside the problem specifications, so I feel I should disclose.

Thanks to MIT for providing all the course materials. It was fun.


Python: Problem Set 10

Problem Set 10 uses K-Means clustering to group counties into similar groups based on 14 demographic features such as income, housing, education, farm acres, age, population, population change and a several others.

The first task is to measure the sum of the squared error (the distance between the points in a cluster and the center of the cluster).

Next, we look at the effects of using increasing numbers of initial clusters (K). If the number of clusters were equal to the the number of points in the dataset, then SSE would be zero and we would be finished. This, however, does not tell us much (if anything) about the relationship between points. So choosing a good K number is important.

In the county dataset, we see that for increasing numbers of clusters (k-vals), the SSE is nearly always on a decreasing trend.

The final part of the problem is to weight some features so as to cluster tighter on the poverty rate without using that feature in the measurement. Weighting all features except poverty ends in about a 44,000 SSE at 125 clusters. But, weighting for income and high school graduation rate was a noticeable decrease, about 31,000.

sum squared error

Python: Problem Set 9

The topic this week is optimization and clustering. This problem is less intensive than last week, but it does demonstrate the trade offs between finding an optimal solution (time intensive) and an adequate solution to an optimization problem.

The point here is to optimize a student’s schedule given two factors: workload and value as defined in the given dictionary. E.g. {‘6.00′: (10, 1)}, the class 6.00 is worth ten times its estimated workload. Naturally, there must be a constraint to our optimization, in this case the student’s desired maximum workload e.g. 12 might return {‘6.00′: (10, 1), ‘6.01’: (5, 4), ‘6.02’: (5, 6)}. With a workload of 11, no additional courses could be added to the schedule without exceeding the maximum.

The initial optimizations went quickly, creating three possible sorting functions: work, value or val/work ratio. The brute force best possible function was more tricky. I first used itertools.permutation method to calculate all possible solutions, in order to then loop through and pick one. This died on the short_subject_list.txt with just 20 courses. My function here works well enough on eight items, but I will have to check the staff solution to see how we are expected to carry out such a calculation on 20 items.

EDIT: OCW has a solution for PS9, but it is for a completely different assignment. But, I realized I need a combination of all possible schedules, not a permutation of each. This makes a sample size of twenty courses manageable.

Python: Problem Set 8

Problem set 8 built on the virus and patient model created in ps7. The main things to look at are comparisons of patients with different medication regimens. In part 2, we look at the results of patients prescribed ‘guttagonal’ with a control group that receives no medication.
guttagonal graph

In part five, we see that there are very similar looking graphs for two groups of patients: group A receives one prescription followed by a delay a second prescription, while the second group, B, receives two anti-virals simultaneously. What the graph does not show is that all 100 patients in group A are virus free by the end of the trial, but group B has 20-25 patients with single digit virus counts remaining.