简体   繁体   中英

EntityFramework throws an exception unless debugging via breakpoints

I have a strange case where EntityFramework throws one of these two exceptions when trying to access an entity:

  • An item with the same key has already been added (If no breakpoint is placed)
  • Duplicate type name within an assembly (if a breakpoint is placed, and I hit continue )

Here is the relevant part of the ERD: ERD

Here is the part of the code that bugs out: 码

The highlighted line is where the exceptions occur.

What happens is this: the code piece before the displayed part gets a list of wallets from the database, and the displayed code is a fragment of the procedure that converts each wallet to readable JSON. so think of this code as being in a for-each loop, where wallet is the variable that represents the current wallet being manipulated in the loop. In the test case, there are two wallets that are retrieved through the database. The first wallet has SourceUser and TargetReortable referring to the same UserAccount entity. the second wallet has the same SourceUser, but TargetReportable refers to a hashtag entity. When the code runs, the first wallet is processed without any problems, but the second wallet returns one of the two exceptions listed above when it tries to access TargetReportable.

There is also something curious that occurs when I play around a bit with the breakpoint debugging feature of visual studio. When I step through the code, and stop just right before reaching the line that throws the exception, I mouse over wallet. SourceUser , to make the following visual pop-up: 在此处输入图片说明

After I make this display popup (which clearly accesses the database to retrieve all that data), the Exception-throwing line is suddenly able to retrieve the correct hashtag, and the rest of the operation runs smoothly.

Anybody have any clue what's causing this behavior? it's been driving me mad for the past few days.

Note, the ERD and the code snippets are fragments of the whole. If you guys think that the problem is related to something outside of this, I'd be glad to show you more.

You probably have DevXpress Visualizer enabled. Try to disable it and the problem will be gone,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM