Skip to content

Instantly share code, notes, and snippets.

@grumpydev
Created September 22, 2011 13:29
Show Gist options
  • Save grumpydev/1234767 to your computer and use it in GitHub Desktop.
Save grumpydev/1234767 to your computer and use it in GitHub Desktop.
Small class to work around AppDomain not existing in WinRT - allows enumeration of assemblies in the package -http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/6e8d015b-4c3b-4e1a-9884-d986ba5935c0/
private sealed class AppDomain
{
public static AppDomain CurrentDomain { get; private set; }
static AppDomain()
{
CurrentDomain = new AppDomain();
}
public Assembly[] GetAssemblies()
{
return GetAssemblyListAsync().Result.ToArray();
}
private async System.Threading.Tasks.Task<IEnumerable<Assembly>> GetAssemblyListAsync()
{
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
List<Assembly> assemblies = new List<Assembly>();
foreach (Windows.Storage.StorageFile file in await folder.GetFilesAsync())
{
if (file.FileType == ".dll" || file.FileType == ".exe")
{
AssemblyName name = new AssemblyName() { Name = file.Name };
Assembly asm = Assembly.Load(name);
assemblies.Add(asm);
}
}
return assemblies;
}
}
@dogfuntom
Copy link

Better write
AssemblyName name = new AssemblyName() { Name = Path.GetFileNameWithoutExtension(file.Name) };
at line 24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment