Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i'm using divils article to teach me how to do plug ins....

I've gotten stuck... This is my main file where i'd like to use the plug... the rest of the files mimic divil's *note i removed his form and included that in the 'main' file. i hope this code is enough


public class jrnMain
{
	public static void Main()
	{
	    jrn.IjrnHost objHost = new jrn.Host();
		int index;
		//get a list of plugins
		jrn.PlugServices.availablePlug[] plugins = jrn.PlugServices.findPlug(Path.GetDirectoryName(Application.ExecutablePath), "jrn.IjrnPlug");

		//loop through available plugins, creating instances and adding them to listbox
		for(index = 0; index <= plugins.Length - 1;index++)
		{		
			 jrn.IjrnPlug objPlug;
			 objPlug =  (jrn.IjrnPlug)PlugServices.CreateInstance(plugins[index]);
			 objPlug.Initialize(objHost);
			 Console.WriteLine(((jrn.IjrnPlug)objPlug).Name());
			
		}//for
	}
}//class


 

 

I get the following error "object reference not set to an instance of an object" on the line Console.WriteLine( .....Name);

I understand what that error means but i don't get how i'm supposed to create an instance. In Divil's vb version he does a DirectCast. Which ithought my line of code was the = of. I'm just confused.

I had all this working at one point now it's seems shot.

Any ideas?

 

thanks

brandon

i'm not lazy i'm just resting before i get tired.
Posted

Maybe that means that your application isn't a Console Application ?

 

When I use Console.WriteLine(...) with a Form based application... I got the same error as you.

 

However... I didn't followed the divil's course so... I might be wrong.

 

I think it don't work because of this line... but ... it's just my opinion.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

yes they implement the interface.

 

Correction to my ealier post it is the obj.Initialize line that throws the exception

 

 

Should i attach the whole project? (it's not very big). I have a feeling it's somethign stupid but i'm just stuck and i think my eyes are going to fall out.

 

thanks,

brandon

i'm not lazy i'm just resting before i get tired.
Posted
Give us the line in the Initialize where it crash and some related code.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

Here are the files...

 

Interfaces is compiled as it's own dll

MTUer is compiled as it's own dll

 

PluginServices, Main and Host are part of a console application.

 

All files are compiled in the same dir

Host.zip

i'm not lazy i'm just resting before i get tired.
  • Administrators
Posted (edited)

firstly change the line

Console.WriteLine(((jrn.IjrnPlug)objPlug).Name());

to

Console.WriteLine(((jrn.IjrnPlug)objPlug).Name);

 

Also change your implementation of ExamineAssembly to

public static void ExamineAssembly(Assembly dll, string thisInterface, ArrayList plugs)
	{
		Type objInterface=null;
		availablePlug plug;

		//loop through each type in dll
		foreach(Type objType in dll.GetTypes())
		{
			//only check public types
			if(objType.IsPublic)
			{
				//ignore base classes and interfaces
				if(!(objType.IsAbstract))
				{
				objInterface = objType.GetInterface(thisInterface,true);
			
				//see if this interface implements our interface
				if (thisInterface != null)
				{
					plug = new availablePlug();
					plug.assemblyPath = dll.Location;
					plug.className = objType.FullName;
					plugs.Add(plug);
				}//if
				}//if
			}//if
		}//foreach
	}//void

you had a misplaced opening brace after the check for abstract type.

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

dude you are the man... thanksf or all the time you put into looking at that... i haven't tested it yet but it think it will work now. throughout changes i missed some little things that were tough to see

 

About removing the parens from the Name property.... It's telling me i need them¿?¿

There are some other bugs in other projects in the solution.... could those keep it from checking sytax of this project correctly? The interface is declared properly... i'm gonna clean up these other bugs and see if that helps.

 

THANKS AGAIN, udaman

later

brandon

 

I'll

i'm not lazy i'm just resting before i get tired.
Posted (edited)

uggg

 

Object Reference not set to an instance of an object?

 objPlug.Initialize(objHost);

 

// i changed that code to this

if(objPlug != null)
			{
				objPlug.Initialize(objHost);
				Console.WriteLine(((jrn.IjrnPlug)objPlug).Name());
			}

 

Now i get the error Specified cast is not valid after skipping a few null values.

Could the PlugServices.CreateInstance method be screwy??? (see above attachment for the file)

 

 

 

 

here is the code minus the added code above

public class jrnMain
{
	[sTAThread]
	public static void Main()
	{
	    jrn.IjrnHost objHost = new jrn.Host();
		int index;
		//get a list of plugins
		jrn.PlugServices.availablePlug[] plugins = jrn.PlugServices.findPlug(Path.GetDirectoryName(Application.ExecutablePath), "jrn.IjrnPlug");

		//loop through available plugins, creating instances and adding them to listbox
		for(index = 0; index <= plugins.Length - 1;index++)
		{		
			 jrn.IjrnPlug objPlug = null;
			 objPlug =  (jrn.IjrnPlug)PlugServices.CreateInstance(plugins[index]);
			 objPlug.Initialize(objHost);
			 Console.WriteLine(((jrn.IjrnPlug)objPlug).Name());
			
		}//for
	}
}//class

 

i could of sworn i had a firmer grasp of programming than this....what's the deal?

 

ugggggg

brandon

Edited by bpayne111
i'm not lazy i'm just resting before i get tired.
  • Administrators
Posted

Not sure what the problem could be, the version I was hacking around with here works fine - running it just displays MTUer to the console.

 

I've attached my working copy - may be worth doing a diff with your sources to see if anything else has changed.

Plugins.zip

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...