Category Archives: .NET

Visual Studio Won’t Open CSHTML Files

I had an issue one day where Visual Studio would not open my CSHTML files.  It would give me the following error.

The operation could not be completed.  Invalid pointer.

So naturally I took to Bing.  I eventually found the work around on StackOverFlow.

The fix for me was not the question’s accepted answer but one further down.  I deleted the contents in the %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache folder.

After that I never had this issue again.

Advertisements

Change Login Using Windows Authentication

Recently I had a need to allow users to change their login on an MVC site that used Windows authentication.  Of course we did not want the user to log out of their machine to do it.  The trick of course involved sending a 401 response, but how to do that and not get stuck in an endless loop.

The 401 Loop

It seemed simple enough, in fact too simple.  You just return a 401 challenge and have them move on to their previous page.  The 401 response is what presents the user with the Windows login popup.  In reality the 401 response acts like a redirect on itself, so you get two page loads and it forgets any variables you set.

Well that simply would not do. Read the rest of this entry

The Magic of Config Transformations

Fog, trees, and a lightWe have all used the magic of the Web.config transformations.  This is when we have our Web.config and connected to that is a version that does some work for release and one for debug; Web.Release.config and Web.Debug.config.  These are a great way to automatically have the correct target use the correct settings, especially connection strings.  Whether we use that or not and just leave it as something that looks cool is a different thing.

Did you know you can get this magic for your console applications as well?  I know, a web developer doing console apps?  As an enterprise one sometimes I find it is the best solution to some problems.  While it seems like a small thing I wished I had it in the console applications, I am happy to say that I have found it!

Read the rest of this entry

MVC 5 Placeholders, Prompts and Watermarks

I have noticed an issue with the MVC project in Visual Studio that I am sure others have seen too.  I say this because I have seen a number of solutions in StackOverflow and the ASP.Net forums.  This post is not about some great way to write your own extensions and automagically have the placeholder set in the HTML that is displayed to the user.  No, this is a much simpler method.

Just manually set the placeholder in your Razor syntax.  Chances are you are going in there anyway to tweak a few things instead of using what Visual Studio scaffolded for you.  I would still recommend setting the Prompt in your model though, I suspect that one day this will get fixed or you might actually need it to be automatically generated.  In fact I’d say that if you are writing your own Edit Templates you should include the small extra step to make it auto-generated.

If you are not doing that, here is the easiest fix or work around.

Read the rest of this entry

Collection Was Modified; Enumeraton Operation May Not Execute

Some Background

This was a very interesting bug for me to track down.  Initially it did not bubble up as the error that is in this title.  Initially it revealed itself as an out of bounds error when I tried to set IsOpen to true for a ContextMenu in a Silverlight project.  After lots of debugging I finally landed on this culprit.

The Task

The task I was trying to accomplish was pretty straight forward.  Given a List<T> remove any duplicate entries based on a given object.  Again, a straight forward task, or so I thought.


foreach(MyClass item in myListOfMyClass)
{
    if(item.SomeValue == objectOfMyClass.SomeValue)
    {
        myListOfMyClass.Remove(item);
    }
}

Read the rest of this entry

One Advantage of CodeWriter

A few weeks ago I posted about WebMatrix, which is a really nice light weight tool if you don’t want to fire up full Visual Studio.  I also indicated that I was using CodeWriter.  I have noticed one real advantage that CodeWriter has over WebMatrix.  I can run CodeWriter on my Surface 2.  My Surface 2 is not a pro version so I cannot run Visual Studio on it, and in turn I cannot run WebMatrix on it.

I will admit, I do not do a whole lot of dev work on my Surface 2.  In fact I normally write something up in CodeWriter so I can copy/paste it into OneNote or test something really small.

WebMatrix Collapsible Areas

Just a quick post about something I noticed in WebMatrix today.  It has some very cool collapsible areas, something I wish I had in Visual Studio 2013 Premium.  Take a look at the screenshot below, you’ll see what I am talking about.  Don’t worry about the code, it is just some basic JavaScript I threw together for this post.

WebMatrix Collapsible Areas

Hello WebMatrix

I have been using a tool for some PluralSight classes and currently a book I’m reading.  Normally I just jump into Visual Studio, but I will admit it is a bit over kill for just playing with HTML5/CSS3.  The PluralSight courses and Pro HTML5 with Visual Studio 2012 make use of WebMatrix.  In fact when I’m on my Windows 8.1 box I often use CodeWriter for the lightweight stuff, but the instructor and writer used WebMatrix so I followed suit.

Not only is WebMatrix quick and lightweight it has intellisense and even the ability to create your site in Azure if you take that option.  Like Visual Studio you can launch your site from the tool in the browser of your choice.  I have not explored everything WebMatrix can do, but I will definitely be using it for small minor things where Visual Studio would just be over kill.  At this time I really don’t see myself using it for real work, just for when I want to play/learn outside a real project.  For example I know you can create an MVC project in WebMatrix but I feel more comfortable in Visual Studio for the real projects.

So if you’re looking for something lightweight that feels like Visual Studio I highly suggest Web Matrix.

Breaking Into Your Lambda

I just learned something new today at Microsoft Virtual Academy.  Heck I almost always learn something new or even things I forgot at Microsoft Virtual Academy.  In this case I thought it was pretty neat.  We all use break points throughout our code, most of the time I just break on a line.  I just learned how to break into a Lambda expression.

Basically you click inside your Lambda expression and then press F9.  To show this I will create a quick class called Stuff.

    public class Stuff
    {
        public string Name { get; set; }
        public int Quantity { get; set; }
    }

In another area I am going to use this class to create a List<Stuff> and then use a Lambda on that list.

            List someStuff = new List()
                            {
                                new Stuff{Name = "Dice", Quantity = 2}, 
                                new Stuff{Name="Cards", Quantity = 52}, 
                                new Stuff{Name = "Tokens", Quantity = 20}
                            };

            var result = someStuff.Where(s => s.Name.Length > 4);

Next I click in my Lambda and press F9, below is a screenshot of the break point inside my Lambda.

Breaking Into Lambda

The WSDL Tool

The WSDL tool is a handy tool to generate a proxy class to consume a web service.  There is plenty of information out there about it, so I will not go into detail.  I will provide some links though.  One bit of advice is to add a new Environment Variable to your machine.  Here is an example, I named mine Path.

Variable name: Path

Variable value: %PATH%;C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin

You may need to verify that path on your actual machine, it should be the location of wsdl.exe.

Web Services Description Language Tool on MSDN.

Read the rest of this entry