David-Barrett-MS / PowerShell-EWS-Scripts

A collection of PowerShell scripts that use EWS to perform actions against Exchange mailboxes
MIT License
119 stars 13 forks source link

Exception setting "TraceListener": "Cannot convert the "EWSTracer" value of type "EWSTracer" to type "Microsoft.Exchange.WebServices.Data.ITraceListener"." #35

Closed gkosmas closed 1 year ago

gkosmas commented 1 year ago

Hi David, I have tried to use your Merge-MailboxFolder.ps1 script today and I am not sure what has changed but I am unable to get it to run.

  1. I import the Web Services DLL like I normally do Import-Module -Name "C:\Program Files\Microsoft Office\root\Office16\ADDINS\Microsoft Power Query for Excel Integrated\bin\Microsoft.Exchange.WebServices.dll"

  2. Then I run the command to start archiving

  3. The script accepts the Auth Code as normal

After this, I get the below error message: Exception setting "TraceListener": "Cannot convert the "EWSTracer" value of type "EWSTracer" to type "Microsoft.Exchange.WebServices.Data.ITraceListener"." At C:\Users\gkosmas\Technical Documents\Office 365\Archive\Merge-MailboxFolder2-2.ps1:1929 char:13 $exchangeService.TraceListener = $script:Tracer


     CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
     FullyQualifiedErrorId : ExceptionWhenSetting

After this, I get this XML code repeating:
<Trace Tag="EwsRequest" Tid="17" Time="2023-07-26 01:22:56Z" Version="15.00.0913.015">
  <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
      <t:RequestServerVersion Version="Exchange2010_SP2" />
    </soap:Header>
    <soap:Body>
      <m:GetFolder>
        <m:FolderShape>
          <t:BaseShape>IdOnly</t:BaseShape>
          <t:AdditionalProperties>
            <t:FieldURI FieldURI="folder:DisplayName" />
            <t:FieldURI FieldURI="folder:FolderClass" />
            <t:FieldURI FieldURI="folder:ParentFolderId" />
            <t:FieldURI FieldURI="folder:ChildFolderCount" />
            <t:FieldURI FieldURI="folder:TotalCount" />
            <t:ExtendedFieldURI PropertyTag="13825" PropertyType="Integer" />
          </t:AdditionalProperties>
        </m:FolderShape>
        <m:FolderIds>
          <t:DistinguishedFolderId Id="msgfolderroot">
            <t:Mailbox>
              <t:EmailAddress>info@domain.com.au</t:EmailAddress>
            </t:Mailbox>
          </t:DistinguishedFolderId>
        </m:FolderIds>
      </m:GetFolder>
    </soap:Body>
  </soap:Envelope>
</Trace>

I have had this issue before where the DLL was the wrong version or it was not imported but everything seems to be in line on my side. 

Any idea what might be the issue here?

Thank you in advance for your help here.
David-Barrett-MS commented 1 year ago

There is a copy of the EWS Managed API available in the same folder as the scripts: https://github.com/David-Barrett-MS/PowerShell-EWS-Scripts/blob/master/Legacy/Microsoft.Exchange.WebServices.dll

This doesn't sound like a dll version issue, but would be worth testing with the correct library. Also please test with the latest version of the script (I've just published 1.3.1).