Error - is not marked as serializable

后端 未结 3 1367
借酒劲吻你
借酒劲吻你 2020-12-01 09:55

The error I\'m getting is:

Type \'OrgPermission\' in Assembly \'App_Code.ptjvczom, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null\' is not marked as s         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 10:42

    Leaving my specific solution of this for prosperity, as it's a tricky version of this problem:

    Type 'System.Linq.Enumerable+WhereSelectArrayIterator[T...] was not marked as serializable

    Due to a class with an attribute IEnumerable eg:

    [Serializable]
    class MySessionData{
        public int ID;
        public IEnumerable RelatedIDs; //This can be an issue
    }
    

    Originally the problem instance of MySessionData was set from a non-serializable list:

    MySessionData instance = new MySessionData(){ 
        ID = 123,
        RelatedIDs = nonSerizableList.Select(item => item.ID)
    };
    

    The cause here is the concrete class that the Select(...) returns, has type data that's not serializable, and you need to copy the id's to a fresh List to resolve it.

    RelatedIDs = nonSerizableList.Select(item => item.ID).ToList();
    

提交回复
热议问题