How can I create an instance of a System.Web.UI.Control viaCreateInstanceAndUnwrap?

K

kkaminski

Our clients want the ability to write their own custom web controls
that will get dynamically loaded onto a page. Essentially, they will
provide one or more DLLs that contain classes that will inherit from a
specialized base class. This specialized base class is essentially a
MustInherit class that inherits from System.Web.UI.Control. Our
clients want the ability to add, update, and remove these DLLs at any
time in order to change the system without having to restart IIS. I've
been struggling with this problem for a few days, and I've now hit a
stumbling block I'm having trouble overcoming.

From what I've read - In order to load an assembly into my ASP.NET
application in such a way that I can change it at a moment's notice
without restarting IIS, I have to create a new AppDomain. Here's how
I'm creating the AppDomain:

Dim setup As New System.AppDomainSetup
setup.ApplicationBase = path
setup.ShadowCopyFiles = "true"
appDomain = System.AppDomain.CreateDomain("RemoteLoaderDomain ",
System.AppDomain.CurrentDomain.Evidence, setup)

The "path" variable is the path to the directory that contains the
DLLs I'm planning on loading. I created a test DLL that contains a
class that inherits from my specialized base class and is marked as
Serializable. I then try to load it using CreateInstanceAndUnwrap

appDomain.CreateInstanceAndUnwrap("myAssemblyName","myFullQualifiedPathName")

This call fails with the following exception:

System.Runtime.Serialization.SerializationException: The type
System.Web.UI.Control in Assembly System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a is not marked as
serializable.
Server stack trace: at
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType
type, Boolean excludeNonSerializable)
at
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type
type, StreamingContext context)
at
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object
obj, ISurrogateSelector surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
at
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object
obj, ISurrogateSelector surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object
graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream
serializationStream, Object graph, Header[] headers, Boolean fCheck)
at
System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessageParts(ArrayList
argsToSerialize)
at
System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage..ctor(IMethodReturnMessage
mrm)
at
System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage.SmuggleIfPossible(IMessage
msg)
at
System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[]
reqStmBuff, SmuggledMethodCallMessage smuggledMcm,
SmuggledMethodReturnMessage& smuggledMrm)
at
System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatch(Byte[]
reqStmBuff, SmuggledMethodCallMessage smuggledMcm,
SmuggledMethodReturnMessage& smuggledMrm) Exception rethrown at [0]:
at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName,
String typeName)

I've been trying to get this to work for a few hours now, and I've had
no luck. Is it simply not possible to do what I want through the .NET
framework? Oh - also, this is being written using .NET 1.1. I cannot
move to a different version of the framework.

Any help on this would be appreciated.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top