私のアプリケーションは、時折例外をスローResourceManager.GetString呼び出す:InvalidOperationExceptionが
例外タイプ:InvalidOperationException例外メッセージ: コレクションが変更されました。列挙操作が実行されないことがあります。
そして、ここでスタックトレース
Exception type: InvalidOperationException
Exception message: Collection was modified; enumeration operation may not execute.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
そして、ここに私のコードですです:
public IList<Function> MapWithLanguage(IList<Function> list)
{
if (list == null)
{
return null;
}
var currentResource = Type.GetType("Fanex.Athena.Models.ViewModel.Menu, Fanex.Athena.Models");
ResourceManager rm = new ResourceManager(currentResource);
var newList = new List<Function>();
foreach (var func in list)
{
newList.Add(new Function
{
Name = rm.GetString("Menu_" + func.FunctionId),
});
}
return newList;
}
誰も助けることができる、それはとても奇妙です?!
ショーの呼び出しコード – Backs
からシェアを行いますこの例外が生成された場所。 – Prabhat
私はちょうど私のコードを更新しました!、見てください@Backs –