Fixing the “circular file references are not allowed” Error in ASP.net

If you get the “circular file references are not allowed” error in an ASP.net Website Project and you do not have any controls that have any obvious circular references, what does the error mean and how do you fix it?

See this blog post from Siderite Zackwehdex as well as this MSDN forum post: by default, in a Website Project, ASP.net compiles one dll per folder in an ASP.net project. So if you have the following setup:

/folder1/Control1.ascx > References Control2
/folder2/Control2.ascx > References Control3
/folder1/Control3.ascx

This means that the folder1 dll will reference the folder2 dll which will again reference the folder1 dll, causing a “circular file reference”.

Even if there is not a direct path between the controls, looping into a circular reference, but there is a direct path connecting the circular reference through other controls in the same directories, it can throw the circular file references error. For example:

/folder1/Control1.ascx > References /folder2/Control2a.ascx
/folder2/Control2b.ascx > References /folder1/Control3.ascx
/folder1/Control3.ascx

Ways to fix it:

  1. Rearrange the layout of your controls (or masterpages) to remove the circular references (normally this will mean moving one control to another folder – in the example above, move control2 to folder1). This is the preferred solution.
  2. Use batch=”false” in the compilation tag of the web.config file. This will cause a new dll to be created for each control/page in the site. This should fix the error but is really lousy for performance, so it should be avoided (especially on production sites).

(This has happened to me a couple of times already, so posting it here as a reminder to myself for the next time).

Tagged , , . Bookmark the permalink.

16 Responses to Fixing the “circular file references are not allowed” Error in ASP.net

  1. Mahmoud Alam says:

    Thanks :)
    really helped me …

  2. jalpari says:

    it helps me out !
    really thanx although i did not like wot u said in last

    (This has happened to me a couple of times already, so posting it here as a reminder to myself for the next time)

  3. Aref says:

    Thank u…

  4. chris says:

    you could also put control3.ascx in /folder1/uc3/ this way it’s still organized into a logical grouping, as long as it’s not in the same folder with control1.ascx

  5. Mike says:

    This helped me snuff out a master page issue this morning. Thanks!

  6. Hallgeir says:

    I got this problem when I had hierarchy of usercontrols included into an .aspx. The solution was to add the following line into the system.web section in web.config.

  7. Hallgeir says:

    It seams like the xml from my previous post was removed when submiting.
    But add this line inside system.web section (including tags)
    compilation batch=”false”

  8. Jonathan says:

    Thanks a lot

  9. Travis says:

    Another way this can happen, even if you have batch=”false”, is by not checking ‘Use fixed naming and single page assemblies’ on the Publish Website configuration page, if you are, in fact, publishing the website. The publishing activity does not respect the compilation settings in the web.config file.

  10. Paul says:

    And … Visual Studio (2008) can just get confused and give the message erroneously. In my case, the message was pointing to a Register tag in a Master Page referencing a particular control.

    After checking version control for recent changes to the control and MasterPage, came up empty.

    Finally, just deleted the Src attrib of the Register tag and then filled it in with exactly the same file reference that was there before.

    Problem solved.

  11. Pree says:

    I have tried all these…but my error still stays on my head.. :-(

    if there is any other suggestion Plz help…

  12. Johnson Yang says:

    Thank you very much, that issue was bothering me for a long time until i read your post.

  13. brijesh says:

    check master page.
    write AutoEventWireup=”true”

  14. Kerrit says:

    This has solved a persistent, frustrating error I’ve been having in VS2008 when debugging caused by certain ascx controls not rebuilding properly. Thank you so, so much.

  15. Pingback: Circular file references not allowed | Younkins Answers

  16. Pingback: Error CS0433 in large precompiled Asp.net Website Project - Technology

Leave a Reply

Your email address will not be published. Required fields are marked *