1

It seems like the DebuggerDisplayAttribute is not having any effect in Visual Studio 2017 (15.9.4) with Resharper 2018.2.3.

  • Placing the attribute in AssemblyInfo.cs, or in Program.cs, has no discernible effect.
  • I am targeting .Net Framework 4.7.2. Changing the framework version also has no discernible effect.
  • I have verified that "Show raw structure of objects in variables windows" is unchecked in Tools -> Options -> Debugging -> General. I even checked it, closed VS, reopened VS, and unchecked it, just to be sure. No effect.

enter image description here

  • Placing the attribute on a custom class does have an effect. It seems that the attribute is only being ignored when at the assembly level.
  • This works as expected in VS 2015 (with the same version of Resharper).
  • Starting VS 2017 in safe mode (using devenv.exe /safemode) has no effect.
  • Updating VS 15.9.4 -> 15.9.7 has no effect.

Here is a very basic console application. Despite the attribute, the dt variable appears as {2/14/2019 10:35:38 AM} in my watch window.
enter image description here

[assembly: DebuggerDisplay("Foo", Target = typeof(DateTime))]

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var dt = DateTime.Now;
            Debugger.Break();
        }
    }
}

If I use ILSpy to decompile my console application, I can see these attributes applied:

[assembly: Debuggable(
    DebuggableAttribute.DebuggingModes.Default | 
    DebuggableAttribute.DebuggingModes.DisableOptimizations | 
    DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | 
    DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: DebuggerDisplay("Foo", Target = typeof(DateTime))]

Why isn't the attribute doing anything? How do I even begin to debug this?

Edit: Complete source files as requested.

ConsoleApp1.csproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{EBBA72C6-5087-4D8E-9F2C-B968ABD59EAA}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>ConsoleApp1</RootNamespace>
    <AssemblyName>ConsoleApp1</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
</configuration>

AssemblyInfo.cs:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("ConsoleApp1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConsoleApp1")]
[assembly: AssemblyCopyright("Copyright ©  2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("ebba72c6-5087-4d8e-9f2c-b968abd59eaa")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
  • I _think_ the problem is that your target type (`DateTime`) is defined in a different assembly (which kind of makes sense). – Vlad Feb 14 '19 at 16:54
  • But: https://stackoverflow.com/a/34697240/276994 – Vlad Feb 14 '19 at 16:55
  • Actually, I've tested and setting the attribute on assembly level even for `int` works. VS 2017 15.9.7. – Vlad Feb 14 '19 at 16:56
  • @Vlad That seems to be the deciding factor, though it's supposed to work with types from other assemblies. I've done this before, which is why this is perplexing. Disabling Resharper had no discernible effect. I'm trying VS2015 now. –  Feb 14 '19 at 16:56
  • 1
    Oh, I don't have Resharper installed. Maybe that's the difference? – Vlad Feb 14 '19 at 16:58
  • Strange. Is it possible to deactivate Resharper temporarily? – Vlad Feb 14 '19 at 17:00
  • @Vlad Yes. I tried [disabling it](https://resharper-support.jetbrains.com/hc/en-us/articles/206546999-How-can-I-temporary-disable-turn-off-ReSharper-). I closed and reopened VS. –  Feb 14 '19 at 17:02
  • 1
    Well, that's strange. Could you please upload the test application source folder somewhere? I cannot reproduce the issue with the source code you posted. – Vlad Feb 14 '19 at 17:07
  • @Vlad I can't upload files anywhere due to corporate firewalls, but I updated the question with the requested content. I also updated Visual Studio 15.9.4 -> 15.9.7, to match your version. No change. –  Feb 14 '19 at 17:32
  • I tried your project, but it seems to work :-/ https://i.stack.imgur.com/ndWlK.png – Vlad Feb 14 '19 at 17:43
  • @Vlad I guess that makes the most likely explanation user error? The screenshots I added were taken during safe mode. Every extension is disabled except "Developer Analytics Tools". I don't know. Thanks for taking the time. It is appreciated. –  Feb 14 '19 at 17:46
  • Try https://www.matteopozzani.com/visual-studio-cache-cleanup. Also you can try create new Windows user account and repeat you problem. – Yarl Feb 14 '19 at 17:46
  • It seems that your installation of VS is somehow corrupt. BTW, maybe complete uninstallation of Resharper would help? (I remember one of the VS plugins was causing bugs even if disabled.) – Vlad Feb 14 '19 at 17:50
  • @Vlad Doing a repair of my VS installation did indeed fix this. If you add an answer saying to do a repair, I'll accept it as the answer. –  Feb 14 '19 at 20:16
  • @Amy: Glad that it helped! So the investigation can be declared finished. – Vlad Feb 14 '19 at 20:17

1 Answers1

2

I've built the project from the sources you provided, and can't reproduce the problem:

debugger display

This means that on the fresh installation of VS 2017 the feature must work. So your installation of Visual Studio must be somehow corrupt.

After investigation in comments I'd suggest to do an installation repair, it should fix the problems.

Vlad
  • 35,022
  • 6
  • 77
  • 199
  • 1
    I'd like to add that reinstalling my extensions, including Resharper, didn't make this happen again. Not sure what it was, exactly, but repairing my VS installation did the trick. –  Feb 15 '19 at 02:44