No overload for method - retrieving from generic list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rene Canter

    No overload for method - retrieving from generic list

    Trying to run an NUnit test to store and retrieve an item and ensure that the item retrieved is the same as the item stored.
    Code:
            public void TestStoreAndRetrieve()
            {
                Factory factory = Factory.GetInstance();
                IBookService bookSvc = (IBookService)factory.GetService(typeof(IBookService).Name);
                Book book1 = new Book("9781426829758", "Stock", "Dark Rival", "Masters of Time", "Brenda Joyce", "Time Travel");
                bookSvc.StoreBook(book1);
                Book book2 = bookSvc.RetrieveBook();
                Assert.AreEqual(book1, book2);
    Getting an error that there is no overload for method RetrieveBook that takes 0 arguments.
    I have updated all my code to put the books in a list, this is when the issues started. Not sure what I am supposed to be calling with RetrieveBook though.

    Code:
        public interface IBookService : IService
        {
            void StoreBook(Book bookx);
            void StoreBookList(Book[] bookx);
            void RetrieveBook(Book bookx);
            Book[] RetrieveBookList(int maxcount);
            //Book RetrieveBook();
        }
    Code:
            public void RetrieveBook(Book bookx)
            {
                FileStream loadStream = new FileStream("Book.bin", FileMode.Open, FileAccess.Read);
                IFormatter formatter = new BinaryFormatter();
                IList<Book> listBooks = formatter.Deserialize(loadStream) as IList<Book>;
                //Book bookX = formatter.Deserialize(loadStream) as Book;
                loadStream.Close();
                //return bookX;
            }
  • Anton Zinchenko
    New Member
    • Sep 2010
    • 16

    #2
    Method RetrieveBook have a param, so it can't be called without it...
    Code:
            public void TestStoreAndRetrieve()
            {
                Factory factory = Factory.GetInstance();
                IBookService bookSvc = (IBookService)factory.GetService(typeof(IBookService).Name);
                Book book1 = new Book("9781426829758", "Stock", "Dark Rival", "Masters of Time", "Brenda Joyce", "Time Travel");
                bookSvc.StoreBook(book1);
                [B]Book book2 = bookSvc.RetrieveBook(book1);[/B]
                Assert.AreEqual(book1, book2);

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Yeah you clearly are calling:
      Book book2 = bookSvc.Retriev eBook();
      and also clearly have this line:
      //Book RetrieveBook();

      The error message is telling you what is wrong. (Although I wonder why you have your function calls the way you do)

      Comment

      • Rene Canter

        #4
        When i put book1 in
        Code:
        Book book2 = bookSvc.RetrieveBook(book1);
        I get error cannot implicitly convert type 'void' to Domain.Book.

        Comment

        • Rene Canter

          #5
          Got it! Thanks for the help.

          Comment

          • hype261
            New Member
            • Apr 2010
            • 207

            #6
            Look at your function declaration.

            Code:
            public void RetrieveBook(Book bookx)
            You are telling the compiler that this function doesn't return anything. To return a Book change the definition to.

            Code:
            public Book Retrievebook(Book bookx)
            {
            //what ever logic you get to return your book goes here
            return book; 
            }
            You will also need to change the method definition in your interface IBookService.

            Comment

            Working...