title: How can built in xaml extensions access IXamlTypeResolver when custom ones can't in Dev Studio 2010?
body: <p>I wrote a custom xaml extenstion but it fails to obtain IXamlTypeResolver at design time. I did some goggling and it seems this is due to a bug introduced in dev studio 2010. As experiment I decompiled x:Static and rebuilt as an external extension but it also cannot obtain IXamlTypeResolver. However the build one works at design time. I guess there must be some internal magic going on. I am wondering if there any workarounds. I dont mind doing  some extra work to get the info I need like parsing the namespace xaml declarations but it seems like the services I would need to do this are also unavailable at design time. Do Microsoft have any plans to fix this issue? It severely limits the usefulness of custom xaml extensions. This must affect the 3rd party library providers - I am wondering how they work around it.</p>
  
  <pre><code>[MarkupExtensionReturnType(typeof(object))]
  [TypeConverter(typeof(MyStaticExtensionConverter))]
  public class MyStaticExtension : MarkupExtension
  {
      private string _member;
      private Type _memberType;
  
      [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
      [EditorBrowsable(EditorBrowsableState.Advanced)]
      public MyStaticExtension()
      {
      }
  
      public MyStaticExtension(string member)
      {
          if (member == null) {
              throw new ArgumentNullException("member");
          }
          this._member = member;
      }
  
      private bool GetFieldOrPropertyValue(Type type, string name, out object value)
      {
          FieldInfo field = null;
          Type baseType = type;
          do {
              field = baseType.GetField(name, BindingFlags.Public | BindingFlags.Static);
              if (field != null) {
                  value = field.GetValue(null);
                  return true;
              }
              baseType = baseType.BaseType;
          }
          while (baseType != null);
          PropertyInfo property = null;
          baseType = type;
          do {
              property = baseType.GetProperty(name, BindingFlags.Public | BindingFlags.Static);
              if (property != null) {
                  value = property.GetValue(null, null);
                  return true;
              }
              baseType = baseType.BaseType;
          }
          while (baseType != null);
          value = null;
          return false;
      }
  
      public override object ProvideValue(IServiceProvider serviceProvider)
      {
          if (this._member == null) {
              throw new InvalidOperationException("MarkupExtensionStaticMember");
          }
  
          Type memberType = this.MemberType;
          string str = null;
          string str2 = null;
          object obj2;
          if (memberType != null) {
              str = this._member;
              str2 = memberType.FullName + "." + this._member;
          }
          else {
              str2 = this._member;
              int index = this._member.IndexOf('.');
              if (index &lt; 0) {
                  throw new ArgumentException("MarkupExtensionBadStatic", this._member);
              }
  
              string qualifiedTypeName = this._member.Substring(0, index);
              if (qualifiedTypeName == string.Empty) {
                  throw new ArgumentException("MarkupExtensionBadStatic", this._member);
              }
  
              if (serviceProvider == null) {
                  throw new ArgumentNullException("serviceProvider");
              }
  
              IXamlTypeResolver service = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
  
              // Exception will thrown here as at design time
              if (service == null) {
  
  
                  throw new ArgumentException("MarkupExtensionNoContext", base.GetType().Name);
              }
  
              memberType = service.Resolve(qualifiedTypeName);
              str = this._member.Substring(index + 1, (this._member.Length - index) - 1);
              if (str == string.Empty) {
                  throw new ArgumentException("MarkupExtensionBadStatic", this._member);
              }
          }
  
          if (memberType.IsEnum) {
              return Enum.Parse(memberType, str);
          }
  
          if (!this.GetFieldOrPropertyValue(memberType, str, out obj2)) {
              throw new ArgumentException("MarkupExtensionBadStatic", str2);
          }
  
          return obj2;
      }
  
      [ConstructorArgument("member")]
      public string Member
      {
          [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
          get
          {
              return this._member;
          }
          set
          {
              if (value == null) {
                  throw new ArgumentNullException("value");
              }
              this._member = value;
          }
      }
  
      [DefaultValue((string)null)]
      public Type MemberType
      {
          [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
          get
          {
              return this._memberType;
          }
          set
          {
              if (value == null) {
                  throw new ArgumentNullException("value");
              }
              this._memberType = value;
          }
      }
  }
  
  internal class MyStaticExtensionConverter : TypeConverter
  {
      public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
      {
          return ((destinationType == typeof(InstanceDescriptor)) || base.CanConvertTo(context, destinationType));
      }
  
      [SecurityCritical, SecurityTreatAsSafe]
      public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
      {
          if (destinationType != typeof(InstanceDescriptor)) {
              return base.ConvertTo(context, culture, value, destinationType);
          }
  
          MyStaticExtension extension = value as MyStaticExtension;
          if (extension == null) {
              throw new ArgumentException("MustBeOfType", "value");
          }
  
          return new InstanceDescriptor(typeof(MyStaticExtension).GetConstructor(new Type[] { typeof(string) }), new object[] { extension.Member });
      }
  }
  </code></pre>