The specified cast from a materialized 'System.Byte[]' type to a nullable 'System.Byte' type is not valid

Hanieh Kiaee
    public virtual ObjectResult<Nullable<byte>> GetPersonalPicture3(Nullable<System.Guid> contactId)
    {
        var contactIdParameter = contactId.HasValue ?
            new ObjectParameter("ContactId", contactId) :
            new ObjectParameter("ContactId", typeof(System.Guid));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<byte>>("GetPersonalPicture3", contactIdParameter);
    }

in the bottom Code, I Faced this error "The specified cast from a materialized 'System.Byte[]' type to a nullable 'System.Byte' type is not valid."

byte x = DBPSO.GetPersonalPicture3(ProfileID).FirstOrDefault() ?? 0000;

in addition, I've tested this Code too

var x = DBPSO.GetPersonalPicture3(ProfileID).Select(B => B.Value).ToArray();

string binaryPic = System.Text.Encoding.Unicode.GetString(x);
bubi

The picture on the db is probably a varbinary so an array of byte and not a single byte. Try this:

public virtual ObjectResult<byte[]> GetPersonalPicture3(Nullable<System.Guid> contactId)
{
    var contactIdParameter = contactId.HasValue ?
        new ObjectParameter("ContactId", contactId) :
        new ObjectParameter("ContactId", typeof(System.Guid));

    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<byte[]>("GetPersonalPicture3", contactIdParameter);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Stored procedure :The specified cast from a materialized 'System.String' type to a nullable 'System.Single' type is not valid

From Dev

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

From Dev

The specified cast from a materialized 'System.Int16' type to the 'System.String' type is not valid

From Dev

The specified cast from a materialized 'System.DateTime' type to the 'System.String' type is not valid

From Dev

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

From Dev

The specified cast from a materialized 'System.DateTime' type to the 'System.String' type is not valid

From Dev

Unable to cast object of type 'WhereSelectArrayIterator`2[System.String,System.Byte]' to type 'System.Byte[]'. Vb.net

From Dev

Migrating working ServiceStack to live causes Unable to cast object of type 'System.Byte' to type 'System.String'

From Dev

Unable to cast object of type 'System.Int32' to type 'System.Byte[]'

From Dev

Unable to cast object of type 'System.DBNull' to type 'System.Byte[]' when record does exist

From Dev

Unable to cast object of type 'System.Byte[]' to type 'System.String'

From Dev

Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'

From Dev

Error-Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'

From Dev

What does the type System.Byte[*] mean and can I cast it to a byte[] without copying?

From Dev

Unable to cast object of type 'Microsoft.SqlServer.Dts.Pipeline.BlobColumn' to type 'System.Byte[]'

From Dev

"Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'." error in Photo: why and how do I fix it?

From Dev

Type cast issue from int to byte using final keyword in java

From Dev

"System.InvalidCastException: Specified cast is not valid" - DateTime

From Dev

Specified cast is not valid - System.InvalidCastException

From Dev

Error: The cast to value type 'System.Int32' failed because the materialized value is null

From Dev

The cast to value type 'System.Int32' failed because the materialized value is null.

From Dev

'System.Guid' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type

From Dev

Specified cast is not valid in date nullable

From Dev

How to cast a byte array to a primitive type in Rust?

From Dev

How to cast a byte array to a primitive type in Rust?

From Dev

Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type

From Dev

Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type

From Dev

Cannot cast DBNull.Value to type 'System.DateTime', Please use nullable types

From Dev

Invalid cast from 'System.Double' to 'System.Nullable`

Related Related

  1. 1

    Stored procedure :The specified cast from a materialized 'System.String' type to a nullable 'System.Single' type is not valid

  2. 2

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

  3. 3

    The specified cast from a materialized 'System.Int16' type to the 'System.String' type is not valid

  4. 4

    The specified cast from a materialized 'System.DateTime' type to the 'System.String' type is not valid

  5. 5

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

  6. 6

    The specified cast from a materialized 'System.DateTime' type to the 'System.String' type is not valid

  7. 7

    Unable to cast object of type 'WhereSelectArrayIterator`2[System.String,System.Byte]' to type 'System.Byte[]'. Vb.net

  8. 8

    Migrating working ServiceStack to live causes Unable to cast object of type 'System.Byte' to type 'System.String'

  9. 9

    Unable to cast object of type 'System.Int32' to type 'System.Byte[]'

  10. 10

    Unable to cast object of type 'System.DBNull' to type 'System.Byte[]' when record does exist

  11. 11

    Unable to cast object of type 'System.Byte[]' to type 'System.String'

  12. 12

    Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'

  13. 13

    Error-Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'

  14. 14

    What does the type System.Byte[*] mean and can I cast it to a byte[] without copying?

  15. 15

    Unable to cast object of type 'Microsoft.SqlServer.Dts.Pipeline.BlobColumn' to type 'System.Byte[]'

  16. 16

    "Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'." error in Photo: why and how do I fix it?

  17. 17

    Type cast issue from int to byte using final keyword in java

  18. 18

    "System.InvalidCastException: Specified cast is not valid" - DateTime

  19. 19

    Specified cast is not valid - System.InvalidCastException

  20. 20

    Error: The cast to value type 'System.Int32' failed because the materialized value is null

  21. 21

    The cast to value type 'System.Int32' failed because the materialized value is null.

  22. 22

    'System.Guid' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type

  23. 23

    Specified cast is not valid in date nullable

  24. 24

    How to cast a byte array to a primitive type in Rust?

  25. 25

    How to cast a byte array to a primitive type in Rust?

  26. 26

    Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type

  27. 27

    Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type

  28. 28

    Cannot cast DBNull.Value to type 'System.DateTime', Please use nullable types

  29. 29

    Invalid cast from 'System.Double' to 'System.Nullable`

HotTag

Archive