471,354 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 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 1333
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Angelos Karantzalis | last post: by
8 posts views Thread by Shaun C Farrugia | last post: by
2 posts views Thread by Lee Alexander | last post: by
12 posts views Thread by Jones | last post: by
2 posts views Thread by Dan | last post: by
4 posts views Thread by Doug Handler | last post: by
3 posts views Thread by John Wright | last post: by
reply views Thread by knightrider | last post: by
2 posts views Thread by Srikumar Natarajan | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.