locked
Why this Error RRS feed

  • Question

  • Hi,

         
    public  class SaveViewModel <T> : ViewModelBase
        {
    
            private List<T> _savedResultsCollection;
            private string  _filename;
    
    
            [DataMember]
            public List<T> SavedResultsCollection
            {
                get
                {
                    return this._savedResultsCollection;
                }
    
                set
                {
                    this._savedResultsCollection = value;
                    this.NotifyPropertyChanged(new StringBuilder(typeof(T).Name).Append("Property").ToString());
                }
            }
    
            public SaveViewModel() 
            {
                _savedResultsCollection = new List<T>();
                _filename = new StringBuilder(typeof(T).Name).Append(".xml").ToString();
            }
    
    
    
    
    
       async public Task RestoreAsync<T>()
            {
               List<T> _restoredResultsCollection = new List<T>();
    
                try
                {
                    StorageFile sessionFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(_filename, CreationCollisionOption.OpenIfExists);
                    IInputStream sessionInputStream = await sessionFile.OpenReadAsync();
    
                    XmlSerializer serializer = new XmlSerializer(_restoredResultsCollection.GetType());
    
                    _restoredResultsCollection = (List<T>)serializer.Deserialize(sessionInputStream.AsStreamForRead());
    
                    _savedResultsCollection = _restoredResultsCollection;// Error is in this line
    
                    sessionInputStream.Dispose();
                }
                catch (Exception e) 
                { 
                }
            }
    }
    }

    Error

        Cannot implicitly convert type 'System.Collections.Generic.List<T> [c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Collections.dll]' to 'System.Collections.Generic.List<T> [c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Collections.dll]'    D:\TFSWorkspace\Mobile\Win8\BR\Bankrate Mortgage App\Sources\Win8Surface\ViewModels\SaveViewModel.cs    70    43    Win8Surface
    Can anyone help me? where i m doing wrong?

    Monday, May 6, 2013 2:20 PM

Answers

  • You don't need <T> in RestoreAsync - by doing it you confuse compiler which type to use.  Define method as

    async piblic Task RestoreAsync()
    {
       ...
    }

    and everything will work as you expected.


    http://lunarfrog.com/blog/

    • Marked as answer by WinNRock Monday, May 6, 2013 4:37 PM
    Monday, May 6, 2013 3:42 PM

All replies

  • You don't need <T> in RestoreAsync - by doing it you confuse compiler which type to use.  Define method as

    async piblic Task RestoreAsync()
    {
       ...
    }

    and everything will work as you expected.


    http://lunarfrog.com/blog/

    • Marked as answer by WinNRock Monday, May 6, 2013 4:37 PM
    Monday, May 6, 2013 3:42 PM
  • waw superb. Thank you so much Andrei.
    Monday, May 6, 2013 4:39 PM