473,241 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Question about Assembly.Load()

Can I load a assembly from memory by Assembly.Load(string) ?

Jan 10 '06 #1
5 1421
ia*******@gmail.com wrote:
Can I load a assembly from memory by Assembly.Load(string) ?


I don't believe so - but you can use Assembly.Load(byte[]).

Jon

Jan 10 '06 #2
How can I delete the assembly file after loading it?
MyClass.dll is a library file at current directory.
Here is my code for testing:

using System;
using System.IO;
using System.Reflection;

public class TestAssembly
{
public void DoIt()
{
Assembly assembly=Assembly.Load("MyClass");
/*
Type type=assembly.GetType("MyNS.MyClass");

Console.WriteLine(type.FullName);

ConstructorInfo ci=type.GetConstructor(Type.EmptyTypes);
object obj=ci.Invoke(null);

MyNS.MyClass myclass=obj as MyNS.MyClass;

Console.WriteLine(myclass!=null);
*/
}
}

public class Test
{
public static void Main()
{
TestAssembly test = new TestAssembly();
test.DoIt();

File.Delete("MyClass.dll");
}
}
An UnauthorizedAccessException exception is thrown because of the last
line of Main method.
How to delete the file MyClass.dll?

Jan 10 '06 #3
ia*******@gmail.com wrote:
How can I delete the assembly file after loading it?


Well, have you tried loading the file into a byte array (using
MemoryStream, probably) and then passing that into Assembly.Load? I
believe that in this case a temporary file will actually be written to
disk anyway, but it might help.

Jon

Jan 10 '06 #4
Thank you.
But I'm writing test codes for a class which uses Assembly.Load(String)
to load a assembly, so I want to know how to solve this case.

Jan 10 '06 #5

<ia*******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
| Thank you.
| But I'm writing test codes for a class which uses Assembly.Load(String)
| to load a assembly, so I want to know how to solve this case.
|

You can create an additional Application domain to load/run your test
assembly. When done with this assembly you can unload the AD, this will
release the assembly and the OS will release the file handle so that you are
free to delete or replace the file.

Willy.

Jan 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Angelos Karantzalis | last post by:
Hi guys, I'm trying to load a class instance dynamically, and then cast it to it's base type so I can use it in my app. More specifically, I'm dynamically instantiating a...
8
by: Shaun C Farrugia | last post by:
I have a multi team solution being built where teams are segmented off into seperate projects. One project is an over all framework containing a Broker class responsible for instantiating...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
2
by: Lee Alexander | last post by:
Why does Assembly.Load allow this: Assembly.Load( "mscorlib" ); if you try the following it fails as expected: Assembly.Load( "System" ); Since it should be (for framework 1.1):...
12
by: Jones | last post by:
I am having problems with my C# project. The project was built using VS.net (original release with service pack 1). The project includes windows forms and a DLL (dot.net) After getting the...
2
by: Dan | last post by:
Let's say I have a class like: class Dummy { public const string CONE = "one"; public const string CTWO = "two"; ... other stuff .... }
4
by: Doug Handler | last post by:
Ok, I think this is my last one - in my app, the user can select via a dialog box the dll's they want to load. I use a checkbox to track this (no worries there), but, once a dll has been bound,...
3
by: John Wright | last post by:
How can I set the property of a loaded Assembly using reflection. My Shell program will log in a person and retrieve a list of all programs the person can use. When the shell program launches a...
0
by: knightrider | last post by:
I am trying to iterate through all of the assemblies in the share that is our production source code repository and gather information about the assemblies (number of classes and methods contained...
2
by: Srikumar Natarajan | last post by:
I have a question on Reflections. Basically, I have two visual studio solutions: SolA & SolB. SolA has a console application project and a class library project. SolB has some framework class...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
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...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.