KSP-CKAN/CKAN — pull request #406 by btbonval (2014-11-18 18:47:15+00:00)
Title: CmdLine Tests - needs some help

This is not an actual pull request (at least not yet).

I'm trying to establish a DisposableKSP instance for testing CmdLine and make it the default instance.

I'm running into an issue at this line:
https://github.com/btbonval/CKAN/compare/test_cmdline#diff-716970b8571614be1169ff1a750ad611R47

The problem starts in my code and moves into a null pointer exception in `KSP.PortableDir()`:
```
System.NullReferenceException : Object reference not set to an instance of an object
at CKAN.KSP.PortableDir () [0x00000] in :0
at CKAN.KSPManager._GetPreferredInstance () [0x00000] in :0
at CKAN.KSPManager.GetPreferredInstance () [0x00000] in :0
at CKAN.CmdLine.MainClass.Main (System.String[] args) [0x00000] in :0
at CmdLineTests.Main._CallOverMods (System.String action, System.String[] mod_list) [0x00000] in :0
```

The problem comes from `Assembly.GetEntryAssembly()` returning `null`, so `.Location` cannot be determined here:
https://github.com/KSP-CKAN/CKAN/blob/master/CKAN/CKAN/KSP.cs#L116

Since `PortableDir()` can be `null`, I had tried to circumvent the error by returning `null` if `Assembly.GetEntryAssembly()` was `null`. That starts creating a new error:
```
CKAN.KSPManagerKraken : Tried to set KSP instance twice!
at CKAN.KSPManager.GetPreferredInstance () [0x00000] in :0
at CKAN.CmdLine.MainClass.Main (System.String[] args) [0x00000] in :0
at CmdLineTests.Main._CallOverMods (System.String action, System.String[] mod_list) [0x00000] in :0
```

Perhaps these problems are because I am calling `Main()` inside the test program, which causes issues initializing the executable properly?
e.g.
https://github.com/btbonval/CKAN/compare/test_cmdline#diff-716970b8571614be1169ff1a750ad611R82