Click here to Skip to main content
15,927,344 members
Home / Discussions / C#
   

C#

 
GeneralReflection and file deletion Pin
Orion Buttigieg30-May-02 15:41
Orion Buttigieg30-May-02 15:41 
hello,

to get information from the dll ie. the methods,types, parameters i use Reflection. at certain times i have to delete this dll which is usually not a problem. the problem is once i've reloaded a dll and performed some reflection on it, that when i go to delete the dll using FileInfo.Delete() i get an Access is Denied exception. so its as if the dll is still being used or a thread that's still alive or.... this one's got me stumped. maybe there's a better way of reflecting the information from the dll or something.

here's the code starting with the Reflection: pretty straight forward. so i get the dll pass it into an Assembly and there you go. for what i need to do i think its about the easiest least overhead way.

string tempPath = Path.GetTempPath();//Gets the path to the MS tempdir
string strMSTempPath = tempPath.Replace(@"\", @"\\");
string strTempName = strNameSpace + ".dll";
Assembly ass = Assembly.LoadFrom(strMSTempPath + strTempName);
string strObject = strNameSpace + "." + strServiceName;
Type typeDynProxy = ass.GetType(strObject);
MethodInfo[] methodArray = typeDynProxy.GetMethods(BindingFlags.Public|BindingFlags.Instance);

this is how i delete the dll from the directory. nothing fancy.

string tempPath = Path.GetTempPath();
string strTempName = tempDeleteDLL + ".dll";
FileInfo fileInfo = new FileInfo(tempPath + strTempName);
fileInfo.Delete();

throws the Exeption as soon as it executes Delete():
"Access to the Path C:\..\..\ is denied."
normally i can delete the dll. just not after i run the Reflection code above.

any ideas or help would be great.

thanks


Orion
GeneralRe: Reflection and file deletion Pin
James T. Johnson30-May-02 17:06
James T. Johnson30-May-02 17:06 
GeneralRe: Reflection and file deletion Pin
Orion Buttigieg31-May-02 5:58
Orion Buttigieg31-May-02 5:58 
GeneralRe: Reflection and file deletion Pin
Eric Gunnerson (msft)31-May-02 8:40
Eric Gunnerson (msft)31-May-02 8:40 
GeneralRe: Reflection and file deletion Pin
Orion Buttigieg31-May-02 8:42
Orion Buttigieg31-May-02 8:42 
GeneralComboBox in Winforms Pin
30-May-02 14:42
suss30-May-02 14:42 
Questionasynchronous calls & threading. which is better? Pin
Li-kai Liu (Angus)28-May-02 23:05
Li-kai Liu (Angus)28-May-02 23:05 
AnswerRe: asynchronous calls & threading. which is better? Pin
Nish Nishant29-May-02 1:46
sitebuilderNish Nishant29-May-02 1:46 
AnswerRe: asynchronous calls & threading. which is better? Pin
Eric Gunnerson (msft)29-May-02 8:18
Eric Gunnerson (msft)29-May-02 8:18 
GeneralRe: asynchronous calls & threading. which is better? Pin
Nish Nishant29-May-02 8:28
sitebuilderNish Nishant29-May-02 8:28 
GeneralRe: asynchronous calls & threading. which is better? Pin
Eric Gunnerson (msft)29-May-02 8:25
Eric Gunnerson (msft)29-May-02 8:25 
GeneralRe: asynchronous calls & threading. which is better? Pin
Li-kai Liu (Angus)29-May-02 17:29
Li-kai Liu (Angus)29-May-02 17:29 
GeneralRe: asynchronous calls & threading. which is better? Pin
Not Active29-May-02 18:13
mentorNot Active29-May-02 18:13 
GeneralRe: asynchronous calls & threading. which is better? Pin
Eric Gunnerson (msft)30-May-02 6:39
Eric Gunnerson (msft)30-May-02 6:39 
GeneralRe: asynchronous calls & threading. which is better? Pin
Eric Gunnerson (msft)30-May-02 7:04
Eric Gunnerson (msft)30-May-02 7:04 
GeneralRe: asynchronous calls & threading. which is better? Pin
James T. Johnson29-May-02 18:16
James T. Johnson29-May-02 18:16 
GeneralRe: asynchronous calls & threading. which is better? Pin
Eric Gunnerson (msft)30-May-02 7:03
Eric Gunnerson (msft)30-May-02 7:03 
GeneralRe: asynchronous calls & threading. which is better? Pin
James T. Johnson30-May-02 17:06
James T. Johnson30-May-02 17:06 
Generalattribute question Pin
meihong28-May-02 22:53
meihong28-May-02 22:53 
GeneralRe: attribute question Pin
James T. Johnson29-May-02 5:11
James T. Johnson29-May-02 5:11 
GeneralRe: attribute question Pin
meihong29-May-02 21:12
meihong29-May-02 21:12 
GeneralListView Problem Pin
28-May-02 22:28
suss28-May-02 22:28 
GeneralQuick Question Pin
Nick Parker28-May-02 17:43
protectorNick Parker28-May-02 17:43 
GeneralRe: Quick Question Pin
Nish Nishant28-May-02 18:34
sitebuilderNish Nishant28-May-02 18:34 
GeneralRe: Quick Question Pin
Nick Parker28-May-02 18:57
protectorNick Parker28-May-02 18:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.