❔ Cast is not valid when casting interface to comcrete impl
this is my concrete imp:
public class TempFile : IBrowserFile
{
public TempFile(string uuid, string name, long size, string contentType)
{
Uuid = uuid;
Name = name;
Size = size;
ContentType = contentType;
}
public TempFile()
{
}
public string Uuid { get; set; } = "";
public string ContentType { get; set; } = "";
public string Name { get; set; } = "";
public long Size { get; set; }
public DateTimeOffset LastModified => throw new NotImplementedException();
public Stream OpenReadStream(long maxAllowedSize = 512000, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
}
=========================
this is where im trying to cast ibrowserFile as TempFile and getting invalid Cast.
private async Task UploadFileAsync(IBrowserFile file)
{
if (file == null)
return;
if (EditModel == null)
{
throw new Exception("No edit model");
}
if (EditModel.Id == 0)
{
var result = await this.EmployeeComptesDepensesService.UploadTemporaryAttachmentFileAsync(file);
if (!result.ApiCallSuccess)
{
this.serverResponseValidator?.DisplayErrors(result.ServerErrors, result.ApiCallResultErrorMessage);
}
else
{
try
{
TempFile tf = (TempFile)file;
tf.Uuid = result.ResultModel?.Result!;
EditModel.TempFiles.Add(tf);
}
catch (Exception ex)
{
this.serverResponseValidator?.DisplayErrors(null, $"cast error {ex.Message}");
}
}
}
What's going on???
public class TempFile : IBrowserFile
{
public TempFile(string uuid, string name, long size, string contentType)
{
Uuid = uuid;
Name = name;
Size = size;
ContentType = contentType;
}
public TempFile()
{
}
public string Uuid { get; set; } = "";
public string ContentType { get; set; } = "";
public string Name { get; set; } = "";
public long Size { get; set; }
public DateTimeOffset LastModified => throw new NotImplementedException();
public Stream OpenReadStream(long maxAllowedSize = 512000, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
}
=========================
this is where im trying to cast ibrowserFile as TempFile and getting invalid Cast.
private async Task UploadFileAsync(IBrowserFile file)
{
if (file == null)
return;
if (EditModel == null)
{
throw new Exception("No edit model");
}
if (EditModel.Id == 0)
{
var result = await this.EmployeeComptesDepensesService.UploadTemporaryAttachmentFileAsync(file);
if (!result.ApiCallSuccess)
{
this.serverResponseValidator?.DisplayErrors(result.ServerErrors, result.ApiCallResultErrorMessage);
}
else
{
try
{
TempFile tf = (TempFile)file;
tf.Uuid = result.ResultModel?.Result!;
EditModel.TempFiles.Add(tf);
}
catch (Exception ex)
{
this.serverResponseValidator?.DisplayErrors(null, $"cast error {ex.Message}");
}
}
}
What's going on???