Kevin Grohoske

Director of Software Development

Missing A Directive Or An Assembly Reference? Might Be The ‘Build Options’ Setting.

Posted on August 10, 2007

Yesterday I was trying to help a co-worker that had an odd problem in their ASP.NET 2.0 application. Despite the fact that the class was in the ‘App_Code’ directory and the class was within the same namespace yet it could not accessed/recognized. We were receiving the error, “The type or namespace name ‘example’ could not be found (are you missing a directive or an assembly reference?)”.

Working through the issue I found some interesting possible issues.

1. I could not delete and create a new ‘App_Code’ directory. When I right clicked the project, chose Add, and chose Add Folder, there was no listing for the App_Code folder.

2. I though that perhaps the ‘App_Code’ directory was created incorrectly, due to issue #1. So I found and interesting article explaining how any folder could be configured with the same behavior as the ‘App_Code’ directory with a the simple xml change in the web.config listed below. Unfortunately this did not fix the problem, but could come in handy in the future.

<configuration>
<system>
<compilation>
<codesubdirectories>
<add directoryname="Subdirectory"></add>
</codesubdirectories>
</compilation>
</system>
</configuration>

3. Finally, I found the problem was that the build option on the class file was set to ‘Content’ rather than ‘Compile’. This made me curious of the different settings available and how they can be used. Here are my initial impressions of each.

  • Content - includes the file in the build/deployment, but does not compile.
  • Embedded Resource - used for situations where you want to utilize the source of the file (for example javascript source for AJAX). There are mechanisms to access the resource through the URL back on the server. Here is a good article on the subject.
  • Compile - compiles the class when you build/deploy and includes MSIL as part of the source code.
  • None - not sure when you’d use this option
Comments
Blog post currently doesn't have any comments.

Want to join the conversation?  Leave a comment using the form below!



 Security code