Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Dynamic Class Creation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
herbert422 - 21 Sep 2007 06:19 GMT
I am trying to instantiate a new class using
Activator.CreateInstance(). The class is actually a window's form.
When the process executes the CreateInstance() method it generates an
exception. The exception states that it could not find an assembly.

In the original project that generated the dll, I added a reference to
the dll in the project (via Add Reference in the Solution Explorer
Pane of the IDE). Everything works in that project. Afterwards, I
recompiled it as a dll.

How would I go about solving the linking issue?

Thanks in Advance.
Marc Gravell - 21 Sep 2007 07:46 GMT
Has the necessary .dll made it into the build-output of your main
project (usually under the "bin" folder)? Note that the compiler will
silently drop references that it detects aren't used by your code,
with the effect that it can get removed from the build-output.
Ensure "Copy Local" is set to true on the reference; if that doesn't
work, and the .dll is in your project-scope, then you can try changing
the build-action to "Component", or setting "Copy to Output Directory"
to true.

If the .dll is already there, then please indicate what are you
passing to Activator.CreateInstance()?

Marc
herbert422 - 21 Sep 2007 19:47 GMT
I tried the settings on the DLL files and it still could not find the
library. However, I included both the files in the resource.resx and
that seemed to have solved the issue of the library not being able to
resolve the missing library.

How I am calling the CreateInstance() method is passing in the type of
the construct. So the following:

Assembly myDLL = Assembly.LoadFile(path)
myObject = Activator.CreateInstance(myDLL.GetType("Namespace.MyClass")

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.