Skip to content

Commit

Permalink
Added understandable exception for the case when MainConfigAssemblyAt…
Browse files Browse the repository at this point in the history
…tribute is applied several times
  • Loading branch information
kirmir committed Dec 4, 2016
1 parent 863e7fa commit dee7a58
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ConfigEx/AssemblyLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ public static Assembly GetEntryAssembly()
private static Assembly GetAssemblyWithAttribute()
{
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
var entryAssemblies = from assembly in assemblies
let attribute = assembly.GetCustomAttributes(typeof(MainConfigAssemblyAttribute)).SingleOrDefault()
where attribute != null
select assembly;
var entryAssemblies = (from assembly in assemblies
let attribute = assembly.GetCustomAttributes(typeof (MainConfigAssemblyAttribute)).FirstOrDefault()
where attribute != null
select assembly).ToList();

return entryAssemblies.SingleOrDefault();
if (entryAssemblies.Count > 1)
{
throw new Exception("Only one assembly should be marked as main using the MainConfigAssemblyAttribute");
}

return entryAssemblies.FirstOrDefault();
}
}
}

0 comments on commit dee7a58

Please sign in to comment.