Error : Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Hello All

I have created list in my SharePoint Site. And my requirement is to get data from SharePoint Site.

Here is my Simple code:

using (SPSite site = new SPSite(siteurl))
{
using (SPWeb web = site.OpenWeb())
{
SPList lstUsers = web.Lists["SiteUsers"];
SPQuery Qry = new SPQuery();
Qry.Query = "<Where><Eq><FieldRef Name='IsActive' /><Value Type='Boolean'>0</Value></Eq></Where>";
DataTable dtUsers = lstUsers.GetItems(Qry).GetDataTable();
if (dtUsers != null && dtUsers.Rows.Count > 0)
{
//Bind the data
}
}
}
}


When I am trying to get data from the SharePoint List, I got this Error Message:

Error : ‘Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack’

After doing some research I found solution. I need to change the Authentication mode in configuration file from ‘Form’ to ‘Windows’.

Solution : <authentication mode="Forms"> replace with <authentication mode="Windows">

That’s it, Problem Solved.
It works fine for me, Hope it helps

Forms Authentication in SharePoint

Hello All,


Here is the good article which explain how to extend FBA site from Window Authenticate site and How to configure Forms Authentication in SharePoint Site.

This article provides detailed description of how to configure Forms Authentication with SharePoint site with code.

Thanks.

Creating Custom Site Definition in WSS / MOSS

Site Definition: It is foundation on which all sites and templates are built. Inside each site definition sub directory the aspx pages for the various WebPages and lists that make up site definition are stored.

The Site Definition folder is located at ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates’ on the SharePoint Server.
Each Site Definition has its own sub directory under this folder.

Steps to Create Custom Site Definition:

1. Navigate to ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates’

2. Copy the STS directory and paste it to back in same directory, Rename the Copy STS directory to DEMOTEST.

3. Navigate to ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033’

4. Follow the same procedures as you follow in step -2 and step-3 for STS directory.

5. Navigate to ‘C:\Program Files\Common Files\Microsoft Shared\web server
extensions\12\TEMPLATE\1033\XML’

6. Copy the WEBTEMP.XML file and paste it in to same directory and rename it ‘DEMOTESTWEBTEMP.XML’.

7. Put the following lines into the DEMOTESTWEBTEMP.XML

<?xml version="1.0" encoding="utf-8" ?>
<!-- _lcid="1033" _version="12.0.4017" _dal="1" -->
<!-- _LocalBinding -->

<Templates xmlns:ows="Microsoft SharePoint">

<Template Name="DEMOTEST" ID="10001">

<Configuration ID="0" Title="Sample Site" Hidden="FALSE" ImageUrl="/_layouts/images/stsprev.png" Description="This sample template creates a site for teams to create, organize, and share information quickly and easily. It includes a Document Library, and basic lists such as Announcements, Calendar, Contacts, and Quick Links." DisplayCategory="Custom Site Definitions" > </Configuration>

<Configuration ID="1" Title="Sample Blank Site" Hidden="FALSE" ImageUrl="/_layouts/images/stsprev.png" Description="This sample template creates a Windows SharePoint Services-enabled Web site with a blank home page. You can use a Windows SharePoint Services-compatible Web page editor to add interactive lists or any other Windows SharePoint Services features." DisplayCategory="Custom Site Definitions" > </Configuration>

<Configuration ID="2" Title="Sample Document Workspace" Hidden="FALSE" ImageUrl="/_layouts/images/dwsprev.png" Description="This sample template creates a site for colleagues to work together on documents. It provides a document library for storing the primary document and supporting files, a Task list for assigning to-do items, and a Links list for resources related to the document." DisplayCategory="Custom Site Definitions" > </Configuration>

</Template>

</Templates>

8. Reset IIS

9. Go to SharePoint Central AdministratoràCreate Site Collection. In TemplateSelection
Section, the new tab named ‘Custom Site Definitions’ available.

That’s it...Hope this helps