System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.Int32'.

sblb 1,231 Reputation points
2022-06-20T19:12:07.3+00:00

HI,

I received this message : System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.Int32'.

In my class I've put :

  public class FilePath  
    {  
       ...  
       public int Size { get; set; }  
        ...  
    }  

this class is associated to the view FilePath
213106-image.png

How can I convert the type of Size from type bigint to type int?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,622 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118.2K Reputation points
    2022-06-20T19:16:24.177+00:00

    I think that it cannot be always converted. Try using long or Int64 instead of int in your class and other parts. (Or use int instead of bigint, if possible).

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.