Short solution for short problems

iOS: How to add a precompiled header file

Sounds stupid, since before this was default behaviour. Now a project starts without. Adding can sometimes be a pain, since just adding the file is not enough. 

This post helped me to the solution, although I head to change 1 more thing.

So the thing was to open the Build settings in xcode of your target. You will see a search box on the upper right corner.

Search for: GCC_PRECOMPILE_PREFIX_HEADER and set it to Yes.

Next search for: GCC_PREFIX_HEADER and add the name of the file including the extension ".pch".

Now it was still not compiling, because the file was not in the root directory of where the project file was, but rather in a subdirectory. So I had to put in the value:


Now everything compiled again and the prefix header is loaded!

LINQ: Left outer join (non relational DB)

If you want to get data en detail data, from for example Routes. You will need to select the data and the details and then select only the distinct records. If your model framework support relations (Foreing key) then it easier to accomplish with LINQ. But in my case the relations were not set in the object model.

So this is how I get all routes with a detail that have a certain status, or routes that have no details:

var routes = from r in Ents.Routes

                from rd in Ents.RouteDetails.Where(s => s.RouteID == r.RouteID).DefaultIfEmpty()

                where (rd.Status == 10 || rd.Status == null)

select r;


var distinctRoutes = routes.Distinct<Routes>();

I cannot use the join with LINQ because there are no relations between the objects, so I select all routes with details that have status 10 or routes that have no details. The .DefaultIfEmpty will add an empty RouteDetail object to the list if it has no detail. So in the were I can check for null, then it includes the Routes that have no details. Now there can be duplicates because some routes have more detials. If we only select the Routes (select r) then the object with different details have the same Route object, so the distinct at the end will clear the duplicates.


VS 2010/2012 crashes when opening designer.

This can be a really time eating problem. In my case this problem came suddenly, in a class that didn't change for a long time. 

The error looked something like this:

Faulting application name: devenv.exe, version: 10.0.40219.1, time stamp: 0x4d5f2a73

Faulting module name: KERNELBASE.dll, version: 6.1.7601.18409, time stamp: 0x53159a86

Exception code: 0xe0434352

Fault offset: 0x0000c42d

Faulting process id: 0x1898

Faulting application start time: 0x01d00d526a76a093

Faulting application path: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe

Faulting module path: C:\Windows\syswow64\KERNELBASE.dll

Report Id: f6f5bf23-7945-11e4-afad-02004e435049

When you experience this kind of behavior, it could be that an add-in is causing the problem or some update of software. In our case this didn't help.

So at the end we found that is was a problem in the page load of a form, it gets executed when you open the designer. We had some code that went to the database. The strange this is that this worked for years and now suddenly it starts crashing on all development PC's. The solution to this problem is to prevent the code from being run at design time by using the System.ComponentModel.LicenseManager.UsageMode:

Private Sub BaseForm_Load(ByVal sender As Object, ByVal e As System.EventArgs)

Handles Me.Load


       If System.ComponentModel.LicenseManager.UsageMode = System.ComponentModel.LicenseUsageMode.Runtime Then



       End If

    Catch ex As Exception


    End Try


End Sub

.Net: using dynamic columns in orderby with LINQ

I have a LINQ query that uses dynamic order by columns. The web client passes an array of key value objects and based on these objects I want to order the LINQ query.

After some googling around I found that the System.Linq.Dynamic namespace has the solution to this!

Add the Linq.Dynamic using the nuget package manager.

Then add the namespace to your class:

using System.Linq.Dynamic;

Now I dynamically build the order by string:

string orderby = String.Join(", ", orderByList.Select(o => o.Key + " " + o.Value ));

For example the orderby string holds this value “SalesOrder DESC CustomerName DESC”. Next we just add the string to the orderby, because you added the namespace in your class, the extensions is available and you can pass a string to the orderby:

List<PlanOrders> lst = PlanEnts.PlanOrders.Where(p => (p.PlanStatus < 100)).OrderBy(orderby).ToList();

LINQ: Group by multiple properties and select only max per group.

I want to get some records from an existing list. The records have to be delivered=false, then from these records I only want the record with the maximum sales order position.

The records could look like this: (ShipID,  SalesOrder, created, createdby, modified, modifiedby)

8431  35602577830  2014-10-15 08:48:29.750  Deraeve Mark @ CORDOBA  2014-10-15 08:57:30.543  MDeraeve@GPA.MES.009

8431  35602577840  2014-10-15 08:48:35.497  Deraeve Mark @ CORDOBA  2014-10-15 08:57:30.553  MDeraeve@GPA.MES.009

8432  24500068130  2014-10-15 09:02:54.577  Deraeve Mark @ CORDOBA  2014-10-15 09:03:45.313  MDeraeve@GPA.MES.009

8433  35602579130  2014-10-15 09:03:13.167  Deraeve Mark @ CORDOBA  2014-10-15 09:03:40.630  MDeraeve@GPA.MES.009

8434  35602583730  2014-10-15 14:32:22.790  Deraeve Mark @ CORDOBA  2014-10-15 14:32:22.790  Deraeve Mark @ CORDOBA

8434  35602583740  2014-10-15 14:32:22.803  Deraeve Mark @ CORDOBA  2014-10-15 14:32:22.803  Deraeve Mark @ CORDOBA

So I only want the get these records at the end:

8431  35602577840  2014-10-15 08:48:29.750  Deraeve Mark @ CORDOBA  2014-10-15 08:57:30.553  MDeraeve@GPA.MES.009

