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 / .NET Framework / New Users / October 2006

Tip: Looking for answers? Try searching our database.

How to instance type of configuration

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Enosh Chang - 13 Oct 2006 17:25 GMT
Hi all:

I saw there is one line on configuration file as following,

   <add name="MyProfileProvider"
             connectionStringName="MyDatabase"
             applicationName="/"
             type="System.Web.Profile.SqlProfileProvider, System.Web" />

I want to know how to instance type in my code. Thanks!

Best Regards
Enosh Chang
Carl Daniel [VC++ MVP] - 13 Oct 2006 17:33 GMT
> Hi all:
>
[quoted text clipped - 6 lines]
>
> I want to know how to instance type in my code. Thanks!

I think you're asking how to create an instance of a type knowing only the
name of the type.  In that case:

Type ty = Type.GetType(
   "System.Web.Profile.SqlProfileProvider, System.Web"
   );
System.Web.SqlProfileProvider prov
   = (System.Web.SqlProfileProvider)Activator.CreateInstance(ty);

If that wasn't what you were looking for, post back with a more detailed
question.

-cd
Massimo - 13 Oct 2006 17:41 GMT
>> I saw there is one line on configuration file as following,
>>
[quoted text clipped - 13 lines]
> System.Web.SqlProfileProvider prov
>    = (System.Web.SqlProfileProvider)Activator.CreateInstance(ty);

You probably should use an interface or an abstract class here: if you're
reading the type name from a configuration file, chanches are you just don't
know the actual type of the object, so you can't give a type to "prov".

Massimo
Enosh Chang - 14 Oct 2006 00:26 GMT
"Massimo" <barone@mclink.it>
???????:%23LFqsZu7GHA.4084@TK2MSFTNGP05.phx.gbl...

>>> I saw there is one line on configuration file as following,
>>>
[quoted text clipped - 20 lines]
>
> Massimo

That's so great. But I encounter another problem that it displays "Could not
load file or assembly 'XXXXX' or one of its dependencies" for some types.
How to solve this problem, dynamic loading assemblies?

Rate this thread:







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.