无法从程序集“mscorlib”加载类型“System.Runtime.CompilerServices.ExtensionAttribute” [英] Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib'

查看:79
本文介绍了无法从程序集“mscorlib”加载类型“System.Runtime.CompilerServices.ExtensionAttribute”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用Microsoft.Exchange.WebServices.dll(v 15.0.466.0)在C#VS2010中发送测试邮件。请参阅下面的代码


自动发现似乎工作正常,即。在跟踪中,我可以发现我的名字  :


< Trace Tag =" AutodiscoverResponse" TID = QUOT 1 QUOT;时间=" 2012-08-22 05:25:11Z"版本=" 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 ">

      <用户>

        < DisplayName> =我< / DisplayName>

      < / User>



但之后,每次出现此错误时:


未处理的异常:System.TypeInitializationException:"Microsoft.Exchange.WebServices.Strings"的类型初始值设定项引发异常。 ---> System.TypeL
$
oadException:无法从程序集'mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken <
加载'System.Runtime.CompilerServices.ExtensionAttribute'类型= b77a5c561934e089' &NBSP;&NBSP;


在System.ModuleHandle.ResolveMethod(RuntimeModule模块,Int32 methodToken,  IntPtr * typeInstArgs,Int32 typeInstCount,IntPtr * methodInstArgs,Int32 methodInstCount)

  &NBSP;在System.ModuleHandle.ResolveMethodHandleInternalCore(RuntimeModule模块,Int32 methodToken,IntPtr [] typeInstantiationContext,Int32 typeInstCount,IntPtr [] methodInstantiationContext,Int32 methodInstCount)

  在System.ModuleHandle.ResolveMethodHandleInternal(RuntimeModule模块,Int32 methodToken,RuntimeTypeHandle [] typeInstantiationContext,RuntimeTypeHandle []  methodInstantiationContext)

  在System.Reflection.CustomAttributeData..ctor(RuntimeModule范围,CustomAttributeRecord caRecord)

  在System.Reflection.CustomAttributeData.GetCustomAttributes(RuntimeModule module,Int32 tkTarget)

   at System.Reflection.CustomAttributeData.GetCustomAttributesInternal(RuntimeAssembly target)

  在System.Reflection.RuntimeAssembly.GetCustomAttributesData()  在System.Reflection.CustomAttributeData.GetCustomAttributes(汇编目标)


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

  在System.Resources.ResourceManager.CommonSatelliteAssemblyInit()


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


  在Microsoft.Exchange.WebServices.Data.ExchangeResourceManager..ctor(String baseName,Assembly assembly)

  在Microsoft.Exchange.WebServices.Data.ExchangeResourceManager.GetResourceManager(String baseName,Assembly assembly)

  在Microsoft.Exchange.WebServices.Strings..cctor()

   ---内部异常堆栈跟踪结束---

  在Microsoft.Exchange.WebServices.Strings.get_NoError()

  在Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverResponse..ctor()

  在Microsoft.Exchange.WebServices.Autodiscover.GetUserSettingsResponse..ctor()

  在Microsoft.Exchange.WebServices.Autodiscover.OutlookConfigurationSettings.ConvertSettings(String smtpAddress,List`1 requestedSettings)

  在Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress,List`1 requestedSettings)

  在Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress,UserSettingName [] userSettingNames)

  在Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress,ExchangeVersion requestedServerVersion,AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)

  在Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress,AutodiscoverRedirectionUrlValidationCallback validateRedirectionU

rlCallback)

  在Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String  emailAddress)

   at the ConsoleApplication2.Program.Main(String [] args)in c:\users\laureph\documents\visual studio 2010 \Projects\ConsoleApplication2 \ConsoleApplication2 \Program.cs:第23行



我已经在

http://social.msdn.microsoft.com/Forums/da-DK/netfxnetcom / thread / 177e7a3d-4c89-4b67-8808-f5cd44575d91
 


==>我用过了所有的  ExchangeVersion.xxx at line:ExchangeService service = new ExchangeService(ExchangeVersion.xxx)


==>我已经在测试机器上安装了.exe


静止不起作用:(


请帮助


<使用System;
使用System.Collections.Generic;
使用System;

$ < .Linq;
使用System.Text;
使用System.Net.Mail;
使用System.Net;
使用Microsoft.Exchange.WebServices.Data;
使用Microsoft.Exchange.WebServices.Autodiscover;
使用System.Net.Security;
使用System.Security.Cryptography.X509Certificates;

命名空间ConsoleApplication2
{
class Program
{
static void Main(string [] args)
{
//在contoso.com上以user1身份连接到Exchange Web服务。
ExchangeService服务= new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.TraceEnabled = true;
service.AutodiscoverUrl(" my email");

//创建电子邮件,设置其属性,然后将其发送到user2@contoso.com,将副本保存到"已发送邮件"文件夹。
EmailMessage message = new EmailMessage(service);
message.Subject =" Interesting" ;;
message.Body ="该命题已被考虑。";
message.ToRecipients.Add(" recipientname@xxxx.aero");
message.SendAndSaveCopy();

//向控制台窗口写入确认消息。
Console.WriteLine(" Message sent!");
}
}
}



解决方案

版本2.0处于测试阶段,因此,除非您针对2012进行开发,否则最好使用托管API的发布版本1.2 http://www.microsoft.com/en-au/download/details.aspx?id=28952。


NET 4.5对  4.0的RTM版本进行更改并更改'mscorlib',请参阅

http://connect.microsoft。含extensionmethods和 - 可能 - 其他-IOC情节移动系统的运行时-compilerservices-extensionattribute到mscorlib程序-场所-structuremap-扫描-的名字空间-&NBSP;所以要在Windows 7上成功使用此
,您需要安装.NET 4.5的RC,这也将改变它们在.NET 4.0中的类型。如果您拥有Windows 8的RTM版本,则不应该出现问题。


干杯

Glen


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!");
        }
    }
}


解决方案

Version 2.0 is in Beta so unless you developing against 2012 you would be better to use the release version 1.2 of the managed apihttp://www.microsoft.com/en-au/download/details.aspx?id=28952.

NET 4.5 makes changes to the RTM version of 4.0 and changes 'mscorlib' see http://connect.microsoft.com/VisualStudio/feedback/details/726702/moving-system-runtime-compilerservices-extensionattribute-to-mscorlib-breaks-structuremap-scans-of-namespaces-containing-extensionmethods-and-possibly-other-ioc-scenarios so to use this successfully on Windows 7 you need to have the RC of .NET 4.5 installed which will change they types in .NET 4.0 as well. If you have the RTM version of Windows 8 you shouldn't have a problem.

Cheers
Glen


这篇关于无法从程序集“mscorlib”加载类型“System.Runtime.CompilerServices.ExtensionAttribute”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