ILearnable .Net

August 16, 2012

ASPNET_COMPILER: “Circular file references are not allowed” or “how bad neighbors can ruin the neighborhood”

Filed under: Uncategorized — andreakn @ 07:36

Yesterday I came across a cute little bug in our codebase (asp.net) which had me totally stumped for a bit.

After a massive change in an underlying API which introduced breakage left and right I had finally managed to get the codebase to compile again and was about to investigate whether changes were needed in the code-front files (.ascx / .aspx / .master). In order to do this somewhat efficiently I ran the aspnet_compiler.exe on the codebase to see what it would tell me:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler -p “E:\*path_to_solution*\*project_directory*\” -v “E:\temp\compilationoutput”

It barfed on me exclaiming “Circular file references are not allowed”. Well isn’t that just nice? I’m fairly certain that I don’t have any “circular file reference”s in the codebase so just what does this mean? After googling a bit I tried running a modified command:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler -p “E:\*path_to_solution*\*project_directory*\” -v “E:\temp\compilationoutput” -fixednames e:\temp\aspnetout

which ran without any such errors.

 

after thinking for a bit I realized what the problem was: Asp.Net compiles all ascx-controls *in the same folder* into *one* dll. So if you have two folders A and B, each with two controls (A1, A2 and B1,B2), while it is obviously not good to have A1 reference B1 and B1 reference A1 back, it is not so obviously similarly no good having A1 reference B1 and also B2 reference A2. Even though none of the files have a circular references, because of the way they are packaged into dlls the resulting dlls *do* have circular references.

There are two ways to fix this:

1) compile each control into its own dll. That way they are not affected by their “neighbors'” behaviors at all (this is done by the aspnet_compiler when you specify “-fixednames”, it is also achieved in the running code by setting batch=”false” in the compilation section of web.config)

2) compile *all* controls into a single dll (however, afaik there is no way to specify this, neither using aspnet_compiler or using web.config)

 

In the end I tracked down which control was being a lousy neighbor to the other controls in the same folder and moved it to a new neighborhood

 

Advertisements

1 Comment »

  1. You still need to find out which page is causing the error. One method is to look at your last files created or modified through the solution explorer in Visual Studio, right click on the file and “exclude from project”. Through the process of elimination you can determine which page is causing the error. Once the page causing the error is excluded the project will compile and you can go back to the page and look for the error.

    Comment by Antony Goddard — May 14, 2013 @ 18:40 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: