πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.csharpbuilder.language.csharp
2 messages
2 total messages Started by Raul Lorenzo Wed, 01 Nov 2006 11:46
Activator.CreateInstance MissingMethodException
#191
Author: Raul Lorenzo
Date: Wed, 01 Nov 2006 11:46
48 lines
2139 bytes
Hello,

I am trying creating a class dynamically at runtime with
Activator.CreateInstance(ObjType); where ObjType is retrieved through

foreach (Type tipo in ass.GetTypes())
{
ObjType=tipo.GetType();
tmp=(IPlugin)Activator.CreateInstance(ObjType);
}

ObjType is "linked" with per example this class

public class PersonaUserControlController:AbstractUserControlController
	{
	private IAlumnosUseCase model;
	private IPersonaUserControl view;
	public PersonaUserControlController()
		{
		//
		// TODO: Add constructor logic here
		//
		this.model =
(IAlumnosUseCase)UseCaseFactory.getInstance().getUseCase("AlumnosUseCase");
		this.view =
(IPersonaUserControl)UserControlFactory.getInstance().getUserControl("PersonaUserControl");
		plugin_name = "PersonaUserControl";
		ConfigureMenu();
		}
	...more methods but only one constructor
	}

/***************************************************************/
I think this could help....

abstract public class
AbstractUserControlController:AbstractPlugin,IUserControlController
		{
		}

abstract public class AbstractPlugin:IPlugin
	{
	}

/***************************************************************/
Why did exception raises if one constructor exists and without parameters?

Thanks in advance
Re: Activator.CreateInstance MissingMethodException
#192
Author: Joanna Carter [TeamB]
Date: Wed, 01 Nov 2006 17:45
39 lines
1917 bytes
"Raul Lorenzo" <rlorenb@agalisa.es> a οΏ½crit dans le message de news: 
4548891f$1@newsgroups.borland.com...

| I am trying creating a class dynamically at runtime with
| Activator.CreateInstance(ObjType); where ObjType is retrieved through
|
| foreach (Type tipo in ass.GetTypes())
| {
| ObjType=tipo.GetType();
| tmp=(IPlugin)Activator.CreateInstance(ObjType);
| }

I think your problem is that you are getting the type of System.Type !!

foreach (Type tipo in ass.GetTypes())
{

  // assuming tipo now contains the type that you want to create...

| ObjType=tipo.GetType();

  // ObjType now contains System.Type as that would be the type of tipo.

| tmp=(IPlugin)Activator.CreateInstance(ObjType);
| }

I think you need to remove one line of code like this :

foreach (Type tipo in ass.GetTypes())
{

  tmp=(IPlugin)Activator.CreateInstance(tipo);
}

Joanna

-- 
Joanna Carter [TeamB]
Consultant Software Engineer 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads