How release file loaded with Assembly.LoadFrom() ?

load the file into a byte array and use Assembly.Load(byte[]) instead.
        private void GenerateWebserviceAgents()
        
{
            
byte[] rawAssembly = LoadFile(webServiceAssemblyPath);
            Assembly ass 
= Assembly.Load(rawAssembly);
            
if (ass == nullreturn;

            
foreach (Type t in ass.GetTypes())
            
{
                
            }

        }


        
// Loads the content of a file to a byte array. 
        static byte[] LoadFile(string filename)
        
{
            FileStream fs 
= new FileStream(filename, FileMode.Open);
            
byte[] buffer = new byte[(int)fs.Length];
            fs.Read(buffer, 
0, buffer.Length);
            fs.Close();

            
return buffer;
        }
  
原文地址:https://www.cnblogs.com/wmz/p/1063167.html