Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidCastException: Object must implement IConvertible when using Get method with interface as type #62

Closed
alexanderar opened this issue Jun 5, 2016 · 1 comment
Labels
Milestone

Comments

@alexanderar
Copy link

I have a pretty simple scenario:

  1. Repo class that returns a IList<SomeDto> items
public class Repo
{
      public IList<SomeDto> Get()
      {
           return new List<SomeDto>();
      }
}
  1. service class that has a ICacheManager and uses it to cache the repo result:
    public class Service
    {
          private ICacheManager<object> _cacheManager;
    
          private Repo _repo;
    
          public Service(ICacheManager<object> cacheManager, Repo repo)
          {
                this._cacheManager = cacheManager;
                this._repo = repo;
          }
    
          public  IList<SomeDto> Get()
          {
                 var items =  this._cacheManager.Get< IList<SomeDto>>("items");
                 if(items == null)
                 {
                       items = this._repo.Get();
                       this._cacheManager.Add("items",items);
                  }
                  return items;
          }
    }
    

    After cache has been instantiated with items
    this._cacheManager.Get< IList<SomeDto>>("items") throws an InvalidCastException: Object must implement IConvertible, while if I change it to
    this._cacheManager.Get<List<SomeDto>>("items") -- notice List instead of IList -- the cache works as expected.

    My question is whether it is possible to use interfaces/base classes to retrieve items from cache.

    Thanks in addvance

    Alex

@MichaCo MichaCo added the bug label Jun 5, 2016
@MichaCo
Copy link
Owner

MichaCo commented Jun 5, 2016

yup can be changed so that the converting Get method supports that

MichaCo added a commit that referenced this issue Jun 5, 2016
@MichaCo MichaCo added this to the Version 0.9 milestone Jun 6, 2016
@MichaCo MichaCo closed this as completed Jun 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants