I am in the process of creating a method that will generate a list of web parts on a specific page. I have found that using the SPLimitedWebPartManager class will help me with the task. When I use the class i receive an error saying The type or namespace name 'SPLimitedWebPartManager' does not exist. So, I add the Namespace for the class Microsoft.SharePoint.WebPartPages. Doing this causing an ambiguous error on my main class public partial class VisualWebPart1 : WebPart. The WebPart is the bit that receives the error. When i comment out the Namespace System.Web.UI.WebControls.WebParts the ambiguous error goes away. Now, when i reload my page i get an error saying <style xmlns=''> was not expected..

Now, my question(s).

Why can't I use both namespaces? I realize i can't because of the ambiguous error. but must be a good explanation

Why am I receiving this <style xmlns=''> was not expected. error? Steps to remove it?

Is there one namespace that will take care of both classes and not give me the <style xmlns=''> was not expected. error?


You can use both namespaces, you just have to set up a way of disambiguating which WebPart class you are referring to when you refer to it.

One way of doing that would be to include the entire namespace when you refer to the WebPart class, i.e.:

public partial class VisualWebPart1 : System.Web.UI.WebControls.WebParts.WebPart

Another option, and the first thing that came to my head when I read your question, is to set up namespace aliases:

using SysUI = System.Web.UI.WebControls.WebParts;
public partial class VisualWebPart1 : SysUI.WebPart

The main idea is that you just have to be specific and set up disambiguation.

Here's some info on namespaces on MSDN.

As far as the other error, I don't know what's going on there.

| improve this answer | |
  • Should have thought of giving them an alias earlier. I will have to research that error I received, it seems to be something with XML. – IE5Master Jul 18 '16 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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