CAB, CSLA , AND Serialization

CAB, CSLA , AND Serialization

Old forum URL: forums.lhotka.net/forums/t/2746.aspx


ntownsley posted on Friday, April 20, 2007

Using the Composite Application Block, we have a module that is loaded dynamically that references CSLA and our Business Object Library. 

Calling CancelEdit against a business object, we receive a serialization exception in the UndoableBase.UndoChanges method. 

The following line of code is the culprit -

Dim formatter As New BinaryFormatter()

state = _

CType(formatter.Deserialize(buffer), HybridDictionary)

The exception thrown is "unable to locate assembly XXXXX" which is our Business Object Library using CSLA.

Everything appears to work fine outside of the CAB....

using CSLA 2.1, VS2005, .NET 2.0

RockfordLhotka replied on Friday, April 20, 2007

I'm guessing here (having not looked at how CAB works) that they are using dynamic assembly loading.

There's a "feature" (Microsoft won't call it a bug no matter how hard I try) of .NET where dynamically loaded assemblies don't always find loaded assemblies during deserialization.

This "feature" is a problem in many scenarios, including Enterprise Services, IE and various other dynamic containers for code.

If you look at the EnterpriseServicesPortal in CSLA .NET (discussed in Chapter 4), you'll find code for a "Serialization bug workaround", including a SerializationWorkaround() method. If this method is called once, at the start of your AppDomain, it will resolve the issue.

Again, I don't know that this is your issue - but it is a good bet that it is - and this workaround solves that particular issue.

Bayu replied on Saturday, April 21, 2007

RockfordLhotka:

I'm guessing here (having not looked at how CAB works) that they are using dynamic assembly loading.

There's a "feature" (Microsoft won't call it a bug no matter how hard I try) of .NET where dynamically loaded assemblies don't always find loaded assemblies during deserialization.

This "feature" is a problem in many scenarios, including Enterprise Services, IE and various other dynamic containers for code.

If you look at the EnterpriseServicesPortal in CSLA .NET (discussed in Chapter 4), you'll find code for a "Serialization bug workaround", including a SerializationWorkaround() method. If this method is called once, at the start of your AppDomain, it will resolve the issue.

Again, I don't know that this is your issue - but it is a good bet that it is - and this workaround solves that particular issue.



I wish to underwrite that this bug is indeed occurring at times in CAB.

For diagnosis: try explicitly referencing the assemblies in your app and see if the error disappears. You can keep the dynamic loading in place, no changes needed. The references will simply assure that your app knows about the assemblies. If this solves your problem: welcome to the club. ;-)

Bayu

ntownsley replied on Saturday, June 30, 2007

Rocky - this solution worked out very well.  Thanks for the help and all that you do for the .NET community.

Copyright (c) Marimer LLC