Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers 3

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

http://blog.mastykarz.nl/the-name-initializecontrol-does-not-exist-in-the-current-context-visual-web-part-sandboxed-bug-fix/

and

http://stackoverflow.com/questions/11233418/sand-boxed-visual-webpart

it should solve your issue :)

EDIT

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:

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/af139e08-4d64-4685-b1d8-b3e03a9b748d

http://connect.microsoft.com/VisualStudio/feedback/details/776185/localization-of-a-sharepoint-visual-web-part-the-name-initializecontrol-does-not-exist-in-the-current-context

share|improve this answer
    
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.. –  marcus.greasly Jan 22 '13 at 23:51
add comment
  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/

share|improve this answer
    
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 Jan 19 '13 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. –  Vardhaman Deshpande Jan 19 '13 at 6:24
add comment
up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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