3. C #/Common exceptions in. NET Programming (continuous update ),

Source: Internet
Author: User

3. C #/Common exceptions in. NET Programming (continuous update ),

1. Object reference not set to an instance of an object.

If an object is not referenced (referenced) to an instance of an object, it means that an object is null, but you are using it to draw out various things.

2. An entity object cannot be referenced by multiple instances of IEntityChangeTracker.

An object cannot be referenced by multiple IEntityChangeTracker instances. First, refer to the description of adding, deleting, modifying, and especially modifying objects in the Entity Framework in MSDN. We can see that the instruction document contains the following sentence: "Object Service uses an IEntityChangeTracker instance to track changes to the objects attached to ObjectContext", 1) Tracker is used to track changes to the attributes of an object, 2) the object to be tracked is the object appended to a certain context. 3) the error message indicates that an object cannot be tracked by multiple trackers, that is, an object attached to a specific Context has a Tracker.

Then I felt that the blog that helped me solve this problem was not very clear, or it may be that I had poor understanding ability. I tried to analyze it myself. Corresponding to the original post, An Entity must be a user. Why does it have multiple IEntityChangeTracker instances, obviously because it is attached to two contexts, RoleManager. getRoleById () method and UserManager. the context of the Add () method is different from that of the Entities method.

In general, perform operations on the same object (Database Association) in the same context.

3. Collection was modified; enumeration operation may not execute.

Perform foreach traversal on a set. If foreach adds or removes a set, this error is returned.

This is determined by the features of IEnumerator. refer to the remarks section:

-------------------------------- Good evening --------------------------------

As long as the Set remains unchanged, the enumerated number remains valid. If the set is modified (such as adding, modifying, or deleting elements), the enumerated number becomes invalid and cannot be restored.MoveNextOrResetWill cause InvalidOperationException. IfMoveNextAndCurrentIf the number of enumerations is invalid,CurrentIt will also return the elements it sets.

The enumerated number does not have exclusive access to the set. Therefore, enumeration through the set is not a thread-safe process in essence. Even if a set has been synchronized, other threads can modify the set, which causes an exception in the number of enumerations. To ensure thread security during enumeration, you can lock the set during the enumeration process or catch exceptions caused by changes made by other threads.

-------------------------------- Good evening --------------------------------

You just need to change foreach to for traversal. I forgot a few mistakes in drawing... I have written so much today.

4. Unrecognized attribute 'targetframework '.

  This error occurs when the website is published, that is, the analyzer error message: the unrecognized attribute "targetFramework ". Note that the attribute names are case sensitive.

The problem occurred today () because the. net clr version configuration in the IIS application pool is incorrect.

(PS: some unknown concepts in the online process, such as w3wp.exe, should be interpreted in hyperlink .)

  

Generally, a website corresponds to an application pool with the same name as a website. The IIS application pool. net clr version should be consistent with the. net clr version used by development.

The local machine is generally version 2.0, and the development version is usually high, resulting in mismatch. Reference

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.