I made a class library which I want to load when something happens.
How can I load this library and then pass in a paramter?
I tried:
Assembly asm = Assembly.Load("mylibrary");
Type t = asm.GetType("MyClass");
Object obj = Activator.CreateInstance(t, new object[] {myargument});
and I get an exception:
Exception caught: System.ArgumentNullException: Value cannot be null.
Parameter name: type
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args) 5 2400
Max,
The reason you are getting this is that the type, t, is null. When you
make the call to GetType (on the Assembly instance asm), you need to pass
the namespace-qualified type name. Change the string to that, and it should
work.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.com> wrote in message
news:uI**************@TK2MSFTNGP15.phx.gbl... I made a class library which I want to load when something happens. How can I load this library and then pass in a paramter?
I tried:
Assembly asm = Assembly.Load("mylibrary"); Type t = asm.GetType("MyClass"); Object obj = Activator.CreateInstance(t, new object[] {myargument});
and I get an exception:
Exception caught: System.ArgumentNullException: Value cannot be null. Parameter name: type at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args)
What is the namespace-qualified type name?
I changed the code to this and t is still null.
Assembly asm = Assembly.Load("mylibraryfile");
Type t = asm.GetType("mylibraryNamespace");
Object obj = Activator.CreateInstance(t, new object[] {myargument});
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Max,
The reason you are getting this is that the type, t, is null. When you make the call to GetType (on the Assembly instance asm), you need to pass the namespace-qualified type name. Change the string to that, and it should work.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.com> wrote in message news:uI**************@TK2MSFTNGP15.phx.gbl...I made a class library which I want to load when something happens. How can I load this library and then pass in a paramter?
I tried:
Assembly asm = Assembly.Load("mylibrary"); Type t = asm.GetType("MyClass"); Object obj = Activator.CreateInstance(t, new object[] {myargument});
and I get an exception:
Exception caught: System.ArgumentNullException: Value cannot be null. Parameter name: type at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args)
"Max" <ma******@yahoo.com> wrote in message
news:uI**************@TK2MSFTNGP15.phx.gbl... I made a class library which I want to load when something happens. How can I load this library and then pass in a paramter?
I tried:
Assembly asm = Assembly.Load("mylibrary"); Type t = asm.GetType("MyClass"); Object obj = Activator.CreateInstance(t, new object[] {myargument});
and I get an exception:
Exception caught: System.ArgumentNullException: Value cannot be null. Parameter name: type at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args)
That means that t is null. Are you sure "MyClass" exists in "myLibary"?
Willy.
Max,
You need the namespace and the type, like this:
Type t = asm.GetType("mylibrarynamespace.mytype");
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... What is the namespace-qualified type name? I changed the code to this and t is still null.
Assembly asm = Assembly.Load("mylibraryfile"); Type t = asm.GetType("mylibraryNamespace"); Object obj = Activator.CreateInstance(t, new object[] {myargument});
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Max,
The reason you are getting this is that the type, t, is null. When you make the call to GetType (on the Assembly instance asm), you need to pass the namespace-qualified type name. Change the string to that, and it should work.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.com> wrote in message news:uI**************@TK2MSFTNGP15.phx.gbl...I made a class library which I want to load when something happens. How can I load this library and then pass in a paramter?
I tried:
Assembly asm = Assembly.Load("mylibrary"); Type t = asm.GetType("MyClass"); Object obj = Activator.CreateInstance(t, new object[] {myargument});
and I get an exception:
Exception caught: System.ArgumentNullException: Value cannot be null. Parameter name: type at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args)
Yes the class exists.
Anyways I got it to work by getting all the Types and then getting the method I wanted...
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl... "Max" <ma******@yahoo.com> wrote in message news:uI**************@TK2MSFTNGP15.phx.gbl...I made a class library which I want to load when something happens. How can I load this library and then pass in a paramter?
I tried:
Assembly asm = Assembly.Load("mylibrary"); Type t = asm.GetType("MyClass"); Object obj = Activator.CreateInstance(t, new object[] {myargument});
and I get an exception:
Exception caught: System.ArgumentNullException: Value cannot be null. Parameter name: type at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args)
That means that t is null. Are you sure "MyClass" exists in "myLibary"?
Willy.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Vaishali Patel |
last post by:
I have been working with Satellite Assemblies. However
when trying to load assembly using the resource manager
class and using the GetString method of Resource Manager,
I am getting the following...
|
by: Tom Dacon |
last post by:
If you're not putting assemblies in the GAC, but are referencing shared code
with copylocal=true into the projects that use them, is there any value to
signing the assemblies?
In the environment...
|
by: cody |
last post by:
What are multi file assemblies good for?
What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a
single multi file assembly (A.DLL+A.NETMODULE)?
|
by: Afaq |
last post by:
Hi,
After adding large number of empty resource files (which will be updated
later), we are not able to compile the project. the following is the output
of the build process. It fails while...
|
by: Paul |
last post by:
Snippet from web.config:
<startup>
<supportedRuntime version="v1.0.3705" />
<requiredRuntime version="v1.0.3705"
safemode="true"/>
</startup>
<runtime>
<assemblyBinding...
|
by: G Dean Blake |
last post by:
I wrote and deployed a control with the assembly name of GP to the GAC of
another dev box via drag and drop. a web page using this control has:
<%@ Register TagPrefix="cc1" Namespace="GP"...
|
by: Charles Law |
last post by:
I'm sorry to keep harping on about this one, but it is really quite
important for me to be able to list _all_ required assemblies in my Help
About box. Herfried kindly posted some code before that...
|
by: Smithers |
last post by:
I have a Windows Forms application that implements a plug-in architecture
whereby required assemblies are identified and loaded dynamically.
Here are the relevant classes:
A = application =...
|
by: Mark B |
last post by:
This is my first try at using AJAX. I want the calendars to be enabled if
the user checks CheckBox1. It works OK for a normal all page refresh but
once I introduced the AJAX code it stopped...
|
by: illegal.prime |
last post by:
Hi all, I'm getting unexpected results when trying to preload
assemblies into an AppDomain I'm creating. Upon creation of the
AppDomain - I attach an AssemblyResolve to both my current AppDomain...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |