'Error when using a conditional breakpoint on System.Type

This is the function:

public void Init(System.Type Type) {
    this.Type = Type;
    BuildFieldAttributes();
    BuildDataColumns(FieldAttributes);
}

I've set a breakpoint on the first line (this.Type = Type) and I want to break when Type.FullName == "Malt.Organisation" so that's what I've entered in as the condition.

However the following error is displayed when the line is hit:

The condition for a breakpoint failed to execute. The condition was 'Type.FullName == "Malt.Organisation"'. The error returned was 'Inspecting the state of an object in the debuggee of type System.Type is not supported in this context.'

What (obvious) thing am I doing wrong?

PS. A workaround is to add this to the code:

if (Type.FullName == "Malt.Organisation") System.Diagnostics.Debugger.Break();


Solution 1:[1]

You say that Type.FullName == "Malt.Organisation" causes it to break, have you tried this.Type.FullName == "Malt.Organisation"?

Another possibility, does the debugger think you are trying to invoke a static method with having the variable named Type like its class name? Does renaming the Type variable to something else fix it?

Solution 2:[2]

I ran into this but when testing for IsInterface in a Web Application. Instead of enabling extra features in the debugger, I simply cheated.

bool blnIsInterface = tType.IsInterface;

//Insert breakpoint here...
if(blnIsInterface)
{
    ...
}

So in your case your could do something like

public void Init(System.Type Type) {
    bool blnBreak = Type.FullName == "Malt.Organisation";
    //insert breakpoint of blnBreak == true
    this.Type = Type;
    BuildFieldAttributes();
    BuildDataColumns(FieldAttributes);
}

It's a bit cumbersome but at least you won't have to worry about performance hits and enabling Native code debugging doesn't seem to be an option in Web Applications.

Solution 3:[3]

I'm not sure about "Use Managed Compatibility Mode" solution described here - did not help me, but in my own case Project > Properties > Debug > Enable Native code debugging - must be unchecked.

Why - no clue currently.

Was using .net 4.5, vs2015, console application.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel Stone
Solution 2 Wes Hanney
Solution 3 TarmoPikaro