Category: Error

Sharepoint Exception: Trying to use an SPWeb object that has been closed or disposed and is no longer valid.

When I created sharepoint webpart and Used


using (SPSite site = new SPSite("http://Server:port/sites/Site/"))
{
using (SPWeb web = site.OpenWeb())
{
//Some Code Here.
}
}

It worked fine but before deploying I changed new SPSite(“http://Server:port/sites/Site/”) to SPContext.Current.Site and it started throwing the above exception on the Error Page but while debugging there was no Exception.

Weird issue and I don’t have any explaination for it but what helpd me solving the issue was the fact when we are passing Url to the SPSite it works fine.

So on the same lines I used SPContext.Current.Web.Url to fetch the Url of current siteand It worked like a charm.

So instead of above if we use


using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = site.OpenWeb())
{
//Some Code Here.
}
}

it works. 🙂

First time Error While working with Silverlight Pivot Viewer

Runtime Error in Silverlight Pivot Viewer

If you are working with Silverlight Pivot Viewer control for the first time and have created a basic Page using Pivot Viewer as explained here but still you are getting the Runtime error as shown below.

System.Windows.Markup.XamlParseException occurred
Message=Set property ‘System.Windows.FrameworkElement.Style’ threw an exception. [Line: 14 Position: 34]
LineNumber=14
LinePosition=34
StackTrace:
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at SilverlightPivotViewer.MainPage.InitializeComponent()
at SilverlightPivotViewer.MainPage..ctor()
InnerException: System.Windows.Markup.XamlParseException
Message=Element is already the child of another element. [Line: 0 Position: 0]
LineNumber=0
LinePosition=0
StackTrace:
at MS.Internal.XcpImports.CreateFromXaml(UnmanagedMemoryStream stream, String sourceAssemblyName, Boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers)
at System.Windows.Controls.Control.GetBuiltInStyle(IntPtr nativeTarget, IntPtr& nativeStyle)
InnerException:

Then the quick resolution for this is to install Latest Silverlight tool kit (which is Apr 2010 release)

For resolving this error Download Silverlight Toolkit from here.