Unable to create new MVC project in Visual Studio 2013

Posted by on Jun 27, 2014 in Asp.net, MVC

I recently had a problem in Visual Studio 2013 whereby I couldn’t create a new MVC project. When I tried, an empty solution would be created and a dialog box would be shown with the following: System cannot find the file specified (0x80070002) After a bit of digging about, it appears this occurs when there is an issue with Nuget – either a faulty installation or its somehow been corrupted. Thankfully fixing it was as simple as you’d imagine. In visual Studio 2013 go to: Tools=> Extensions and Updates => Installed => Nuget Package Manager for Visual Studio 2013 => Uninstall Close VS when you’re asked to restart it and then download a fresh copy from here by ruinning the VSIX file: Nuget from the Visual Studio Gallery Once the installation is complete, it should be working again… Hope that...

Read More »

Getting started with OWIN

Posted by on Sep 29, 2013 in Asp.net

OWIN If you’re a developer in the web space, especially focusing or involved with the Microsoft stack, you’ve no doubt heard a lot about OWIN lately. OWIN, or Open Web Interface for .NET is an open-source initiative somewhat inspired by the Rack project on the Ruby platform and the increasingly popular Node.js movement. Like Rack, OWIN sets out to provide a flexible, lightweight middleware between web servers and the underlying framework components. OWIN also delivers on its promise of portability and modularity meaning applications written on top of OWIN are server and potentially even OS agnostic. If, like me, you’ve created a simple web server using Node.js in a dozen lines of code, then self-hosted via a command line, you’ve no doubt been slightly envious as the elegance and autonomy of that solution compared to the tightly coupled MS/IIS/asp.net stack. However, you also soon probably found that a lot of the goodness asp.net gives you ‘out of the box’ goes a long way, and with OWIN, developers can potentially have the best of both worlds. Katana If you’re a Microsoft web developer then for every OWIN you’ve probably heard two Katana’s. Katana is Microsofts (also open-source) implementation of the OWIN specification. It can be found on Codeplex and is unsurprisingly geared to provision for the Microsoft hosts and frameworks. An Example Lets put this into an example. Using Visual Studio, click File, New Project and select Console App Once that’s completed, we need to grab a few packages from NuGet. From the package manager console (or via the GUI if you’d prefer), obtain the following packages: install-package Microsoft.Owin.Hosting –IncludePreRelease install-package Microsoft.Owin.Host.HttpListener –IncludePreRelease Once the process completes you’ll notice a few dependencies have been imported for you via the magic of NuGet dependency management: Now your app is good to go. It’s quite basic: C# using Microsoft.Owin.Hosting; using System; namespace Owin.ConsoleApp { class Program { static void Main(string[] args) { string uri = "http://localhost:8001"; using (WebApp.Start<StartUp>(uri)) { Console.WriteLine("App started"); Console.ReadKey(); Console.WriteLine("App stopping..."); } } } } 1234567891011121314151617181920 using Microsoft.Owin.Hosting;using System; namespace Owin.ConsoleApp{    class Program    {        static void Main(string[] args)        {            string uri = "http://localhost:8001";            using (WebApp.Start<StartUp>(uri))            {                Console.WriteLine("App started");                Console.ReadKey();                Console.WriteLine("App stopping...");            }        }    }} The static WebApp class has a generic Start method which takes in a URL on which to listen and a TStartup parameter which is a class that defines our configuration for the application. As per the above, create a new class inside the project called Startup.cs as follows: C# namespace Owin.ConsoleApp { class StartUp { public void Configuration(IAppBuilder app) { app.Run(ctx => { ctx.Response.ContentType = "text/plain"; return ctx.Response.WriteAsync("Helo from OWIN"); }); } } } 12345678910111213141516 namespace Owin.ConsoleApp{    class StartUp    {         public void Configuration(IAppBuilder app)        {            app.Run(ctx =>            {                ctx.Response.ContentType = "text/plain";                return ctx.Response.WriteAsync("Helo from OWIN");            });        }     }} Everything should compile just fine – hit F5 to start the app. A console window should appear telling you the app has started. Next, just open your browser and go to the Uri specified in the app (in this...

Read More »