Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The current type is an interface and cannot be constructed. Are you missing a type mapping?

I have a controller class that takes care for the double click command and in turn calls a method that popups a window to the user. Something like :

var popup = container.GetService<PopupCommand>();

In the above line it throws an error saying : The current type, PopupCommand.IPopupDataHandler, is an interface and cannot be constructed. Are you missing a type mapping?

I updated the DLL that contained a method for container.GetService(), before that it used to work fine.

I tried searching in google, but the issues similar are more related to Unity, and i doubt whether my issue is anywhere related to Unity.

like image 783
Manali Avatar asked Apr 19 '12 04:04

Manali


1 Answers

Basically the compiler tells you that you are trying to instantiate an interface.

container.GetService<PopupCommand>() probably brings you back an interface named PopupCommand.IPopupDataHandler, you probably need to cast it to the type you need or change the type to an object, you should also check the constrains of the method - it could be missing the new constraint.

like image 143
G.Y Avatar answered Oct 13 '22 19:10

G.Y