Home > .Net, C# > How to call a method from assembly without reference it?

How to call a method from assembly without reference it?

public static void ShowMessageBox
(
string message,
params object[] args
)
{
try
{
// Skip for non-interactive execution.
if (!IsInteractive)
return;

Type type;
object[] info;

type = Type.GetType(“System.Windows.Forms.MessageBox, ” +
“System.Windows.Forms, ” +
“Version=1.0.5000.0, ” +
“Culture=neutral, ” +
“PublicKeyToken=b77a5c561934e089”);
info = new Object[2];
info[0] = String.Format(message, args);
info[1] = Assembly.GetExecutingAssembly().GetName().Name;
type.InvokeMember(“Show”,
/* 280 = */ BindingFlags.Static |
BindingFlags.Public |
BindingFlags.InvokeMethod,
null, null, info);
}
catch
{
}
}
For out Side memory assembly-

Assembly assembly = Assembly.LoadFrom(@”C:\Documents and Settings\Sample.dll”);
Type local_type = assembly.GetType(“GetString”); //Getting Class File Name
Object local_Instance = Activator.CreateInstance(local_type);
string local_string = (string)local_type.InvokeMember(“ReturnString”, BindingFlags.InvokeMethod, null, local_Instance);
//Just invoking return string method,If you are calling any parameterised methods,add params at last parameter here,

Advertisements
Categories: .Net, C#
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: