We had a Situation when we want to check different binaries files for managed assembly. In our case we had more than 100 files in which 50 of them are .Net assembles and we want to check all of them and load all of .Net assemblies for verification. The very common approach that comes in our mind is AppDomain. But the problem with AppDomain.CurrentDomain is that it not unload the loaded assemble from current AppDomain and keep in mind that we had around 50 .net assembles that we need to check.
Here is come a very handy utility I found in Microsoft.Build.Tasks.dll
public bool FileIsAssembly(string assemblyName)
{
bool _loadAss = false;
AssemblyIdentity identity = null;
try
{
identity = AssemblyIdentity.FromFile(assemblyName);
if (identity != null)
_loadAss = true;
}
catch (Exception ex)
{ }
return _loadAss;
}
|
Enjoy geeks...
Assemble is not load in Current AppDomain so no need to unload that.