.NET exception caught is unexpectedly null

后端 未结 6 1651
囚心锁ツ
囚心锁ツ 2021-02-05 01:16

See below for an explanation of what is going on

I have a really weird issue where the exception caught is null.

The code uses MEF and tries har

6条回答
  •  隐瞒了意图╮
    2021-02-05 01:39

    Just ran into this same problem. I finally found out that I catched different exceptions with the same name, like you did:

    catch (ReflectionTypeLoadException ex)
    {
        // ... 
    }
    catch (Exception ex)
    {
        // ex is not null!
        // ...
    }
    

    Both are named 'ex'. Changing one of both names solved this problem for me, like:

    catch (ReflectionTypeLoadException reflectionEx)
    {
        // ... 
    }
    catch (Exception ex)
    {
        // ex is null - that should not be possible!
        // ...
    }
    

提交回复
热议问题