Saturday, May 21, 2005

C# - Loading and creating an object instance from a file

This sample is pretty simple. It is basically loading a latebound object. I am not sure how often most people will have to do this, but I did so I will share it.

This method does not do that much. It will load an assembly from the provided file path and then attempt to create an instance of the type specified. If an empty string is provided for the type, it will create an instance of the first type in the assembly. If there is an error then null is returned.

Use: myType myObj = (myType)CreateLateBoundObjectFromFile(@"c:\myFilePath.dll", "myType");

Code:

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home