views:

358

answers:

1

I'm working on an application where users can create classes programatically at runtime. They have a UI screen where they fill out meta data which gets turned into classes. Basically, the data the user enters is used to generate properties in the .cs file.

So, I need to be able to instantiate an object from the generated class file after the user is finished entering the meta data. Since the class file is new and is not part of the compiled code for the web app, how do I go about loading and instantiating the class?

I am able to generate a DLL programatically after the user is finished entering the meta data. the DLL contains the .cs file representing the meta data entered by the end user.

I've looked into creating an appDomain and loading the dll but that fails because the process can't find the DLL (even though I'm using a physical path for the newly created DLL). I've looked into plugIn architecture - MEF (Microsoft Extensibility Framework), MAF (Microsoft Addin Framework) but I'm a little confused on which to use.

What is the best approach to use?

A: 

Seems like you are using the wrong tool for the job. For this type of dynamic object there is the dynamic extensions in .net40 and u can use a generic property bag object pattern otherwise.

But if you really wanted to do this and keep it simple enough, use MEF. structuremap works wells with known data types. MEF excels at composing together objects that are unknown. all you have to do really is apply an export to the generated classes, compile the dll, ask MEF to compose a container from the dll and then u can retrieve the objects from MEF.

it would also help a lot when you put the error you get when trying to load the generated dll directly into an app domain.

Dovix