Software Architecture Designer

Tuesday, March 5, 2013

Only parameterless constructors and initializers are supported in LINQ to Entities

This is the error that usually come up when you try to run a LINQ Query and return an object out of this QUERY.

Something like the below example:
var query = (from c in ctx.Clients
                         where l.UserID == userid
                         select new ClientList(c.ClientFirstName, c.ClientLastName,  c.ClientEmail)
                          ).ToList();
Well the Error is Pretty much self explanatory. No Parameterized constructors are allowed for LINQ to Entities...

Workaround ?
Change your Query to something like this..
var query = (from c in ctx.Clients            
                         where l.UserID == userid
                         select new ClientList{ClientFirstName= c.ClientFirstName, ClientLastName= c.ClientLastName, ClientEmail= c.ClientEmail}
                          ).ToList();



Thursday, December 20, 2012

JQuery Autocomplete "Internal Server Error"

Hello,

This is something that is very common for all of us to encounter. I encountered this N no. of times during my work and most of the times for all new reasons then before.

Here are a few things that you could look out for:

This error clearly mentions that it is a "Server Error" which means we could not get a proper response back from the server. So chk for these....

1. Make sure you are calling to the correct WebService and correct Method of the webservice.

2. The make sure you pass the correct name of the parameter as requested by the WebMethod.

3. The method should be marked as WebMethod in the WebService.

4. Debug through your Webmethod to see if it fails somewhere.

5. If you are not at all getting the Webmethod to hit (Which was precisely my case), then look for the
    [System.Web.Script.Services.ScriptService]
tag above your asmx.

To allow this Web Service to be called from script, using ASP.NET AJAX, you need to have the  following line on top of your WebService declaration

    [System.Web.Script.Services.ScriptService] 

Hope this helps... 

Sunday, October 28, 2012

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "AjaxControlToolkit.Properties.Resources.NET4.resources" was correctly embedded or linked into assembly "AjaxControlToolkit" at compile time, or that all the satellite assemblies required are loadable and fully signed.

Thats the Error: 

Reason:  AjaxControlToolkit’s control load reference refers to the base System.Web.UI.Control method which is present as a part of the ASP.NET AJAX Libraries and those libraries are referenced only when the ScriptManager is referenced in the page.


Solution: - Add a ScriptManager control to your page.


<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

Friday, August 10, 2012

The Controls collection cannot be modified because the control contains code blocks




The above error is very common when we try to access server side values on client side using Javascript.

The solution to this problem is simple.

1. The Server Tag to get values of any variable or property is as below
var propVal = '<%= ServerSideProperty %>';
This is also particulartly helpful when accessing Web.Config values in Javascript as:
var configVal = '<%= ConfigurationManager.AppSettings["ConfigPropName"] %>';

This would raise the above error. And the solution to it, "Replace the "=" with a "#""
So now your properties would be something like
var propVal = '<%= ServerSideProperty %>';
var configVal = '<%= ConfigurationManager.AppSettings["ConfigPropName"] %>';

Now, if you are accessing any Data bound values, such as in a grid view etc, then this would work good for you but for accessing properties or other variables, here is another small piece of code required.

On Page Load, we need to Bind these together using
Page.Header.DataBind();
Unless you do this, you would not be able to access these values and they would return a BLANK.
 

Wednesday, August 10, 2011

Failed to generate a user instance of SQL Server

OK.

I know the updates have been real slow... Its more like I am a touch too busy to go on and update the blog. But.... lets pick it up once again and try to revive it...

Here is the one for today !! I was working on a small VS2010 WPF Application when I came across this weird error.

Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.

Searched a bit around the net and found a lot of solutions to it.

The most un-convincing one did the trick.

Goto the below location in WIndows Explorer

C:\Users\\AppData\Local\Microsoft\Microsoft SQL Server Data

Delete the folder SQLExpress.

NJoy !!

Tuesday, October 19, 2010

Unable to cast object of type System.Data.DataRowView to type System.IConvertible

Wow...

Long time.. A lot of distractions. I have been interested in a lot new things. With Windows Phone, Robotics coming into picture, the hobbies and pass-times all changed around.

But to get back on the track.. Here is a very small piece of information that I am sure would help a lot of people.

I encountered the above error while working with a Combobox in a Windows Application.

This would come up every time the form loads and the the SelectedValue of the combobox was selected.

This normally would occur to comboboxes, which are databound.

So here is the problem and the solution.

This is how we usually bind the combobox to data

cboBox.DataSource = data_set.Tables["table_name"].DefaultView;

cboBox.DisplayMember = "field_name";

cboBox.ValueMember = "field_id";


Instead, to resolve this issue all we need to do is first specify the DisplayMember and ValueMember and then Bind.


cboBox.DisplayMember = "field_name";

cboBox.ValueMember = "field_id";

cboBox.DataSource = data_set.Tables["table_name"].DefaultView;