InvalidOperationException When calling ResourceManager.GetString

后端 未结 2 1669
再見小時候
再見小時候 2021-01-12 00:13

My application throw the exception occasionally:

Exception type: InvalidOperationException Exception message: Collection was modified; enumeration

2条回答
  •  猫巷女王i
    2021-01-12 00:21

    After a long time checking, I found the root cause. And here's my code cause above issue:

    AppDomain.CurrentDomain.GetAssemblies().
    

    Because this method try to load generated assemblies such as "web_adg_gfgt_dfd.dll" and they can be removed when IIS recycle .So to fix it we only need to avoid loading "generated assemblies".

    Therefore we have 2 way for fixing:

    1.Filter "generated assemblies":

    AppDomain.CurrentDomain.GetAssemblies().Where(i => i.IsDynamic == false).ToList()
    

    2.Using this method :

    BuildManager.GetReferencedAssemblies().Cast().ToList()
    

提交回复
热议问题