This error is coming up when you try to execute a linq query. After checking this out we found out how to resolve this.
What happens is that we create an organization proxy variable and then cast to service context object. Before you cast to service context object you need to enable proxy types in organization service proxy. You can use the code below to do that and that would prevent you from seeing the above error and getting your task done.