Cannot create an instance of the abstract class or interface RRS feed

  • Question

  • I created a simple MVC Web application and used LINQ to SQL to have the model (.emx) built for me.  The schema is like this.

    Trip <<---> Traveler
    Trip <<---> City <<---> Country

    I have no problem building IList<Country>, IList<City>, but the IList<Traveler> got the compiler error (code underlined)

    Error    1    Cannot create an instance of the abstract class or interface 'System.Collections.Generic.IList<Travel.Model.Traveler>'    myCode.cs    24    25 

    Does anyone know what's wrong with the code.
    public class TestTravelRepository: ITravelRepository
    IList<Traveler> travelers;
    IList<Country> countries;
    IList<City> cities;
    IList<Travel.Model.Trips> trips;

    #region Constructors
    public TestTravelRepository()
    #region Build Travelers
    travelers = new IList<Traveler>() ;
    var Joe = new Traveler();
    Joe.SSN = "1111";
    Joe.DOB = new DateTime(1980,9,1);
    Joe.FName = "Joe";
    Joe.LName = "Blow";

    //remaining code omitted
    Tuesday, December 1, 2009 5:49 AM


  • Hello,


    Welcome to LINQ to SQL forums!


    I am not quite familiar with the MVC web development.  But the IList is a generic interface here.  We cannot initialize an instance of such interface.  Instead, we can create an instance of generic object that has implemented the IList interface, like the generic List:

    IList<Traver> list = new List<Traver>();


    Does it solve the problem?   If you have any other questions, please feel free to let me know.   


    Have a nice day!



    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, December 1, 2009 8:06 AM

All replies