好吧,我對這個有點困惑。更改我的ViewModel上不相關的int屬性似乎使我的模型不可序列化。更改ViewModel中的屬性,使模型不可序列化?
我有一個對象,它跟蹤與某人聯繫的最佳時間。它可以設置爲Anyday,平日,晚上,特定日期和任何時間,早上,下午,晚上和特定時間。當對象被保存時,它會被序列化併發送到WCF服務器。
實質上,該對象是7天的集合。每天包含一個星期幾的int值,TimeSpans集合,它定義當天良好的通話時間,一組布爾標誌,定義選擇哪些「快捷」時間組(早晨,下午,晚上等) 。
我正在使用MVVM並有一個虛擬機來處理這個類。 VM所包含的除日期集合之外唯一的屬性是int值,其中定義了工作日的「快捷方式」組(週日,週末等)。
一切工作絕對沒問題,直到我設置「快捷方式」組爲週日「SpecificDays」。保存後,我嘗試將對象傳遞給WCF服務器時出現錯誤。該錯誤表示它無法序列化一個參數,並顯示下面顯示的內部異常(請記住,WCF錯誤非常通用,並且通常根本不指出問題)。這裏是什麼,我試圖做一個屏幕截圖:
這沒有意義,我,因爲ShortcutWeekday不會被髮送到服務器WCF在所有。唯一要做的就是收集天。而另一個令人費解的事情,點擊「Specific Days」單選按鈕,然後再次點擊另一個選項,也會導致WCF調用失敗。另外,如果問題出在我的課程上,那麼它是否會在任何時候節約成本,而不僅僅是特定日子?我使用上面的例子仔細檢查了Days集合的屬性值,並且對象屬性設置完全相同。
內部異常:
"Type 'System.DelegateSerializationHolder+DelegateEntry' with data contract name
'DelegateSerializationHolder.DelegateEntry:http://schemas.datacontract.org/2004/07/System'
is not expected. Consider using a DataContractResolver or add any types not known
statically to the list of known types - for example, by using the KnownTypeAttribute
attribute or by adding them to the list of known types passed to DataContractSerializer."
視圖模型屬性:
// Used to track which Radio Button is selected
private int _selectedWeekdayGroup = 0;
// Object holding the current BestContactTime
private BestContactTime _bestContactTime;
// Shortcut to multiple Days in BestContactTime
public int SelectedWeekdayGroup
{
get { return _selectedWeekdayGroup; }
set
{
//UpdateCallableDays(value); // This updates the BestContactTime.Days collection
_selectedWeekdayGroup = value;
//OnPropertyChanged("SelectedTimesGroups"); // This property is just which set of ShortcutTimes are displayed in checkboxes
}
}
BestContactTime:
// Should always have only 7 objects, one per day of week
public ObservableCollection<ContactDay> Days;
聯繫天:
public int WeekDay;
public SortableObservableCollection<TimeSpan> CallableTimes;
public SortableObservableCollection<bool> CallableTimeGroups;
SortableObservableCollection只是一個從ObservableCollection繼承的類,它具有一些其他方法,如Sorting和AddRange。
唯一的事件處理程序是PropertyChanged事件,它已經具有該屬性 – Rachel 2010-08-26 16:15:45
@Rachel:'SortableObservableCollection'怎麼樣? – SLaks 2010-08-26 16:19:30
我很抱歉,顯然我錯了。我認爲我所有的模型都是從具有該屬性的基礎模型類繼承而來的,但顯然這不是。非常感謝!我今天浪費了很多時間試圖找出這一個...... – Rachel 2010-08-26 16:20:39