SubscribeToStreamingNotifications with .Net 6 is not working. Could not load type System.Web.HttpException

37 Views Asked by At

We are using Exchange Web Services with .Net 6 and while sending and receiving mails works fine, I have trouble to implement StreamingSubscription in .Net 6.

I know EWS is not fully compatible with .Net 6 but maybe there is a quick solution without switching to Graph Api. It tried the same code with .Net 4.x and it worked without any problems.

When I execute connection.Open() I alwas run into an exception:

    System.TypeLoadException
    HResult=0x80131522
    Message = Could not load type 'System.Web.HttpException' from assembly 'System.Web,   Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

The following is a simplyfied version of our code.

        string sEwsUrl = "urlXY";
        string sMBX = "usernameXY";
        string sPassword = "userpasswordXY";

        ExchangeService service = new ExchangeService
        {
            Credentials = new NetworkCredential(sMBX, sPassword, "GBNET"),
            Url = new Uri(sEwsUrl),
        };

        var ids = new FolderId[2] { new FolderId(WellKnownFolderName.Root), new FolderId(WellKnownFolderName.Inbox) };
        var events = new List<EventType>();
        events.Add(EventType.NewMail);
        StreamingSubscription subscription = service.SubscribeToStreamingNotifications(ids, EventType.NewMail);

        conn = new StreamingSubscriptionConnection(service, 5);
        conn.AddSubscription(subscription);
        conn.OnNotificationEvent += OnNotificationEvent;
        conn.OnDisconnect += OnDisconnect;
        conn.Open();

        Console.WriteLine("PRESS <ENTER> TO SEND MESSAGE");
        Console.ReadKey();
        EmailMessage msg = new EmailMessage(service);
        msg.Subject = "Testing Streaming Notification on 16 Aug 2010";
        msg.Body = "Messagebody";
        msg.ToRecipients.Add("[email protected]");
        msg.Send();

        Console.WriteLine("PRESS <ENTER> TO EXIT");
        Console.ReadKey();
        subscription.Unsubscribe();
        conn.Close();
0

There are 0 best solutions below