Interesting Error

Mar 24, 2008 at 1:58 PM
Hi,

Just tracked down an interesting error and thought I'd mention it here to save other people time. I put together a simple test solution and was getting this error when attempting to activate my add-in:
System.ArgumentNullException was unhandled
  Message="Value cannot be null.\r\nParameter name: con"
  Source="mscorlib"
  ParamName="con"
  StackTrace:
       at System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode, ConstructorInfo con)
       at System.AddIn.Hosting.AddInActivator.AssertAndCreateInvoker(Type targetType, Type argType, Type[] methodArgs, ConstructorInfo havCtor)
       at System.AddIn.Hosting.AddInActivator.CreateConsInvoker(Type targetType, Type argType)
       at System.AddIn.Hosting.AddInActivator.AdaptToHost[T](AddInToken pipeline, IContract addInContract)
       at System.AddIn.Hosting.AddInActivator.ActivateInAppDomain[T](AddInToken pipeline, AppDomain domain, AddInControllerImpl controller, Boolean weOwn)
       at System.AddIn.Hosting.AddInActivator.Activate[T](AddInToken token, PermissionSet permissionSet, String appDomainName)
       at System.AddIn.Hosting.AddInActivator.Activate[T](AddInToken token, AddInSecurityLevel level, String appDomainName)
       at System.AddIn.Hosting.AddInActivator.Activate[T](AddInToken token, AddInSecurityLevel level)
       at System.AddIn.Hosting.AddInToken.Activate[T](AddInSecurityLevel trustLevel)
       at AddinTest.Program.Main(String[] args) in C:\Users\kboogaart\Desktop\AddinTest\AddinTest\Program.cs:line 40
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
Reflecting through the code it appeared as though the ConstructorInfo for the add-in was being pulled from an interface, hence was yielding null. Therefore, the call to DynamicILGenerator.Emit was receiving a parameter of null.

It turns out the fix was simple: my host was referencing my contracts DLL. Once I removed this reference, the problem was resolved. Hmmm.

HTH,
Kent
Mar 26, 2008 at 11:50 PM
Edited Mar 27, 2008 at 7:55 AM
I am getting this too but removing the reference to the contracts DLL doesn't fix it. Mine is a WPF app that now has the same references as my WinForms app that works. I did previously have a reference to the contracts DLL but removed it after reading your post.

Thanks,
Ed

Edit: Fixed by also deleting the contracts DLL in the output folder as I had not set the Copy Local to False.