Partager via


Visual Studio 2012 unexpected behavior (crash and irrelevant errors)

Scenario 1: = You have ASP.NET (VB.NET) application on Microsoft Visual Studio 2012.

The solution do gets build successfully without any errors.

When we go any class file (*.vb/*.cs) which inside the App_Code folder and type something (in comments) and save, we suddenly get some irrelevant errors point to the same class file which we are editing.

If we double click the errors, it takes us to some line which has no error, in fact the complete class file is error free.

Every time we get different number and type of errors.

Scenario 2: When we try to edit or do any operation by opening a web forms application on VS 2012  we see that VS is intermittently crashing with the below entry in the event log.

Event xmlns="https://schemas.microsoft.com/win/2004/08/events/event">

- <System>

<Provider Name="Application Error" />

<EventID Qualifiers="0">1000</EventID>

<Level>2</Level>

<Task>100</Task>

<Keywords>0x80000000000000</Keywords>

<TimeCreated SystemTime="xxxxxxx" />

<EventRecordID>31205</EventRecordID>

<Channel>Application</Channel>

<Computer>xxxxxx</Computer>

<Security />

</System>

- <EventData>

<Data>devenv.exe</Data>

<Data>11.0.60610.1</Data>

<Data>51b52140</Data>

<Data>msvbide.dll</Data>

<Data>11.0.60610.1</Data>

<Data>51b521bf</Data>

<Data>c0000005</Data>

<Data>001953b8</Data>

<Data>13a0</Data>

<Data>01cedbd1b23787b9</Data>

<Data>C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe</Data>

<Data>C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\msvbide.dll</Data>

<Data>7843d764-47e7-11e3-9cef-7ce9d3e60a9c</Data>

</EventData>

</Event>

 

Workaround:

If we are using App_Code in a web application project, we need to rename into any other folder name.

Why is app_code problem a problem?

Below is the reason why we are not supposed to use app_code in a web application project.

App_Code was introduced to support razor helper classes. Note that vb/cs files added to that app+code should have a build action of Content rather than Compile to ensure they are not compiled with the rest of the project files.

https://msdn.microsoft.com/en-us/library/t990ks23.ASPX

In a Web site project, you can store source code in the App_Code folder, and it will be automatically compiled at run time. The resulting assembly is accessible to any other code in the Web application. The App_Code folder therefore works much like the Bin folder, except that you can store source code in it instead of compiled code. The App_Code folder and its special status in an ASP.NET Web application makes it possible to create custom classes and other source-code-only files and use them in your Web application without having to compile them independently.

The App_Code folder can contain source code files written as traditional class files — that is, files with a .vb extension, .cs extension, and so on. However, it can also include files that are not explicitly in a specific programming language. Examples include .wsdl (Web service description language) files and XML schema (.xsd) files. ASP.NET can compile these files into assemblies.

The App_Code folder can contain as many files and subfolders as you need. You can organize your source code in any way that you find convenient, and ASP.NET will still compile all of the code into a single assembly that is accessible to other code anywhere in the Web application.

App_Code should not be used with web application project.( is written by Principal Program Manager Lead from asp.net team in 2009)=> https://vishaljoshi.blogspot.in/2009/07/appcode-folder-doesnt-work-with-web.html

Deployment of your WAP to the server you will might accidentally move the App_Code\Products.cs on the server as well. This is time when things start getting tricky… Now you have a DLL in the BIN which is provided as a reference to ASP.NET runtime which has the Products class… Also ASP.NET is trying to compile your App_Code folder (as it is a special Runtime folder and that is an expected behavior) which will result in duplicate declaration of your Product class (one in the referenced project DLL and second in the dynamic compilation). As you can imagine duplicate declaration of same type is not desirable.

Additionally, VS will auto generate namespace for your Products class in the DLL to be something like WebApplication1.App_Code.Products vs ASP.NET runtime will produce a hashed version of the name space causing additional connotations giving you weird error messages.

So at a high level there are many reasons why App_Code folder is not supported for Web Application Projects and should be avoided.

 

You might be thinking that If App_Code folder is not suggested in web applications, why do we see it in the options for a web app project in VS2012?

With asp.net webpages 2 (mainly used in MVC4 )we introduced a particular feature on Razor view engine where we can have Razor helpers defined in Razor itself .This is very cool feature with Razor view engine  and is praised even by other open source web development community) and there were some short comings on this feature due to the way it worked. So Initially in the beta phase, product team tossed different ideas and got community feedbacks, and after the beta period product group  decided to add support for App_Code folder in VS 2012  to properly support this feature .

Hope this Helps Smile

 

Technorati Tags: VS2012,visual studio 2012,crash. errors,app_code,web application

Comments

  • Anonymous
    December 02, 2015
    This has helped immensely. Thanks!