8432  24500068130  2014-10-15 09:02:54.577  Deraeve Mark @ CORDOBA  2014-10-15 09:03:45.313  MDeraeve@GPA.MES.009

8433  35602579130  2014-10-15 09:03:13.167  Deraeve Mark @ CORDOBA  2014-10-15 09:03:40.630  MDeraeve@GPA.MES.009

8434  35602583740  2014-10-15 14:32:22.790  Deraeve Mark @ CORDOBA  2014-10-15 14:32:22.803  Deraeve Mark @ CORDOBA

Now the LINQ query how to get this:

public List<GP_MES_ShippingToDo> GetShippingToDoOrders()


var query = Ents.GP_MES_ShippingToDo.Where(s => s.Delivered == false)

                .GroupBy(x => new { x.ShipID, x.SalesOrder })

                .Select(group => group.Where(x => x.SalesOrderPos == group.Max(y => y.SalesOrderPos))


return query.ToList();




iOS: Unhandled exception handling

Application crashes are very frustrating, especially if you do not know what happened. Lets says a memory problem on an old iPad 2 or recently we had a missing storyboard, but the app only crashed when archived and deployed, not when we were debugging. Probably some files were not cleaned and still  there in debug mode. Anyway, a very easy way to capture any unhandled exception is to add this small piece of code to your app delegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions



Then add the onUncaughtException method and do whatever you want to do with it. I write the error to the internal DB, so later I can see on the client what happened.

void onUncaughtException(NSException* exception)


  NSLog(@"uncaught exception: %@", exception.description);

  NSArray *backtrace = [exception callStackSymbols];

  NSString *version = [[UIDevicecurrentDevice] systemVersion];

  NSString *message = [NSStringstringWithFormat:@"OS: %@.\nSummary:%@\nBacktrace:\n%@",





  [DBStoreCreateErrorLog:@"Uncaught exception occurred"AndText:message];


Windows Experience index on Windows 8

There are a lot of posts about this, this one is just very basic how to run the test and get the result with a lot of screen shots.

First run command prompt, make sure you're logged in as admin, then enter "winsat prepop" and press enter:

The test will run fir a while, have patience. At the end you will return to the prompt:

Now to analyse these results we need to open powershell, you can find this here:


In the powershell prompt, enter following command:"Get-WmiObject -Class Win32_WinSAT". The system will now show your scores:

The demo was done in windows 7, the commands are also existing there.

iOS: Navigate back to root view controller then navigate away in one action.

There are several ways to reach this goal. The goal being to navigate from any view controller in the navigation controllers view controller collection, back to the root view controller and then forward to another controller. Why, because sometimes you want the back of you're new view controller to be the root view controller and not the previous controller. In my case I end an editing proces and the user has to be directed back to the edit template overview page. But when the user then pushes back, he needs to end up in the root view.

So here's the code, what we are doing it simple, just alter the list of view controller from the navigation controller:

        NSArray *viewControllers = senderVC.navigationController.viewControllers;

        NSMutableArray *newViewControllers = [NSMutableArray array];


        // preserve the root view controller

        [newViewControllers addObject:[viewControllers objectAtIndex:0]];

        // add the new view controller

        UIStoryboard * sb = [UIStoryboardstoryboardWithName:@"TemplatesStoryboard"bundle:nil];

        UIViewController * vcTo = [sb instantiateInitialViewController];

        [newViewControllers addObject:vcTo];

        // animatedly change the navigation stack 

        [senderVC.navigationController setViewControllers:newViewControllers animated:YES];

First we take the root view controller from the index 0, then add it to our newviewcontroller array. Next just init your second view, were you want the user to end up and add it to the newviewcontrollers array. Last we set the current view controller which has to be in the navigation controllers view controllers collection.

This piece of code is called from a top menu action, that is added dynamically to each view controller. This code does the trick!

.Net Web API and querystrings


Creating a web api is very easy and powerfull. If you want to use querystrings, its not done with the ols Request.Querystrings, but rather like this:

publicIEnumerable<GALV_ACCOUNT> GetAllAccounts()


    var q = Request.GetQueryNameValuePairs().Where(nv => nv.Key =="q").Select(nv => nv.Value).FirstOrDefault();

    if (q != null && q != string.Empty)


        var result = accounts.Where(a=>a.Name.ToLower().StartsWith(q.ToLower()));

        return result;




        thrownewException("Please specify a search query");



Then you can call the method like this:



UIButton with gradient background and image on it!

I got a request for an app with lots of gradient styles on all kinds of controls.

When I applied the typical code to the UIButton, the text stayed on but the image disappeared.

So I found that the solution is to bring the UIImageview to the front like this:

[vw bringSubviewToFront:vw.imageView];

Now the complete code to make the UIButton look like this:

is this:

+ (void) MakeNormalButton:(UIButton *) vw


    CAGradientLayer *gradient = [CAGradientLayerlayer];

    gradient.frame = vw.bounds;

    gradient.colors = [NSArrayarrayWithObjects:(id)[[UIColorwhiteColor] CGColor], (id)[[UIColorlightGrayColor] CGColor], nil];

    [vw.layer insertSublayer:gradient atIndex:0];

    vw.layer.masksToBounds = NO;

    vw.layer.shouldRasterize = YES;




    [vw.layersetShadowOffset:CGSizeMake(2.0f, 2.0f)];


    [vw bringSubviewToFront:vw.imageView];