Arrh! Invocation Error! NHibernate

I had started to get this annoying error when I ran my web app:

Exception has been thrown by the target of an invocation.

Simple fix. Add back those virtual keywords onto my POCOs that somehow disappeared.
public int Id {get;set}   –>  public virtual int Id {get;set;}

Posted in NHibernate | Tagged | Leave a comment

FTP Publishing on Windows Server 2008 with Amazon EC2 – Rough guide

AS A NOTE – WEB DEPLOY IS MUCH BETTER THAN FTP PUBLISHING - Just letting you know :)

This is my quick guide ( i.e. how i did it) on how to get FTP Publishing working on a Amazon Instance Website.

  1. Install FTP Publishing using the Microsoft  Web Platform Installer
  2. Under the IIS Manager, go to the server and run through the FTP items one by one:
    1. FTP Authentication – I just used basic authentication, but you can roll your own.
    2. Authorization Rules – I added a “Allow All Users Read Write”. You can be more exclusive
    3. Firewall support
      1. Specify a Data channel range. I used 28000 –> 28100
      2. Leave the external IP address empty. Seems to work well
    4. SSL Settings – Choose your certificate and allow SSL connections (Used with Explicit SSL over FTP)
    5. User Isolation – I have this set to FTP root directory
    6. Setup the Windows Firewall to allow the SSL connections to actually connect by running this command (credit for this tip goes to learn.iis.net)
      netsh advfirewall firewall add rule name="FTP for IIS7" service=ftpsvc action=allow protocol=TCP dir=in
  3. Log into the Amazon Instance Manager or use Elastic Fox for Firefox (which is pretty cool) to access the security groups
    1. Add FTP port 21 with host 0.0.0.0/0
    2. Add the port range that you added before (e.g  28000 –> 28100) and set the host to 0.0.0.0/0
  4. Add FTP publishing to a specific site
    1. Right click one of your sites in the IIS manager and select “Add FTP Site Publishing”
    2. Add a virtual host name if you feel the need, or require it to differentiate.
    3. Customise at will or let the server defaults handle the settings, then click Finish
  5. Log into the site using a Windows login and  a good FTP client (e.g. like Filezilla) with the servertype as “FTPES – FTP over Explicit TLS/SSL” or if that doesn’t work, try just plain ol’ FTP (not recommended with a Windows Login). Hopefully there is no issue. If there is let me know what happens or how you fixed it if you did.
Posted in Amazon EC2 | Tagged , , | 2 Comments

Fiddler, Visual Studio and Localhost working together!

 

I found two new tricks to make all these things work together for debugging a Visual Studio Asp.Net web project on Localhost. Here they are:

  1. Disable IPv6 – This stops the “Fiddler: No connection could be made because the target machine actively refused it” message.  (Credit to Mike Ormand) This happens as visual studio will not allow external connections to the “test” server it creates, so all requests must be local.
    For some reason it treats fiddler IPv6 connections as external, and therefore nothing works through the fiddler proxy.
    fiddler_disableIPv6
  2. Instead of using localhost, use localhost.  <- notice the fullstop / period on the end of the localhost. This makes it look external, so the requests show up in your Fiddler GUI.
    image

And there you go! A working Fiddler session off the Localhost.

Posted in Uncategorized | Leave a comment

Employers: Codility for testing your applicants!

This is about Codility Candidate Testing

