locked
The 'xxx' property on 'yyy' could not be set to a 'Int32' value. You must set this property to a non-null value of type 'String'. RRS feed

  • Question

  • Hi!

    By some unknown reason, and random, we are getting this sequence of exceptions:

    1-  The data reader has more than one field. Multiple fields are not valid for EDM primitive types.

     

    2-  System.IndexOutOfRangeException: Index was outside the bounds of the array.

       at System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32 i)

       at System.Data.SqlClient.SqlDataReader.IsDBNull(Int32 i)

     

    3-  System.InvalidOperationException: The 'Query' property on 'Parametro' could not be set to a 'Boolean' value. You must set this property to a non-null value of type 'String'.

       at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)

       at lambda_method(Closure , Shaper )

     

    4-  System.Data.MetadataException: At least one SSDL artifact is required for creating StoreItemCollection.

       at System.Data.Metadata.Edm.MetadataCache.GetOrCreateStoreAndMappingItemCollections(String cacheKey, MetadataArtifactLoader loader, EdmItemCollection edmItemCollection, Object& entryToken)

     

    5-  System.Exception: The data reader has more than one field. Multiple fields are not valid for EDM primitive types. ---> System.Data.EntityCommandExecutionException: The data reader has more than one field. Multiple fields are not valid for EDM primitive types.

    at System.Data.Query.InternalTrees.ColumnMapFactory.CreateColumnMapFromReaderAndType(DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, Dictionary`2 renameList)

     

    This exceptions does not follow any patern. We have to close the program and run it again…

    It’s like for some reason the EF gets “dizzy”…

    Does anyone have any idea what can be happening?


    Best Regards, Daniel.
    Friday, June 10, 2011 1:21 AM

Answers

  • Hi Daniel,

    Thanks for your feedback.

    Are you using EF in WebApplication or multi-thread scenario?

    The ObjectContext class is not thread safe. The integrity of data objects in an ObjectContext cannot be ensured in multithreaded scenarios.

    you can refer this blog: http://cgeers.com/2009/02/21/entity-framework-objectcontext/

    Have a nice day.

     


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alan_chen Thursday, June 30, 2011 4:00 AM
    Friday, June 17, 2011 8:07 AM
  • Hi I think you are right!

    We are using multiple threads in a window application. Some of them access to the same Context.

    I will fix the code to create a new Context and see what happens.

    Thanks a lot!

    I will post my feedback after publishing the new version....
    Best Regards, Daniel.
    • Marked as answer by dKaco Monday, June 27, 2011 2:23 AM
    Friday, June 17, 2011 3:40 PM

All replies

  • Hi Daniel,

    Welcome!

    The IndexOutOfRangeException is thrown when an attempt is made to access an element of an array or collection with an index that is outside the bounds of the array or less than zero.

    >>System.InvalidOperationException: The 'Query' property on 'Parametro' could not be set to a 'Boolean' value. You must set this property to a non-null value of type 'String'

    Please check whether the Query's value is string type. You can use this way to define this property: Public string ? Query{get; set;}

    If it doesn't solve your problem, would you please feel free to give us some code, thanks for understanding.

    Have a nice day.

     


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 13, 2011 2:23 AM
  • Hi Alan,
    Thank you for your quick reply.
    I understand what all exceptions are about, the problem is that there’s no logic about this exceptions.
    Everything works fine; suddenly it’s like the context looses it healthy state, after that, every query throws an Exception (not following a known pattern).
    Closing the window (that close the context and create a new one) makes everything work as expected again.
    We are using EF 4.0 with Self Tracking Entities and precompiled views.
    Best Regards, Daniel.
    Tuesday, June 14, 2011 1:04 PM
  • A very common Exception we are getting is:

    At least one SSDL artifact is required for creating StoreItemCollection.

     Method                 :  System.Data.Mapping.StorageMappingItemCollection GetOrCreateStoreAndMappingItemCollections(System.String, System.Data.Metadata.Edm.MetadataArtifactLoader, System.Data.Metadata.Edm.EdmItemCollection, System.Object ByRef)

     

    Inner Ex                :  System.Data.MetadataException: At least one SSDL artifact is required for creating StoreItemCollection.

       at System.Data.Metadata.Edm.MetadataCache.GetOrCreateStoreAndMappingItemCollections(String cacheKey, MetadataArtifactLoader loader, EdmItemCollection edmItemCollection, Object& entryToken)

       at System.Data.EntityClient.EntityConnection.LoadStoreItemCollections(MetadataWorkspace workspace, DbConnection storeConnection, DbProviderFactory factory, DbConnectionOptions connectionOptions, EdmItemCollection edmItemCollection, MetadataArtifactLoader artifactLoader)

       at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)

       at System.Data.EntityClient.EntityConnection.InitializeMetadata(DbConnection newConnection, DbConnection originalConnection, Boolean closeOriginalConnectionOnFailure)

       at System.Data.EntityClient.EntityConnection.Open()

       at System.Data.Objects.ObjectContext.EnsureConnection()

       at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)

       at System.Data.Objects.ObjectQuery`1.Execute(MergeOption mergeOption)


    Best Regards, Daniel.
    Tuesday, June 14, 2011 4:01 PM
  • Hi Daniel,

    Thanks for your feedback.

    Are you using EF in WebApplication or multi-thread scenario?

    The ObjectContext class is not thread safe. The integrity of data objects in an ObjectContext cannot be ensured in multithreaded scenarios.

    you can refer this blog: http://cgeers.com/2009/02/21/entity-framework-objectcontext/

    Have a nice day.

     


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alan_chen Thursday, June 30, 2011 4:00 AM
    Friday, June 17, 2011 8:07 AM
  • Hi I think you are right!

    We are using multiple threads in a window application. Some of them access to the same Context.

    I will fix the code to create a new Context and see what happens.

    Thanks a lot!

    I will post my feedback after publishing the new version....
    Best Regards, Daniel.
    • Marked as answer by dKaco Monday, June 27, 2011 2:23 AM
    Friday, June 17, 2011 3:40 PM
  • Hi dKaco,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 22, 2011 3:30 AM
  • Hi!

    By now we are not getting those exceptions so I think that was the problem!

    Thanks!


    Best Regards, Daniel.
    Monday, June 27, 2011 2:23 AM