Saturday, January 26, 2013

InvalidCastException in AddInToken.Activate

If you're playing with System.AddIn (also called MAF for Managed Addin Framework not to be confused wief MEF which is Managed Extensibility Framework), you might get an InvalidCastException when calling Activate<T> method on some AddInToken instance : unable to cast transparent proxy to type ...

First of all, try to rebuild your pipeline folder from scratch, check with AddInUtil.exe that there are no warning.

If you still get the error, ensure that the program you are running has no dependency on any pipeline assembly. Your main project should not depend on the following assemblies : addin, addin adapter, addin view, contract. Otherwise, the token activation will get completely mixed up.

HTH