3

I'm trying to deserialize application data and cast it to a specific type from within my event handler, but this seems impossible as it refuses to find my class even though it's compiled into the same assembly as the event handler.

Regardless if I use the ApplicationData utility GetAs<T>() or deserialize it myself I get the same error:

Could not cast as MyClass, reason: Unable to find assembly 'MyAssembly.MyClass, 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)

Has anyone had a similar issue and solved it?

The only way forward that I can see, is either sticking the assembly in the GAC and pray that it can find it, or reduce my object to a string.

File: myeventhandler.cs

namespace MyAssembly
{
    [TcmExtension("This does stuff")]
    public sealed class MyEventHandler : TcmExtension
    {

        public MyEventHandler()
        {
            EventSystem.Subscribe<PublishTransaction, SaveEventArgs>(
                (subject, args, phase) =>

                    // pseudo code!
                    foreach (var item in PublishTransaction))
                    {
                        var appData = item.ReadApplicationData(MyAppDataId);
                        if(appData != null)
                        {
                            var myAppData = appData.GetAs<MyClass>();
                            // do stuff with myAppData
                        }
                    }
                },
                EventPhases.TransactionCommited
            );
        }
    }
}

File: myclass.cs

namespace MyAssembly
{
    [Serializable]
    public class MyClass
    {
        // has properties and constructors
    }
}
7
  • Could you have the wrong version of the Assembly deployed? I have used different classes in Event Systems (from the same assembly and from dependencies) and never had issues there.
    – Nuno Linhares
    Commented Apr 2, 2013 at 11:10
  • Can you please elaborate what actually you are trying to do: means Have you written a particular Event Handler for a Tridion activity and there you have written the above said code and you are getting the above error when this event is triggered...kindly elaborate if my assumptions are wrong Commented Apr 2, 2013 at 11:11
  • Nuno, I only have one version deployed and it's only reference is the <add assemblyFile> entry in the Tridion.ContentManager.config file. I know it's the correct version of the assembly as additional debug logging added to the event handler shows up correctly. Commented Apr 2, 2013 at 11:47
  • Have you tried restarting COM+ Application? Commented Apr 2, 2013 at 13:15
  • 1
    Only about 15 times today :) can't deploy a new version of the DLL without shutting down COM+ Commented Apr 2, 2013 at 13:24

1 Answer 1

6

Can't say I know anything specific about this version of Tridion, but if I was getting odd loader errors, I'd fire up the Fusion Log Viewer. Scott Hanselman describes it here.

That can help you work out where .Net has been looking - which might give you a clue as to what's up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.