web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Could not load file or assembly 'Microsoft.Exchange.WebServices

(0) ShareShare
ReportReport
Posted on by 1,040

Hi,

I have implemented a C# code to retrieve the unread email from Exchange by using Microsoft.Exchange.WebServices . I am going to call this C# class in AX and get the emails data. I consume C# class as reference into AOT but getting the below error while running this class-> method? 

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Exchange.WebServices, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Exchange.WebServices, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at ZonMicrosoftExchangeEmail.MicrosoftExchangeEmail.ReadUnreadEmails(String _EmailAddress, String _Username, String _Password, Boolean _MarkRead)

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Exchange.WebServices, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 

at ZonMicrosoftExchangeEmail.MicrosoftExchangeEmail.ReadUnreadEmails(String _EmailAddress, String _Username, String _Password, Boolean _MarkRead)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Dynamics.AX.ManagedInterop.ClrBridgeImpl.InvokeClrInstanceMethod(ClrBridgeImpl* , ObjectWrapper* objectWrapper, Char* pszMethodName, Int32 argsLength, ObjectWrapper** arguments, Boolean* argsAreByRef, Boolean* isException)

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Ali R Profile Picture
    1,040 on at
    RE: Could not load file or assembly 'Microsoft.Exchange.WebServices

    Yes. I was using EWS 2.0. After upgrading to 2.1, I don't get any error. Not sure why 2.0 was not working. BTW the problem has been solved. :)

  • Suggested answer
    Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: Could not load file or assembly 'Microsoft.Exchange.WebServices

    It's not a problem about locating the web service, it's about a .NET assembly. Adding a reference to AOT will make no difference - the application can't find the assembly at run-time.

    Try to identify the problematic assembly with Assembly Binding Log Viewer (it may be either Microsoft.Exchange.WebServices or another assembly referenced by it). Then decide where the assembly should be found and ensure that it's there - either in bin folder of the application (either AX client or AOS, depending on where you use the assembly) or in GAC on the right computer (client machine or AOS machine).

  • Ali R Profile Picture
    1,040 on at
    RE: Could not load file or assembly 'Microsoft.Exchange.WebServices

    This happens only when I call this C# class from AX. I consumed this class in another C# project and it works fine.

    I also added Exchange Web Service into reference in AOT, but still getting error. Should I do anything in C# side to embed the web service. ?  

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Could not load file or assembly 'Microsoft.Exchange.WebServices

    it seems as if you C# class which you created in .net and referenced in AX in not able to find the webserivce which you are using.

    i suggest you should also reference the web service in dynamics AX.

    Please verify and update us with your further findings

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans