如題:
本來返回的數據源是以List <T>表示,但因需要在DataGridView中單擊列標題進行排序,所以模仿(http://msdn.microsoft.com/zh-tw/library/ms993236.aspx)寫了一個繼承於BindingList <T>的類SortableBindingList <T> 。
 在remoting客戶端調用遠程對象時,如果數據源返回結果是List <T>則沒問題,如果是SortableBindingList <T>則提示以下錯誤:Type 'System.ComponentModel.PropertyDescriptor' in Assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not ed as serializable.。我想應該是SortableBindingList <T>序列化與反序列化的問題吧!
以下為代碼
[Serializable]
    public class SortableBindingList<T> : BindingList<T>
    {
      .....
    }遠程對象:
 public class UserOnline : MarshalByRefObject, IUserOnLine
    {
        public SortableBindingList<UserOnLineInfo> GetListbyDiffTime(string UserName)
        {
            SortableBindingList<UserOnLineInfo> models = new SortableBindingList<UserOnLineInfo>();
      ......
            return models;
        }
    ...
    }
客戶端:
 IUserOnLine uitem = (IUserOnLine)Activator.GetObject(typeof(IUserOnLine), System.Configuration.ConfigurationManager.AppSettings["UserOnlineURL"]);
            SortableBindingList<UserOnLineInfo> models = uitem.GetListbyDiffTime(CurUserName);謝謝!非常感謝!

解决方案 »

  1.   

    [Serializable] 
        public class SortableBindingList <T> : BindingList <T> 
        { 
          ..... 
        } 
    泛型类不支持Serializable你可以这样用[Serializable]
    public class TempSortableBindingList:SortableBindingList <T> 
    {}
      

  2.   

    是不是由于 BindingList <T> 的属性    protected override PropertyDescriptor SortPropertyCore
        {
          get { return _sortProperty; }
        }的类型不能序列化导致的?
      

  3.   

    传说每天在CSDN吐口痰即可获得10分可用分!
      

  4.   


    按道理这样应该可以啊。
    你不会少了using System.Collections.Generic;
    吧.
      

  5.   


    我加了using System.Collections.Generic; 
    BindingList  <T> 編譯通過,按理那個也應該通過
      

  6.   


    这样做以后。你就得把以前的SortableBindingList<T>换成TempSortableBindingList
      

  7.   


    [Serializable]
    public class TempSortableBindingList : BindingList   <T>
    {
    }這樣嗎?還是一樣的提示錯誤。只有像下面這樣才會提示沒錯誤。
    public class TempSortableBindingList<T> : BindingList   <T>
    {
    }
      

  8.   


    无语我是叫你public class TempSortableBindingList:SortableBindingList   <T> 
    这样用以后就不能再用SortabelBindingList<T>来操作了
      

  9.   


    還是一樣的錯誤。提示出錯:
    找不到型別或命名空間名稱 'T' (您是否遺漏 using 指示詞或組件參考)
      

  10.   


    這樣解決了。
     [Serializable]
        public class SortableBindingList<T> : BindingList<T>
        {
            [NonSerialized]
            private PropertyDescriptor sortPropertyCore = null;
        protected override PropertyDescriptor SortPropertyCore
            {
                get { return sortPropertyCore; }
            }
       }謝謝兩位!