Visual Studio

Error Building Class Library after Upgrading to Update 1 of VS2015

I recently updated to Update 1 of VS2015, using the Community Edition.  Shortly after, I began work on a new project and as I was setting the solution up, I created two class library projects in my solution.

My first compile of a relatively empty project devoid of most code.  I received hundreds of errors, all were similar to the following.

Unexpected character ' Trizbort-Tests C:\Users\Lautz\AppData\Local\Temp\.NETFramework,Version=v4.5.2.AssemblyAttributes.cs 1

I couldn’t find anyone with the same issue that had a solution, other than Uninstall VS and reinstall. Well that was not how I wanted to spend my evening.

Simple Solution

What seems to be a simple solution, browse to the file in question in the Appdata\temp folder and you’ll see at at least the file in question (my case .NETFramework,Version=4.5.2.AssemblyAttributes.cs).  I also had a few other similar files for different .NET versions.

Just delete them out of the temp folder.  When you recompile, they will get recreated, but I received no errors and all is working well.

C#, Code, Tips, Visual Studio

Visual Studio – Paste Special – JSON as Classes

This has been there since 2013 I believe, but I’m just now discovering it….wish I would have found it sooner as it’s an awesome feature.

Take a JSON (or XML as there is a Paste XML as Classes as well) like the following and copy it into the clipboard:

{
"People" :[{
    "First Name" : "Jason",
    "Last Name" : "Lautzenheiser", 
    "Address" : {
        "Street" : "1122 Main",
        "City" : "BigTown",
        "State" : "OH",
        "Zip" : 66554
    },
    "Phones" : [{
        "PhoneType" : "Home",
        "Number" : "330-555-7777"
      },
      {
        "PhoneType" : "Work",
        "Number" : "330-222-1111"
      }
    ]
  }]
}

Then under the Edit->Paste Special menu, there is an option for Paste JSON as Classes which will spit out the following code:

public class Rootobject
{
 public Person[] People { get; set; }
}

public class Person
{
 public string FirstName { get; set; }
 public string LastName { get; set; }
 public Address Address { get; set; }
 public Phone[] Phones { get; set; }
}

public class Address
{
 public string Street { get; set; }
 public string City { get; set; }
 public string State { get; set; }
 public int Zip { get; set; }
}

What a beautiful thing that is. I recently had to import and manipulate some JSON data for a report which was much more complex than this. Within minutes I had my object model setup and the JSON files being read in.

Small feature, but what a time saver.