Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do I get a SerializationException if I do not copy my .NET dll into the Office application folder?
    primarykey
    data
    text
    <p>I am referencing a C# dll from Excel VBA. This C# dll connects to a .NET Remote Service. One of the types that the Remote Service passes as a parameter, TSConditionList, is contained in general.dll. If I do not copy general.dll to the Office application folder then I get a serialization exception, because the SoapFormatter doesn't have the correct type information.</p> <hr> <p>My C# dll is TarsanExcelConnector.dll. I use REGASM to register this C# dll at the fixed location 'C:\TarsanExcelConnector'.</p> <p>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Regasm.exe TarsanExcelConnector.dll /codebase /tlb:TarsanExcelConnector.tlb</p> <p>In the 'C:\TarsanExcelConnector' directory I have a number of DLL's that are referenced by TarsanExcelConnector.dll:</p> <ul> <li>general.dll</li> <li>TradeSourceParsers.dll</li> <li>TradeSourcePureDataAdapter.dll</li> </ul> <p>All three of these assemblies are correctly located and loaded into the AppDomain.</p> <p>My VBA code is as follows:</p> <pre><code>Public Function GetTradesDebug(url As String, conditionList() As Variant, contextMap() As Variant) As String Dim TTSConnection As New TarsanExcelConnector.TarsanExcelConnector GetTradesDebug = TTSConnection.GetTradesDebug(url, conditionList, contextMap) End Function </code></pre> <p>This fails with the following exception:</p> <pre><code>System.Runtime.Serialization.SerializationException: Invalid method signature 'a1:TSConditionList a2:StringDictionary'. Server stack trace: at System.Runtime.Serialization.Formatters.Soap.SoapHandler.ProcessType(ParseRecord pr, ParseRecord objectPr) at System.Runtime.Serialization.Formatters.Soap.SoapHandler.ProcessAttributes(ParseRecord pr, ParseRecord objectPr) at System.Runtime.Serialization.Formatters.Soap.SoapHandler.EndElement(String prefix, String name, String urn) at System.Runtime.Serialization.Formatters.Soap.SoapParser.ParseXml() at System.Runtime.Serialization.Formatters.Soap.SoapParser.Run() at System.Runtime.Serialization.Formatters.Soap.ObjectReader.Deserialize (HeaderHandler handler, ISerParser serParser) at System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream serializationStream, HeaderHandler handler) at System.Runtime.Remoting.Channels.CoreChannel.DeserializeSoapResponseMessage(Stream inputStream, IMessage requestMsg, Header[] h, Boolean bStrictBinding) at System.Runtime.Remoting.Channels.SoapClientFormatterSink.DeserializeMessage(IMethodCallMessage mcm, ITransportHeaders headers, Stream stream) at System.Runtime.Remoting.Channels.SoapClientFormatterSink.SyncProcessMessage(IMessage msg) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type) at GFX.Services.ITradeSourceService.GetTrades(TSConditionList conditionList, StringDictionary contextMap) at GFX.Services.Pure.TradeSourceClient.GetTrades(TSConditionList conditionList, StringDictionary contextMap) at TTSConnector.TarsanTradeSourceConnector.GetTrades(String tssUrl, Object[,] tssConditionList, Object[,] tssContextMap) in C:\new_code\TTSConnector\TTSConnector\TarsanTradeSourceConnector.cs:line 99 at TTSConnector.TarsanTradeSourceConnector.GetTradesDebug(String tssUrl, Object[,] tssConditionList, Object[,] tssContextMap) in C:\new_code\TTSConnector\TTSConnector\TarsanTradeSourceConnector.cs:line 66 </code></pre> <hr> <p>If I copy general.dll into the office application directory then I do not get this exception. </p> <p>For Windows 7/Excel 2010 I copy to here: C:\Program Files (x86)\Microsoft Office\Office14\general.dll</p> <p>For Windows XP/Excel 2003 I copy to here: C:\Program Files\Microsoft Office\Office11\general.dll</p> <p>I don't understand why the SoapFormatter is not seeing the general.dll in the 'C:\TarsanExcelConnector' directory?? If I check the assemblies that are loaded into the AppDomain I can see that it is definately loading the assembly from 'C:/TarsanExcelConnector/general.DLL'.</p> <hr> <p>When I wrote some test methods to find the troublesome type, the much more useful SerializationException I got was something like this: 'Parse Error, no assembly associated with Xml key TSConditionList'. This type is contained in general.dll.</p> <p>If the runtime loads the assembly from C:\TarsanExcelConnector then it can't find the type. If the runtime loads the assembly from the Office directory, then the Serialization succeeds. WHY?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload