I'm trying to create a blank Visual Web Part project with VS 2012 (on Windows 7) for a site on SP 2010 Foundation. When I build the project, it throws this error "The name 'InitializeControl' does not exist in the current context".

I've also tried using the "SharePoint 2010 Project" and "SharePoint 2010 Visual Web Part" VS 2012 Project templates targeting .NET Framework 3.5, .NET Framework 4.0 and .NET Framework 4.5 but I still get the same error.

The web part's corresponding .ascx.g.cs file is empty.

The issue is similar to these unresolved items on Microsoft Connect

How can I overcome this error?

Could this issue have something to do with my dev environment (Windows 7 Enterprise, SP 2010 Foundation, Visual Studio 2012 installed along with VS 2010 SP1 with Power Tools)?

Am I the only one not able to build a sandboxed Visual Web Part solution targeting SP 2010 Foundation with VS 2012?

4 Answers 4


After some research we found out that the error has to do with the length of the contents of the User Control. Once you exceed the limit of 8256 characters the User Controls won’t be parsed anymore. Compare the two images. With the contents length of 8256 characters the ascx.g.cs file is still present in the solution.

enter image description here

Once you add another character to the file and save it, the ascx.g.cs file will disappear and the familiar error will appear if you try to build the project.

enter image description here




it should solve your issue :)


It looks like a common issue that is going around related to the resx and the fact it needs to be included in the build I have also found some other resources that have a workaround until microsoft fix's the issue:



  • I've had this issue in VS2012 as well, and it seemed that the solution (VS2010 SP1) won't help if you are using VS2012. I had to work around this by using VS2010 for that project instead of VS2012.. Commented Jan 22, 2013 at 23:51
  1. Is it a sandbox solution?

  2. Is the domain controller installed on the same server as SharePoint? If yes, then have a look here: http://jaliyaudagedara.blogspot.in/2011/06/debugging-sharepoint-sandbox-solutions.html

  3. Also another link which might be helpful to you: http://blog.mastykarz.nl/the-name-initializecontrol-does-not-exist-in-the-current-context-visual-web-part-sandboxed-bug-fix/

  • Yes, it is a sandbox solution. The domain controller is not installed on the same server as SharePoint. Even a very basic Visual Web Part sample with just a label doesn't build and throws the error mentioned. So as the content of the control is very less, the solution in third link does not apply. Could this issue have something to do with my dev environment (Windows 7 Enterprise, SP 2010 Foundation, Visual Studio 2012 installed along with VS 2010 SP1 with Power Tools)?
    – mvark
    Commented Jan 19, 2013 at 3:13
  • Yes most probably it is your Dev Environment. Can you try on a few other environments with different configurations? Also check whether the service account with which the sandbox service is running is in the farm administrators group. Also the sandbox service account needs to have db creator permissions on the content database. You can check this through SQL Server. Commented Jan 19, 2013 at 6:24

As suspected, the issue was with my dev environment which was on the Windows 7 OS. I was able to run a Visual Web Part just fine on Windows Server 2008 with SP 2010 Foundation and VS 2012.


In my case the g.cs file was missing and I have then create a new control on ascx page. I have added asp button control and add onclick event and I found that g.cs file has been created automatically and it is running now.

This is for Sand box solution as well as for On premise solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.