Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Error in XML Document (1,40)

  Asked By: Ryan    Date: Dec 16    Category: Sharepoint    Views: 1358

I received this error when trying to add my current project to a fresh portal. Every time I went to Add Web Parts and dragged/dropped the part into a zone, the Error in XML Document (1,40) message would appear in the side menu in red letters. Well, after much digging, I have figured out why it does this. It is caused by an unhandled exception in a constructor. I had missed a few spots in my code when I went back and refactored my error handling, and so the web part didn’t gracefully handle empty tables. Fixed the problem (and added a general try/catch to my constructor) and I was able to add the web part back in.

To test: Create a new web part, verify it is safe and working, then add the following:

VB.Net

Public Sub New()

Throw New Exception()

End Sub

C#:

public YourClassName()

{

throw new Exception();

}

Rebuild/deploy. The web part that was already added in will display a ‘Cannot desieralize’ error message. If you try to add it in again, you will get the XML Document error. To fix change the constructor to this:

VB.Net

Public Sub New()

Try

Throw New Exception()

Catch err As Exception

End Try

End Sub



C#

public YourClassName()

{

try

{

throw new Exception();

}

catch

{

}

}

Rebuid/deploy. Error will be fixed.

Please let me know if this doesn’t happen. It has so far for me with all my code.

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Error in XML Document (1,40) Or get search suggestion and latest updates.




Tagged: