By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,919 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,919 IT Pros & Developers. It's quick & easy.

Creating AppDomain for 3rd Party Win32 DLL that isn't marked "serializable"

P: n/a
I have a 3rd Party DLL that is a Win32 NOT .NET Assembly that is misbehaving.
I am trying to isolate it in its own AppDomain. I got to load but can not create an
instance. I receive the following error:

"The type MyNameSpace.MyClass in Assembly MyAssembly, Version=1.0.1797.22641,
Culture=neutral, PublicKeyToken=null is not marked as serializable."

I changed the names to protect the innocent... :)
Is there anything that I can do short of creating a new managed .NET DLL to call the
3rd Party DLL?

namespace LiveCode.LiveInterface
/// <summary>
/// Factory class to create objects exposing ILiveInterface
/// </summary>
public class LiveInterfaceFactory : MarshalByRefObject
private const BindingFlags bfi =
BindingFlags.Public |
BindingFlags.Instance |

public LiveInterfaceFactory() {}

/// <summary> Factory method to create an instance of the type whose name is specified,
/// using the named assembly file and the constructor that best matches the specified
/// parameters. </summary>
/// <param name="assemblyFile"> The name of a file that contains an assembly where the
/// type named typeName is sought. </param>
/// <param name="typeName"> The name of the preferred type. </param>
/// <param name="constructArgs"> An array of arguments that match in number, order, and
/// type the parameters of the constructor to invoke, or null for default constructor. </param>
/// <returns> The return value is the created object represented as ILiveInterface. </returns>
public IFunctionProvider Create( string assemblyFile, string typeName, object[] constructArgs )
return (MyInterface) Activator.CreateInstanceFrom(
assemblyFile, typeName, false, bfi, null, constructArgs,
null, null, null ).Unwrap();

AppDomain domain = AppDomain.CreateDomain("MyNewDomain");

LiveInterfaceFactory factory = (LiveInterfaceFactory) domain.CreateInstance
("LiveInterface", "LiveCode.LiveInterface.LiveInterfaceFactory").Unw rap();

// with the help of this factory, we can now create a real 'LiveClass' instance
_fp = factory.Create(
catch (Exception ex)
string s = ex.Message;
s = null;

Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.