none
Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib'

    Question

  • Hi,

    I'm using Microsoft.Exchange.WebServices.dll (v 15.0.466.0)  to send a test message in C# VS2010. See code below

    The Autodiscover seems to work fine ie. in the traces, I can spot my name  :

    <Trace Tag="AutodiscoverResponse" Tid="1" Time="2012-08-22 05:25:11Z" Version="15.00.0466.000">
      <?xml version="1.0" encoding="utf-8"?>
      <Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
        <Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
          <User>
            <DisplayName>= ME </DisplayName>
          </User>

    But afterwards, each time I got this error:

    Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.Exchange.WebServices.Strings' threw an exception. ---> System.TypeL
    oadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken
    =b77a5c561934e089'.  

    at System.ModuleHandle.ResolveMethod(RuntimeModule module, Int32 methodToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount)
       at System.ModuleHandle.ResolveMethodHandleInternalCore(RuntimeModule module,Int32 methodToken, IntPtr[] typeInstantiationContext, Int32 typeInstCount, IntPtr[] methodInstantiationContext, Int32 methodInstCount)
       at System.ModuleHandle.ResolveMethodHandleInternal(RuntimeModule module, Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
       at System.Reflection.CustomAttributeData..ctor(RuntimeModule scope, CustomAttributeRecord caRecord)
       at System.Reflection.CustomAttributeData.GetCustomAttributes(RuntimeModule module, Int32 tkTarget)
       at System.Reflection.CustomAttributeData.GetCustomAttributesInternal(RuntimeAssembly target)
       at System.Reflection.RuntimeAssembly.GetCustomAttributesData()   at System.Reflection.CustomAttributeData.GetCustomAttributes(Assembly target)

       at System.Resources.ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(Assembly a, UltimateResourceFallbackLocation& fallbackLocation)
       at System.Resources.ResourceManager.CommonSatelliteAssemblyInit()

       at System.Resources.ResourceManager..ctor(String baseName, Assembly assembly)

       at Microsoft.Exchange.WebServices.Data.ExchangeResourceManager..ctor(String baseName, Assembly assembly)
       at Microsoft.Exchange.WebServices.Data.ExchangeResourceManager.GetResourceManager(String baseName, Assembly assembly)
       at Microsoft.Exchange.WebServices.Strings..cctor()
       --- End of inner exception stack trace ---
       at Microsoft.Exchange.WebServices.Strings.get_NoError()
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverResponse..ctor()
       at Microsoft.Exchange.WebServices.Autodiscover.GetUserSettingsResponse..ctor()
       at Microsoft.Exchange.WebServices.Autodiscover.OutlookConfigurationSettings.ConvertSettings(String smtpAddress, List`1 requestedSettings)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List`1 requestedSettings)
       at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionU
    rlCallback)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress)
       at ConsoleApplication2.Program.Main(String[] args) in c:\users\laureph\documents\visual studio 2010\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs:line 23

    I have applied all the recommandations   mentionned by tamu-bill in http://social.msdn.microsoft.com/Forums/da-DK/netfxnetcom/thread/177e7a3d-4c89-4b67-8808-f5cd44575d91 

    ==> i have used all  ExchangeVersion.xxx at line : ExchangeService service = new ExchangeService(ExchangeVersion.xxx)

    ==> I have installed the .exe on a test machine

    Still dosesn't work :(

    Please help

    Philippe

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Net.Mail; 
    using System.Net; 
    using Microsoft.Exchange.WebServices.Data; 
    using Microsoft.Exchange.WebServices.Autodiscover; 
    using System.Net.Security; 
    using System.Security.Cryptography.X509Certificates; 
    
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                    // Connect to Exchange Web Services as user1 at contoso.com. 
                    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); 
                    service.TraceEnabled = true;
                    service.AutodiscoverUrl("my email"); 
     
                    // Create the e-mail message, set its properties, and send it to user2@contoso.com, saving a copy to the Sent Items folder.  
                    EmailMessage message = new EmailMessage(service); 
                    message.Subject = "Interesting"; 
                    message.Body = "The proposition has been considered."; 
                    message.ToRecipients.Add("recipientname@xxxx.aero"); 
                    message.SendAndSaveCopy(); 
     
                    // Write confirmation message to console window. 
                    Console.WriteLine("Message sent!");
            }
        }
    }
    
    

    Wednesday, August 22, 2012 6:07 AM

All replies