- Home
- Forum
- ASP.NET Core - EJ 2
- DataOperation - System.InvalidCastException: 'Invalid cast from 'System.String' to 'System.Guid'.'
DataOperation - System.InvalidCastException: 'Invalid cast from 'System.String' to 'System.Guid'.'
2. By the way, is there somewhere a complete example on how I can use an ASP.NET Core 3.1 backend im combination with the Rest API Adaptor with a React Grid (instead of using the UrlAdaptor). In particular, I'm looking for an elegant way how to solve the filtering in combination with Linq (Entity framework)?
An InvalidCastException is thrown when cast from one type to another type is not supported. In some reference type conversions , the compiler cannot determine whether a cast will be valid. It is because of the source type cannot be converted to the destination type , so the cast does not succeed.
How to fix InvalidCastException?
It is important to note that this exception is caused by programming error and should not be handled in a C# try/catch block; instead, the cause of the exception should be eliminated.
C# provides the "is" operator to enable you to test for compatibility before actually performing a cast operation . It will checks if the runtime type of an expression result is compatible with a given type. The "is operator" returns true if the given object is of the same type otherwise, return false. It also returns false for null objects . It's a straightforward extension of the "is" statement that enables concise type evaluation and conversion.
- Share the full Grid code files.
- Share the Syncfusion package script version.
- When you face the reported issue? (Initial render of Grid/ Doing any Grid action)
- Share the video demo of the reported behavior.
- If possible, share a simple issue reproducible sample which will be very helpful to resolve the issue earlier.
|
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
});
}
|
|
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver =
new DefaultContractResolver();
}); }
|
- 3 Replies
- 3 Participants
- Marked answer
-
LS Laurin S
- Oct 15, 2020 07:50 AM UTC
- Sep 15, 2021 01:06 PM UTC