I while back I installed an extension into Visual Studio called "Default Browser Switcher". It's a really neat tool that allows you to specify which browser to debug with when testing an ASP.NET application. In the past you had to right click an aspx file and choose "Browse With", then set your default.

Problem is that when working with MVC, you cannot do this (since there's no *.aspx files!). So I used to add a dummy aspx file and use that to choose my browser. Since then all was well, but recently I received the following message:

Beta Bits


Solution:

Goto: %localappdata%\Microsoft\VisualStudio\10.0\Extensions and delete the folder named: "Clarius Consulting", then re-download the extension and all should be well.

Hope this helps someone else if they've run into the same problem as I.

~ Steve

Been working on an MVC project and my templates were not generating. I first created my Model inside my "Models" folder, then did a quick compile. Next I went to the Views folder to get it created, right click and say "Add View" then I clicked the checkbox to create an edit page. What happened was the template would never seem to pull in my Model, it would just have the default header items, but the entire model was missing.

Scaffold Example

 My model was defined as follows:

public class LogOnModel

{

[Required]
[
Display(Name = "User name")]
public string UserName;

[Required]
[
DataType(DataType.Password)]
[
Display(Name = "Password")]
public string Password;[Display(Name = "Remember me?")]
public bool RememberMe;

}

See anything wrong with that? I couldn't figure out why each time I created my View and selected the option to create the "Edit" scaffold automatically, it would come up blank.

Turns out I'm missing my get / set methods on the Model class items.

Here's my code with the correct setup:

public class LogOnModel

{

[Required]
[
Display(Name = "User name")]
public string UserName { get; set; }

[Required]
[
DataType(DataType.Password)]
[
Display(Name = "Password")]
public string Password { get; set; }

[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }

}

 I hope that helps someone out, it's pretty simple when I look at it now, but that's always the case!

 ~ Steve

I've been working with Linq now for a while, but sometimes the simplest things get the best of you.  I was working with a new project where I had been using Linq all over the place. Everything was working, selecting rows, inserting logs, etc, etc, however, one portion was not. I was attempting to get a row from the database, changing a value then saving back that row. 

Here's an example:

DataContext db = new DataContext(pConnectionString);

MyRow pRow = db.MyRows.SingleOrDefault(p => p.pkID == ppkID);

pRow.column = DateTime.Now;

db.SubmitChanges();

Looked good to me.  So I did some digging through my database and found that for some reason I did not set a Primary Key on the table I was trying to update. There aren't any exceptions or errors thrown so it was a little more hidden.

So to summarize, make sure you set your primary keys when using linq, even if it needs to be a surrogate key!

~ Steve

 

 

I have been having some performance problems with Visual Studio 2008 web applications.  I see a delay when working on aspx pages.  Just typing, adding controls, or switching between Design to Code view (or even Split) would spike the cpu a little and freeze up for 10-15 seconds.

I found this forum post which fixed my issue completely. It seems to be related to the HTML validation.

Here's the change which worked for me:

Tools --> Options --> Text Editor --> HTML --> Validation and clear the 'Show errors' checkbox to completely disable any HTML validation at all. 

 

 ~ Steve

We have been adopting Linq slowly but surely and have run into some issues we never had to deal with in the past.  Currently I use DataSets in VS2005 for everything.  These are nice since they return DataTables easily and allow updates / inserts / etc without issue. 

When we dove into Linq and had to return a DataTable for the first time we were stuck.  Looking through examples & searching online did not return much. I did find an example by Kevin Goff in CoDe Magazine which outlined 13 tips for Linq.  This worked great except I had some issues with null datatypes. Those issues should be fixed in the sample below.

The following code outlines a quick way using Linq to query a database and return the results to a DataTable.

Here is my newly created class:

static public class ConvertDataTable

{

public static DataTable ToADOTable<T>(this IEnumerable<T> varlist, CreateRowDelegate<T> fn)

{

DataTable dtReturn = new DataTable();

// Could add a check to verify that there is an element 0

T TopRec = varlist.ElementAt(0);

// Use reflection to get property names, to create table

// column names

PropertyInfo[] oProps =

((Type)TopRec.GetType()).GetProperties();

foreach (PropertyInfo pi in oProps)

{

Type colType = pi.PropertyType;if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))

{

colType = colType.GetGenericArguments()[0];

}

dtReturn.Columns.Add(
new DataColumn(pi.Name, colType));

}

foreach (T rec in varlist)

{

DataRow dr = dtReturn.NewRow();foreach (PropertyInfo pi in oProps)
{
   dr[pi.Name] = pi.GetValue(rec,
null) == null ? DBNull.Value : pi.GetValue(rec, null);
}

dtReturn.Rows.Add(dr);

}

return (dtReturn);

}

public delegate object[] CreateRowDelegate<T>(T t);

}

Here is the usage in code:

LData.MyDataContext db = new LData.MyDataContext();
var query = from p in db.Extensions
w
here p.DepartmentNumber == "412"select p;

DataTable dt = query.ToADOTable(rec => new object[] { query });

 

Hope this helps someone else out.

~ Steve

 

I responsed to Joe's post on getting a new blog setup on asp.net here we are.

I work for a Software company 20 minutes outside of Pittsburgh, PA.  We develop communications based software which integrates into systems like AVAYA, & Cisco.  We heavily use ASP.NET, SQL 2005, Reporting Services, and Winforms in a day-to-day operations in the software we sell.  We also do a fair amount of .NET remoting.

More details to come!

~ Steve

More Posts