Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6646209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:23:18+00:00 2026-05-26T00:23:18+00:00

I have an automation addin (implementing Extensibility.IDTExtensibility2), written in C# 4, in which I’m

  • 0

I have an automation addin (implementing Extensibility.IDTExtensibility2), written in C# 4, in which I’m trying to load some (binary) serialized data. It works perfectly in unit tests, but fails when running from within Excel:

Unable to find assembly 'XXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
   at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
   at 

On the BinaryFormatter I’m setting the AssemblyFormat (for both serialization and deserialization) as follows:

serializationCodec.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;

Which I thought would ignore the version as per here.

Then thought it may be due to Excel’s notion of “Trusted Location” so I added the project’s directory and checked all subdirectories, but the error remained.

In vain I tried adding the System.Runtime.Serialization.OptionalFieldAttribute attribute, but it didn’t help.

The unit tests can load the serialized files generated by itself or the same code executed in Excel, but Excel cannot load the serialized data regardless of whether it did the actual serialization.

The fact that Excel cannot deserialize what it has serialized itself hints that this is a redherring as it would obviously have access to the assembly used.

So the question is why does Excel deserialize differently compared to my unit test? (Or perhaps more importantly; How can I get deserialization working in Excel?)

thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:23:18+00:00Added an answer on May 26, 2026 at 12:23 am

    I chased the red herring(s) and got no where with the assumption that it was a versioning issue (I’d looked at shims and all sorts).

    It was in fact due to weird assembly binding; although the automation addin’s DLL could see and load classes from the DLLs it depended on, when it can to deserialization it failed to find the necessary assemblies – even though the deserialization call was from a class belonging to a DLL that it claimed it couldn’t find!

    Solution is certainly a hack but it’s got me past this, so in case anyone else is stuck as i was, here’s the hack(s):

    Inside a class X, that depends on classes Y and Z each from their respective project DLLs (named ProjectForX, ProjectForY and ProjectForZ)

    private static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
        {
            if(args.Name.StartsWith("ProjectForX,")) {
                return typeof(X).Assembly;
            } else if(args.Name.StartsWith("ProjectForY,")) {
                return typeof(Y).Assembly;
            } else if(args.Name.StartsWith("ProjectForZ,")) {
                return typeof(Z).Assembly;
            }
            return null;
        }
    
    
        public static X LoadX(string filename)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;
            ResolveEventHandler handler = new ResolveEventHandler(MyResolveEventHandler);
            currentDomain.AssemblyResolve += handler;
            try {
                Stream stream = new FileStream(@filename, FileMode.Open);
                try {
                    BinaryFormatter deserializer = createBinaryFormatter();
                    X model = (X)deserializer.Deserialize(stream);
                    return model;
                } finally {
                    stream.Close();
                }
            } finally {
                currentDomain.AssemblyResolve -= handler;
            }
        }
    

    Basically it just hooks into the resolve events and provides the correct assembly based on the requested type name – this isn’t particularly safe (I’m using the comma in the assembly descriptor to try to minimize any clashes).

    There’s almost certainly a clear way to do this, and the issue is probably just a result of poor configuration and my limited experience with MS products and C# in particular.

    This wouldn’t have been an issue if I’d just built a monolithic DLL =)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some C# automation code which does interesting things with Microsoft.Office.Interop.Word.Document objects. The
I have created an Automation Add-in for Excel,implemented as a c# class library, which
I have an application that uses MSWord automation to edit some documents, after they
I have a Windows Workflow application that uses classes I've written for COM automation.
I'm trying to automating some tests for an Excel add-in, which is in xll
I'm facing a huge challenge with some excel sheets which was written in 90's
I have created an automation addin in C# .NET and have a shim dll
I have an Excel UDF . It is written in C# and the automation
I have written a ruby script which opens up dlink admin page in firefox
I am doing some automation work that requires several reboots. I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.