Visual Studio Doesn’t Hit My Breakpoints!

Dieter Bremes' Blog

The bane of every developer: Visual Studio doesn’t hit your breakpoints! It usually happens when creating extensions for a program and there are two general reasons for this:

  • Visual Studio and the program to be extended load different versions of your extension
  • Visual Studio 2010 uses the wrong debugger

I’ll use SharePoint and a .dll file as an example but you can substitute “SharePoint” with “program to extend” and “.dll” with your type of extension.

Visual Studio and the Program to be Extended Load Different Versions of Your Extension

Use Process Explorer (see External References section) to check from where Visual Studio (process devenv.exe) and SharePoint (one of the w3wp.exe processes or the OWSTIMER.EXE process) load your .dll file. Chances are that the locations don’t match.

One problem I found was that SharePoint loaded the correct version of the .dll file from the GAC (C:WindowsassemblyGAC_MSIL…) but Visual Studio loaded it…

View original post 431 more words


C#: Add Object List as Test Data for the same Test Case in NUnit

Sometimes, it is required to define a couple of test data for one test case. In NUnit, “TestCaseSource” is the way to collect the test data for the same test case.

  1. Add annotation “TestCaseSource” before test case.
    [Test, TestCaseSource(typeof(TestDataFactory), "TestDataCollection")]
    public void TestMethod(TestData data) {}
  2. Define a “TestDataFactory” class, which includes static IEnumerable variable “TestDataCollection”.
    public class TestDataFactory
    public static IEnumerable TestDataCollection
    yield return new TestData {var1 =123,var2="test1"};
    yield return new TestData{var1 =456,var2 = "test2"};
  3. Define some test data as a class.

    public class TestData
    public int var1 { get; set; }
    public string var2 { get; set; }

C#: Call by reference or by type?

  • For the object with the basic type, e.g. int, string, etc. It is different with calling by value or by reference.
    int year = 10;
    t.SetYear(year); //year = 10;
    t.SetYearRef(ref year); // year changed in SetYearRef();
  • There is no concept of “call by reference” or “call by value” for List . It works like “call by reference”.
    List l = new List { "a", "b" };

    The values of l are changed in method.
  • The object is called also like “reference”.MySubClass has two variables, t1.year and t1.myList, the values will be changed in the method SetObject() like a reference.
    MySubClass t1 = new MySubClass (2015,new List{"a"});

Warning in Add-Migration of EF6 to create a new DataBase

When I use Code-First to create table in a blank Database (without table) in EF6 on SQL Server 2014 with following commands,

PM> Enable-Migrations (somethimes with "-EnableAutomaticMigrations")
PM> Add-Migration
PM> Update-DataBase

in the step “Add-Migration”, the following warning will be displaying always at first time.

“The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running ‘Add-Migration test_db’ again.”

After  Command “Update-Database”, the SQL script can be generated correctly but tables are not created in DB yet.

Re-run “Add-Migration” can solve the problem, but I have not quite understood the problem with SQL Server 2014 by creating tables in a blank DB.

Data Annotation or Fluent API

Data Annotation:

  • Simple for basic scenarios;
  • Integrates with MVC validation;
  • It may support more features in the next version of EF.

Fluent API:

  • Flexibility. Things with Data Annotation is possible with Fluent API. The reverse is not true.
  • Domain class always in separate section;
  • Support  more operations (e.g. advanced inheritance mappings, switching off cascading deletes, etc.)


Create a new Database with Code First

Use an existing Database with Code First

Configuring/Mapping Properties and Types with the Fluent API

Tips: Some information about local DB:

  • (localdb)\ProjectsV12 instance is created by SQL Server Data Tools (SSDT)
  • (localdb)\MSSQLLocalDB is the SQL Server 2014 LocalDB default instance name
  • (localdb)\v11.0 is the SQL Server 2012 LocalDB default instance name