Error 19 - Cannot register assembly. Exception has been thrown by the target of an invocation.

Add-in Express™ Support Service
That's what is more important than anything else

Error 19 - Cannot register assembly. Exception has been thrown by the target of an invocation.
Visual Studios hates me. 
Keith Maggio




Posts: 9
Joined: 2013-02-26
I've been through most, if not all, the answers on this site, and I'll knock out the FAQs.

- Windows 7 Ultimate, Visual Studios 2010, Add-in Express v.7.1.4050 Proffessional
- No, there is no code in my class constructor.
- No, I am not mixing versions of .NET
- Yes, registering does work for OTHER solutions, but not the one I'm working in.
- No, I can't give out my code due to company rules.
- Turning on/off COM is useless, since registering turns COM on.

Here's my case: I have an RTD Server and wrapper add-in in one project. This project is using DLL's my company has developed to get the Data from the server in C++. They've been used in other C# projects before, but not as Excel plugins.

These DLL's are unsigned, and so my project's DLL is unsigned as well (Under Properties->Signing, uncheck the Sign the assembly checkbox). The code compiles fine, and I even had it registering fine at one point. I made one code modification, and now it can't register. I've removed the code, cleaned the project, cleaned the solution, restarted Visual Studios, restarted my computer, and still nothing.

Wit's end, here, people. Anyone got a clue?

- Keith
Posted 26 Feb, 2013 17:35:34 Top
Andrei Smolin


Add-in Express team


Posts: 18979
Joined: 2006-05-11
Hello Keith,

I would like to understand when exactly the exception occurs? Do you choose Build | Register ADX Project? Or you run an installer of your add-in?

Please check if you have class-level initializers such as MySuperDuperClass myVariable = new MySuperDuperClass(). Such initializers are executed even before the constructor. And if the code of MySuperDuperType is not prepared to run outside of the host application, it will fail. Instead, you need to initialize such class instances in an aevent e.g. AddinInitialize.

Maybe, your add-in implements some interface provided by some of the DLLs that you use?


Andrei Smolin
Add-in Express Team Leader
Posted 27 Feb, 2013 05:43:51 Top
Keith Maggio




Posts: 9
Joined: 2013-02-26
Hello Andrei,

The exception (though not really an exception. More of a Build Error, like a Linker Error or Syntax Error) occurs when I try to choose Build | Register ADX Project. I click Register ADX Project, it builds all the dependencies, and when it gets to the actual add-in, it immediately throws this into my Error List.

Here's the output from the Error List:
Error	19	Cannot register assembly "C:SomePathSome.dll". 
Exception has been thrown by the target of an invocation.	
c:WindowsMicrosoft.NETFramework4.0.30319Microsoft.Common.targets	3341


So, I was initializing several member variables to null at their declaration
public class A 
{ 
    private MySuperDuperClass myVariable = null; 
    public A() {...

I removed the initialization and it works now. I was beating into my brain "Why oh why doesn't this work!?" and it was all because of null.

Thanks for the help, Andrei!
Posted 27 Feb, 2013 08:19:05 Top
Andrei Smolin


Add-in Express team


Posts: 18979
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 27 Feb, 2013 09:11:38 Top