I just did a test on Codility and it’s great! In fact, this is sooo much than PreVisor (http://select2perform.com) which I had to use the other day.

You can write your code in any language (as long as its in Java, C#, C++, Javascript, Ruby, Pearl, Python, Pascal, C and I think a few more)

image

Maybe I like it because I did so well :)

image

 

You have a simple test system initially so you can check if your code compiles and fits the initial test. Then you submit it to the hard core tests which tries to break it, and you get a score.

 

The analysis is very cool:

image

And I know why i failed test 4. Should have used double instead of int. But that’s why you use TDD, ‘cause those mistakes are easily made. 

Posted in Uncategorized | Leave a comment

World Countries – Simple Outlines in XML format

I needed the outlines of most countries for a simple GIS project that I’m doing. I managed to find a world simple shapes file from http://mappinghacks.com/ called TM_WORLD_BORDERS_SIMPL-0.2.zip

This was in a shapes format used by ARC GIS and the likes, but I needed it in an easy to consume manner i.e. XML

So taking it, feeding it through MapWindow GIS and a  shareware  plugin “Shape2Earth”  (a shapefile to KML converter) I received a KML file out the other side.

As it was a bit bloated, I built a console app using some hideous code turned it into a nice usable XML doc.

image

Here’s an example of the result showing the UK, France, etc, produced in DeepEarth:

image

Deciphering should be pretty easy. Here is the rundown:

A country has a name and ISO3 tag and one to many polygons.

Each polygon has one outer bound (outer island)  and zero to many inner bounds (inner islands) for where the country isn’t (as in Swaziland inside South Africa).

Easy stuff.  Here’s the zipped download:

Let me know where you use it!

There is no licence except where mappinghacks.com applies one, but I couldn’t see one there. Tell me if I’m wrong.

Posted in GIS | Tagged , , , , | Leave a comment

Firefox Ubiquity Command for StackOverflow

Just made a quick and dirty Ubiquity command for StackOverflow searches.

Download from GitHub:  Ubiquity StackOverflow Search 

Don’t know Ubiquity?

It’s like a Command Line for the web but… it’s really cool! Trust me. Watch the clip below. Sure it starts out dull, but then so does District 9. Then bam, explosions and stuff! It’s not 0.1 anymore either, so ignore that bit.

The link to get it is https://mozillalabs.com/ubiquity/
Then go to about:ubiquity and read the Commands. There are lots!

Posted in Uncategorized | Leave a comment

Is Firefox using all your CPU? It’s probably Adobe Flash

 

But how do you fix it? The weird thing is that to fix it, you install another program: Adobe Shockwave

Don’t know how or why, but it fixes the high CPU usage where Firefox sits at 99% or 100%

Strange huh?

You should probably update Adobe Flash while you’re at it anyway. Do it first, that way it’s all associated nicely.

Posted in Tips | Tagged | Leave a comment

Godaddy Hosting – Medium Trust vs Inversion of Control

Whatever I think of Godaddy, they haven’t caused me too much pain yet, just minor inconvenience. This time it’s my precious StructureMap.

StructureMap, I like it and alot of people do, but it just won’t work under Medium Trust! So it’s either time to change Hosts, or change IoC container. Pretty obvious which one is the easier choice here.

So what choice do you have? Well not much. So the answer is:

Unity from Microsoft Patterns & Practices*

Here’s a nice manual to go with it.

And what’s not able to be run in medium / partial trust:

Windsor Castle
Spring.Net
StructureMap

There was someone who was explaining how to download and build Spring.Net to allow it to run under Medium Trust, but that seems pretty likely to cause issues when you hack code (try to ignore my NHibernate post when I say that).

It may be the same for the other 2, but off the bat, Unity wins.

*Caveat: Unity is restricted in what it can do when run without ReflectionPermission (which is what Medium Trust disallows), but typically this won’t affect much from the normal IoC behaviour.  The restrictions are explained on this MSDN doc, but it’s to do with internal and private constructors and properties. If it’s public you should be sweet.

Posted in ASP.Net, godaddy | Tagged , , | Leave a comment

NHibernate, IoC and removing that damn Log4Net dependency

Ok, so Log4Net is not that bad. It is a very good logging system, etc…

So how do you perform IoC with the NHibernate logger? Well, you can’t. Unless you are ready to HACK CODE.

That’s the brilliant thing about open source. Take it and modify until its the shade of green that suits you.

The First Warning

If you modify the DLL for NHibernate, then all associated DLL’s break.
For me this means FluentNHibernate wont like you. So you will have to rebuild that too for the new NHibernate DLL.

According to the bug report for exactly this issue, in the future log4net will be removed as a dependency (yay). For the logger interface Commons.Logging has been “sort-of” chosen. Meaning: you should  use the ILog interface from Commons.Logging for your Log interface! Make’s it a bit more future proof.

What I did to have IoC : 2nd Warning  – This is not a concise walkthrough

  1. Download the source code of
    1. NHibernate – Under the Browse Files you will find a SRC version.
    2. FluentNHibernate – Download from GitHub
    3. Commons.Logging 
  2. Create a new Interface called ILog that is inside the NHibernate project. This is because it will be used as an adapter for the Commons.Logging. It’s probably best to put under a smart namespace like NHibernate.Logging.ILog
  3. Create a LogManager class that does the same thing as the log4net LogManger, but using the Commons.Logging assembly. I know this is vague, but my implementation wasn’t very good. The idea is that when NHibernate is called, the LogManager is setup using the Commons.Logging.ILog object that was returned by my  IoC object  factory.
  4. Remove the References of log4net from the projects
  5. Replace all namespaces of log4net with the namespace of your new Interface and LogManager (say NHibernate.Logging).
  6. Remove all Log4Net residue, like Cfg calls and XML setup arguments.
  7. Build and everything should be happy.
Posted in ASP.Net | Tagged , , | Leave a comment

Global.asax Events and Descriptions

This is a direct quote from the Wikipedia page on Global.asax. Just thought it would be nice to a quick list to refer to.

  • Application_Init
    • Fires when the application initializes for the first time.
  • Application_Start
    • Fires the first time an application starts.
  • Session_Start
    • Fires the first time when a user’s session is started.
  • Application_BeginRequest
    • Fires each time a new request comes in.
  • Application_EndRequest
    • Fires when the application terminates.
  • Application_AuthenticateRequest
    • Indicates that a request is ready to be authenticated.
  • Application_Error
    • Fires when an unhandled error occurs within the application.
  • Session_End
    • Fires whenever a single user Session ends or times out.
  • Application_End
    • Fires when the application ends or times out (Typically used for application cleanup logic).
Posted in Uncategorized | Leave a comment