Hi group!
Is it possible to scan an assembly *which has NOT been added as a
reference* for types, and dynamically create instances of the loaded
types?
I have a program, MyProgram.exe, which at runtime uses
Asseembly.LoadF ile(...) to load an assembly, MyAssembly.dll. When
MyAssembly.dll is added as a reference to the MyProgram project,
serialization and de-serialization works lige a charm.
However, when I remove the reference to MyAssembly.dll in the MyProgram
project, I get an exception upon de-serialization.
Is there something I can do which is like "adding an assembly as a
reference at runtime"?
The best,
Mogens 6 2292
Howdy,
Yes it's possible and quite simple. Have a look at my short C# example
private void button3_Click(o bject sender, System.EventArg s e)
{
System.Reflecti on.Assembly assembly
=
System.Reflecti on.Assembly.Loa dFile("C:\\WIND OWS\\assembly\\ GAC\\Microsoft. VisualBasic\\7. 0.5000.0__b03f5 f7f11d50a3a\\Mi crosoft.VisualB asic.dll");
listBox1.BeginU pdate();
foreach (System.Type type in assembly.GetExp ortedTypes())
{
listBox1.Items. Add(type.FullNa me);
if (type.IsClass && !type.IsAbstrac t)
{
object instance = System.Activato r.CreateInstanc e(type);
}
}
listBox1.EndUpd ate();
}
--
Milosz Skalecki
MCP, MCAD
"mo********@gma il.com" wrote: Hi group!
Is it possible to scan an assembly *which has NOT been added as a reference* for types, and dynamically create instances of the loaded types?
I have a program, MyProgram.exe, which at runtime uses Asseembly.LoadF ile(...) to load an assembly, MyAssembly.dll. When MyAssembly.dll is added as a reference to the MyProgram project, serialization and de-serialization works lige a charm.
However, when I remove the reference to MyAssembly.dll in the MyProgram project, I get an exception upon de-serialization.
Is there something I can do which is like "adding an assembly as a reference at runtime"?
The best, Mogens
> Is it possible to scan an assembly *which has NOT been added as a reference* for types, and dynamically create instances of the loaded types?
YES IT IS
something like this (untested) :
Assembly myAss = Assembly.Load(" myDll.dll");
Type t = myAss.GetType(" namespacemyDll. typeName");
ConstructorInfo ci = new t.GetConstructo r( new t[0] );
object o = ConstructorInfo .Invoke( new object[0] );
// now o is a ref. to an anstance of namespacemyDll. typeName
or
foreach( Type t in myAss.GetTypes( ) )
{
Console.WriteLi ne( "object: " + t.ToString() );
object o = Activator.Creat eInstance(type) ;
// and so on ....foreach( MethodInfo m in t.GetMethods() ....
}
Nicolas Guinet www.nicolasguinet.com
<mo********@gma il.com> a écrit dans le message de news: 11************* ********@u72g20 00...legro ups.com... Hi group!
Is it possible to scan an assembly *which has NOT been added as a reference* for types, and dynamically create instances of the loaded types?
I have a program, MyProgram.exe, which at runtime uses Asseembly.LoadF ile(...) to load an assembly, MyAssembly.dll. When MyAssembly.dll is added as a reference to the MyProgram project, serialization and de-serialization works lige a charm.
However, when I remove the reference to MyAssembly.dll in the MyProgram project, I get an exception upon de-serialization.
Is there something I can do which is like "adding an assembly as a reference at runtime"?
The best, Mogens
Thanks for the replies guys, but I think neither of you really
understood my problem.
I do use Assembly.LoadFi le to load an assembly, and I do use
GetExportedType s to iterate through all types and look for subclasses
of one particular class.
The problem arises when the user of my program saves his work. At this
point all instances of the dynamically loaded types will be serialized
into a file.
Now, when the user quits the program and tries to load his work, a
SerializationEx ception occurs.
I can solve my problem temporarily by adding the assemblies I want to
load at runtime as references to the project, but this does not solve
my problem entirely, because I want to be able to load the assemblies
truly at runtime.
You should make XmlSerializer aware of all types in your objects net.
Use following constructor to specify extra types.
System.Xml.Seri alization.XmlSe rializer(Type type, Type [] extraTypes)
You can subscribe to the AssemblyResolve event; the deserializer will
generate an event for each assembly that needs to be loaded.
<mo********@gma il.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. . Thanks for the replies guys, but I think neither of you really understood my problem.
I do use Assembly.LoadFi le to load an assembly, and I do use GetExportedType s to iterate through all types and look for subclasses of one particular class.
The problem arises when the user of my program saves his work. At this point all instances of the dynamically loaded types will be serialized into a file.
Now, when the user quits the program and tries to load his work, a SerializationEx ception occurs.
I can solve my problem temporarily by adding the assemblies I want to load at runtime as references to the project, but this does not solve my problem entirely, because I want to be able to load the assemblies truly at runtime.
I did this, and it seems to work most of the time. However, it seems
sometimes the event handler does not get called when it should. But I
will figure out why that is on my own...
Thanks for the quick reply!
-Mogens This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: WebRod |
last post by:
Bonjour,
comment savoir en moins de 5 secondes (enfin rapidement quoi) combien de
nouveaux messages non récupérés se trouvent dans une BAL sur une serveur
POP3 (pas d'imap donc)????
(en sachant que lorsque l'on récupère les emails, on ne les supprime pas du
serveur au fur et à mesure)
Parceque OUTLOOK y arrive bien lui!!
|
by: grigoo |
last post by:
bonjour a tous
je me presente a vous::: greg dit le grigoo sur le web ,,etudiant en
bioinformatique a montreal et jusqu au cou dans notre language
prefere....java. et biojava.. et je suis en un newbee dans ce domaine
et me dit que l homme est bien peu de chose
voici en definitive mon probleme>>>
je construit une classe appele symbolListWithGap.
dans celle j y mets un constructeur:::: symbolListWithGap qui recoit
|
by: Laurent Pointal |
last post by:
Bienvenue sur la liste Python francophone, hébergée par l'AFUL, ou
sur le newsgroup fr.comp.lang.python ("fclp").
Votre abonnement à cette liste de diffusion ou votre lecture de
fclp montrent un intérêt pour le langage Python et ce qui tourne
autour. Après quelques temps de lecture, vous serez sûrement amené à
poster vous aussi un message. Voici quelques conseils d'utilisation,
suivi d'une série de liens à partir desquels vous ...
|
by: Michael Dyson |
last post by:
M. Michael DYSON
DIRECTEUR-ADJOINT
SOCIÉTÉ DE SÉCURITÉ SARL.
TEL.00229 20 21 80
Cotonou République du Bénin
Email:michaeldyson2005@latinmail.com
Bonjour .
Je sais que mon message sera d’une grande surprise quand t-il vous
parviendra. Donc, je vous présente toutes mes excuses. Je vous écris
sincèrement dans le but d’obtenir votre coopération et votre confiance pouvant
|
by: Alejandro Scomparin |
last post by:
FORMULACION, PREPARACION Y EVALUACION ECONOMICA Y FINANCIERA DE
PROYECTOS DE TECNOLOGIA INFORMATICA (IT)
en la UTN
Inicia: 17 de Mayo. 19 hs
Dirigido a
Esta preparado para gerentes, jefes, líder de proyectos del área de
IT de todo tipo de organizaciones, y para profesionales de
| |
by: Alejandro Scomparin |
last post by:
FORMULACION, PREPARACION Y EVALUACION ECONOMICA Y FINANCIERA DE
PROYECTOS DE TECNOLOGIA INFORMATICA (IT)
en la UTN
Inicia: 17 de Mayo. 19 hs
Dirigido a
Esta preparado para gerentes, jefes, líder de proyectos del área de
IT de todo tipo de organizaciones, y para profesionales de
|
by: gandalf |
last post by:
Con motivo del enorme esfuerzo realizado para visitar la ciudad
argentina de Córdoba, participar en la Reunión del MERCOSUR, en la
clausura de la Cumbre de los Pueblos en la histórica Universidad de
Córdoba y en la visita a Altagracia, la ciudad donde vivió el Che en
su infancia y unido a esto asistir de inmediato a la conmemoración del
53 aniversario del asalto a los cuarteles Moncada y Carlos Manuel de
Céspedes, el 26 de julio de 1953,...
|
by: crow |
last post by:
http://www.pagina12.com.ar/diario/elpais/1-72984-2006-09-14.html
Por Miguel Bonasso
Desde La Habana
Me había preparado para verlo, pero la realidad fue mucho más fuerte.
Incluso le llevaba de regalo un ordenador de viaje. Es decir una suerte
de cartuchera de cuero argentino, que en su interior tiene espacios
predeterminados para papeles, tarjetas, pasaje, pasaporte, anotaciones
varias, todo lo que necesita un viajero. Sé muy bien que...
|
by: gandalf |
last post by:
CON LA PASION DE SIEMPRE HABLO DE CHAVEZ, DE LA MEDICINA CUBANA... Y DE
SU PROPIA MUERTE
Relato de la nueva gran batalla de Fidel
El líder cubano mostró cómo evoluciona su recuperación en el
encuentro con el diputado argentino. También elogió a Hugo Chávez
por su lucha para ingresar al Consejo Permanente de la ONU y por
aliarse a sectores medios para "hacer los cambios
democráticamente" y mostró su preocupación por terminar de editar
sus...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |