title: Calling System.Linq.Enumerable.Any throws exception on Windows 10
body: <p>I have got a windows desktop application which uses EF4 (I know it is old) as ORM to connect to database and I am experiencing a weird issue on Windows 10 when I call "Any" for one of the object types in database. The following is the exception:</p>
  
  <p><strong>Exception Info:</strong> </p>
  
  <blockquote>
    <p>System.TypeInitializationException Stack:    at
    System.Data.Objects.ObjectQuery<code>1[[System.__Canon, mscorlib,
    Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089]].GetResults(System.Nullable</code>1)
    at System.Data.Objects.ObjectQuery<code>1[[System.__Canon, mscorlib,
    Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089]].System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator()
    at System.Data.Entity.Internal.Linq.InternalQuery</code>1[[System.__Canon,
    mscorlib, Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089]].GetEnumerator()    at
    System.Data.Entity.Infrastructure.DbQuery<code>1[[System.__Canon, mscorlib,
    Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089]].System.Collections.Generic.IEnumerable&lt;TResult&gt;.GetEnumerator()
    at System.Linq.Enumerable.Any[[System.__Canon, mscorlib,
    Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable</code>1)
    at
    Bootstrapper.LoginModel.HasUserAcceptedTraining(Int32)</p>
  </blockquote>
  
  <p>I have tried the exact same application on different Windows and also on another Windows 10 machines and it is not happening. I have tried the following:</p>
  
  <ol>
  <li>Checked the database and it was fine</li>
  <li>Checked the .NET version and compared it with Windows 10 machine the application works fine on it and it was the same (Target version 4.0.0, Version 4.6.0079, Release 393295)</li>
  <li>Tried fusion log to see whether there is any problem in loading any assembly</li>
  <li>Re-installed the application - no change</li>
  </ol>
  
  <p>I don't know what else I can do to find the issue? Has anyone experience such an issue on windows 10? Any thought on that?</p>
  
  <p><strong>Update</strong> :
  I have added exception handling to the application and now this is the exception I am getting after running the application:</p>
  
  <p>[2015-09-08 13:21:07.8404] [Error   ] - Exception Occurred in Method MainForm_Load - Details : The type initializer for 'ProxyTypeBuilder' threw an exception.,    at System.Data.Objects.Internal.EntityProxyFactory.ProxyTypeBuilder.MarkAsNotSerializable(FieldBuilder field)
     at System.Data.Objects.Internal.EntityProxyFactory.ProxyTypeBuilder.RegisterInstanceField(FieldBuilder field, Boolean serializable)
     at System.Data.Objects.Internal.LazyLoadImplementor.Implement(TypeBuilder typeBuilder, Action<code>2 registerField)
     at System.Data.Objects.Internal.EntityProxyFactory.ProxyTypeBuilder.get_TypeBuilder()
     at System.Data.Objects.Internal.EntityProxyFactory.ProxyTypeBuilder.CreateType(ModuleBuilder moduleBuilder)
     at System.Data.Objects.Internal.EntityProxyFactory.BuildType(ModuleBuilder moduleBuilder, ClrEntityType ospaceEntityType)
     at System.Data.Objects.Internal.EntityProxyFactory.TryCreateProxyType(EntityType ospaceEntityType)
     at System.Data.Objects.Internal.EntityProxyFactory.GetProxyType(ClrEntityType ospaceEntityType)
     at System.Data.Common.Internal.Materialization.Translator.Visit(EntityColumnMap columnMap, TranslatorArg arg)
     at System.Data.Query.InternalTrees.EntityColumnMap.Accept[TResultType,TArgType](ColumnMapVisitorWithResults</code>2 visitor, TArgType arg)
     at System.Data.Common.Internal.Materialization.Translator.ProcessCollectionColumnMap(CollectionColumnMap columnMap, TranslatorArg arg, ColumnMap discriminatorColumnMap, Object discriminatorValue)
     at System.Data.Common.Internal.Materialization.Translator.Visit(SimpleCollectionColumnMap columnMap, TranslatorArg arg)
     at System.Data.Query.InternalTrees.SimpleCollectionColumnMap.Accept[TResultType,TArgType](ColumnMapVisitorWithResults<code>2 visitor, TArgType arg)
     at System.Data.Common.Internal.Materialization.Translator.TranslateColumnMap[TRequestedType](QueryCacheManager queryCacheManager, ColumnMap columnMap, MetadataWorkspace workspace, SpanIndex spanIndex, MergeOption mergeOption, Boolean valueLayer)
     at System.Data.Common.Internal.Materialization.ShaperFactory.TypedShaperFactoryCreator</code>1.TypedCreate(QueryCacheManager cacheManager, ColumnMap columnMap, MetadataWorkspace metadata, SpanIndex spanInfo, MergeOption mergeOption, Boolean valueLayer)
     at System.Data.Common.Internal.Materialization.ShaperFactory.Create(Type elementType, QueryCacheManager cacheManager, ColumnMap columnMap, MetadataWorkspace metadata, SpanIndex spanInfo, MergeOption mergeOption, Boolean valueLayer)
     at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection<code>1 compiledQueryParameters, AliasGenerator aliasGenerator)
     at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable</code>1 forMergeOption)
     at System.Data.Objects.ObjectQuery<code>1.GetResults(Nullable</code>1 forMergeOption)
     at System.Data.Objects.ObjectQuery<code>1.System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator()
     at System.Data.Entity.Internal.Linq.InternalQuery</code>1.GetEnumerator()
     at System.Data.Entity.Infrastructure.DbQuery<code>1.System.Collections.Generic.IEnumerable&lt;TResult&gt;.GetEnumerator()
     at System.Linq.Enumerable.Any[TSource](IEnumerable</code>1 source)
     at HasUserAcceptedTraining(Int32 userID)</p>