« November 2006 | Main | April 2007 »
February 05, 2007
Battling VSTO's SerializationException: Type is not resolved for ...
I've just won half a day battle with VSTO's SerializationException. The actual error turned out to be a red-herring, that was what giving me such a grief (not to mention that this is my first day of cutting down my daily coffee intake)
This is the background of the problem as I posted in MSDN forum earlier today:
I'm currently at loss with this current problem. This is the scenario: I have several c# libraries (all strongly named) in my solution. This solution processes data and serialised the result into a MS SQL Server database.
From my VSTO project (using VB.NET) I tried to access the database and deserialise the result back into my object. Everything works until the moment of deserialisation where I get the SerializationException: Type is not resolved for member ...
I have a test project that accesses the database and deserialise my object and it is working perfectly fine, so I'm certain that the serialisation/deserialisation code is working, but just not within VSTO framework.
Now this error is suspiciously related to way VSTO is run by Excel. I spent ages trying to figure out what went wrong since all the assemblies are available and loaded properly. I even tried strong naming all the assemblies.
I almost gave up before fortunately helped arrived from this thread. Basically it gave me the idea of hooking to AppDomain's AssemblyResolve event to find out if there is a problem. Yes there was, but in a completely different assembly than the one that was in the exception message!
Apparently this is a common problem when .NET is hosted by an external application. Often the virtual machine has difficulties loading assemblies. For example your project requires assembly A and A requires assembly B, normally you only need to add reference to A and the virtual machine will be able to load assembly B automatically, but not with VSTO. The solution is to strong reference (add the reference from Visual Studio's add reference dialog box) the assemblies, and voila, everything works ... half a day later.
Posted by vhadiant at 08:53 PM | Comments (0) | TrackBack
