The specified cast from a materialized 'System.Guid' type to the 'System.Int32' type is not valid.

We have several WCF services that have concurrency mode of Multiple and InstanceContextMode of Single. Our architecture focuses on a loosely coupled model using constructor-based dependency injection. This in turn is implemented using Unity 2.0 (web.config of each service has mappings between interfaces and types defined in a unity container section). One of our dependencies is a DAL assembly (data access layer) that uses Entity Framework 4 to communicate with MSSql Server. The classes that do the talking to the database are also included in the unity mapping.

Everything is great when we run our integration tests. But when we move to our performance environment to run load tests (2, 3, 4 concurrent users) we start seeing the following error:

System.InvalidOperationException: The 'auth_token' property on 'Session' could not be set to a 'Int32' value. You must set this property to a non-null value of type 'Guid'.

With the following stack:

at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
at System.Data.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String typeName)
at lambda_method(Closure , Shaper )
at System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
at lambda_method(Closure , Shaper )
at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at System.Linq.Queryable.First[TSource](IQueryable`1 source)
at MISoa.DataAccessLayer.Authentication.Authentica
Edit
Report