WCF Data Service: The type initializer for 'System.Data.Services.Client.TypeSystem' threw an exception.
In an application, we are consuming an OData feed. In development, this worked without any issue but the moment we deployed the application to our test environment, it started to fail with the following exception:
The type initializer for 'System.Data.Services.Client.TypeSystem' threw an exception.
Looking in the logs on the server, we found the following stacktrace:
Sync.exe Information: 0 : Error occured during synchronization: The type initializer for 'System.Data.Services.Client.TypeSystem' threw an exception.
Sync.exe Information: 0 : Stacktrace: at System.Data.Services.Client.TypeSystem.IsPrivate(PropertyInfo pi)
at System.Data.Services.Client.ResourceBinder.PatternRules.MatchNonPrivateReadableProperty(Expression e, PropertyInfo& propInfo, Expression& target)
at System.Data.Services.Client.ResourceBinder.VisitMemberAccess(MemberExpression m)
at System.Data.Services.Client.ALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.ALinqExpressionVisitor.VisitBinary(BinaryExpression b)
at System.Data.Services.Client.ResourceBinder.VisitBinary(BinaryExpression b)
at System.Data.Services.Client.ALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.ALinqExpressionVisitor.VisitLambda(LambdaExpression lambda)
at System.Data.Services.Client.ALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.ALinqExpressionVisitor.VisitUnary(UnaryExpression u)
at System.Data.Services.Client.ALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.ALinqExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original)
at System.Data.Services.Client.ALinqExpressionVisitor.VisitMethodCall(MethodCallExpression m)
at System.Data.Services.Client.ResourceBinder.VisitMethodCall(MethodCallExpression mce)
at System.Data.Services.Client.ALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.ResourceBinder.AnalyzeProjection(MethodCallExpression mce, SequenceMethod sequenceMethod, Expression& e)
at System.Data.Services.Client.ResourceBinder.VisitMethodCall(MethodCallExpression mce)
at System.Data.Services.Client.ALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
at System.Data.Services.Client.ResourceBinder.Bind(Expression e, DataServiceContext context)
at System.Data.Services.Client.DataServiceQueryProvider.Translate(Expression e)
at System.Data.Services.Client.DataServiceQuery`1.Execute()
at System.Data.Services.Client.DataServiceQuery`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Sync.Synchronizer.GetChangedPortfolios(DateTime lastSyncDate)
at Sync.Synchronizer.Start(DateTime lastSyncDate)
at Sync.Program.StartSynchronization(DateTime lastSyncDate)
at Sync.Program.Main(String[] args)
There are 2 things you need to check if you see this error:
- Are all required assemblies copied to the server? (In our case Copy Local was set to false for some assemblies). You’ll need the following assemblies to be copied:
- System.Spatial.dll
- Microsoft.Data.Edm.dll
- Microsoft.Data.OData.dll
- Microsoft.Data.Services.dll
- Microsoft.Data.Services.Client.dll
- Do all these assemblies have the same version number? (In our case, one project contained a newer version of System.Spatial.dll)