We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Invalid cast exception in constructor Aspose.Email.Clients.Smtp.SmtpClient

After I upgraded Aspose.Email to Version 20.4.0 the constructor of
Aspose.Email.Clients.Smtp.SmtpClient fails with an Invalid cast exception.
See attached image for details.

Screendump SmtpClient.png (87.8 KB)

After downgrading to Version 20.3.0 everything worked again.

In another project upgrading to Version 20.4.0 was no problem.
Both projects target netcoreapp3.1

@hromkes,

I have observed the issue shared by you and like to share that Aspose.Email for .NET has no issue while using it in NET Core 3.1 environment. Can you please provide the sample project for investigation on our end.

That will not be possible.
Constructing a simple project to reproduce the problem is also not possible.
I have 2 projects .
Both projects use Aspose.Email 20.4.0.
One project works fine. In the other project, constructing a new instance of SmtpClient fails.

Could you provide package with debug symbols?

Current stack trace does not help much:

    System.InvalidCastException
      HResult=0x80004002
      Message=Unable to cast object of type '   ' to type '   '.
      Source=Aspose.Email
      StackTrace:
       at    .(    ,     )
       at    .(    ,     )
       at    .(String )
       at Aspose.Email.Clients.EmailClient.ResetLogSettings()
       at Aspose.Email.Clients.EmailClient..ctor(String type, String host, Int32 port, String username, String authInfo, Boolean useOAuth, SecurityOptions securityOptions)
       at Aspose.Email.Clients.EmailClient..ctor(String type)
       at Aspose.Email.Clients.CredentialsByHostClient..ctor(String type)
       at Aspose.Email.Clients.Smtp.SmtpClient..ctor()
       at TelaSoft.TelaManager.Data.Providers.ExchangeMailProvider.<SendMailAsync>d__4.MoveNext() in C:\Git\TelaManager\Backend\Data\Providers\ExchangeMailProvider.cs:line 48

I completely stripped the failing project and discovered the following:
My appsettings.json contains the following config:

  "Serilog": {
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Microsoft": "Information",
        "System": "Information"
        //"Microsoft": "Fatal",
        //"System": "Fatal"
      }
    }
    ,
    "WriteTo": [
      {
        "Name": "Console"
      },
      {
        "Name": "Seq",
        "Args": {
          "serverUrl": "http://localhost:5341"
        }
      }
    ]
  }

When I delete the WriteTo property, the error does not occur.
When I move the serilog config to appsettings.development.json the error also does not occur.
For me that works as a solution right now.
But because this behavior did not happen in version 20.3.0 it seems obvious that this is a bug in Version 20.4.0.

@hromkes,

I have observed the details shared by you and a ticket with ID EMAILNET-39814 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Now I know how to reproduce, it was easy to create an application with the failing behavior.

WebApplication1.zip (2.6 MB)

Start Webapplication1 (not IIS Express) to trigger the error.
I hope this helps.

@hromkes,

Thank you for sharing the information. We will share feedback with you as soon as the issue will be fixed.

The issues you have found earlier (filed as EMAILNET-39814) have been fixed in this update.