title: C# Source Generator - warning CS8032: An instance of analyzer cannot be created
body: <p>I'm trying to build a Source Generator. Right now, just the most basic static method that returns &quot;Hello World&quot;.</p>
  <p>The generator project builds, but the generated code is not available, the debugger never starts, and the build output shows</p>
  <blockquote>
  <p>CSC : warning CS8032: An instance of analyzer Generator.StaticPropertyEnum.helloWorld cannot be created from ...\bin\Debug\net5.0\Generator.StaticPropertyEnum.dll : Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified..</p>
  </blockquote>
  <h3>Examples I'm referencing</h3>
  <ul>
  <li><a href="https://github.com/dotnet/roslyn-sdk/blob/master/samples/CSharp/SourceGenerators/SourceGeneratorSamples/SourceGeneratorSamples.csproj" rel="noreferrer">Roslyn Team Generator Sample Project</a></li>
  <li><a href="https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.cookbook.md" rel="noreferrer">Roslyn Team Generator Cookbook</a></li>
  <li><a href="https://github.com/diegofrata/Generator.Equals" rel="noreferrer">Generator.Equals Project</a></li>
  <li><a href="https://nicksnettravels.builttoroam.com/debug-code-gen/" rel="noreferrer">How To Debug C# 9 Source Generators</a></li>
  </ul>
  <h3>I've tried</h3>
  <ul>
  <li>changing the TargetFramework and LanguageVersion of both the generator and test projects</li>
  <li>referencing many version of the analyzer libraries <code>Microsoft.CodeAnalysis.CSharp</code> and <code>Microsoft.CodeAnalysis.Analyzers</code></li>
  <li>referencing an explicit version of <code>Microsoft.Net.Compilers.Toolset</code></li>
  <li>Adding an explicit reference to the NetStandard library</li>
  <li>starting from scratch with an analyzer project template</li>
  <li>looking for a generator project template (but didn't find one)</li>
  </ul>
  <h3>Versions</h3>
  <p>Visual Studio: version 16.8.3<br />
  .NET SDK: 5.0.101</p>
  <h3>Code</h3>
  <p>Generator.csproj</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;net5.0&lt;/TargetFramework&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include=&quot;Microsoft.CodeAnalysis.CSharp&quot; Version=&quot;3.9.0-2.final&quot; PrivateAssets=&quot;all&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.CodeAnalysis.Analyzers&quot; Version=&quot;3.0.0&quot; PrivateAssets=&quot;all&quot; /&gt;
    &lt;/ItemGroup&gt;
   
  &lt;/Project&gt;
  </code></pre>
  <p>Test csproj</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;
  
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;net5.0&lt;/TargetFramework&gt;
  
      &lt;IsPackable&gt;false&lt;/IsPackable&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include=&quot;Microsoft.NET.Test.Sdk&quot; Version=&quot;16.7.1&quot; /&gt;
      &lt;PackageReference Include=&quot;xunit&quot; Version=&quot;2.4.1&quot; /&gt;
      &lt;PackageReference Include=&quot;xunit.runner.visualstudio&quot; Version=&quot;2.4.3&quot;&gt;
        &lt;IncludeAssets&gt;runtime; build; native; contentfiles; analyzers; buildtransitive&lt;/IncludeAssets&gt;
        &lt;PrivateAssets&gt;all&lt;/PrivateAssets&gt;
      &lt;/PackageReference&gt;
      &lt;PackageReference Include=&quot;coverlet.collector&quot; Version=&quot;1.3.0&quot;&gt;
        &lt;IncludeAssets&gt;runtime; build; native; contentfiles; analyzers; buildtransitive&lt;/IncludeAssets&gt;
        &lt;PrivateAssets&gt;all&lt;/PrivateAssets&gt;
      &lt;/PackageReference&gt;
    &lt;/ItemGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;ProjectReference Include=&quot;..\Generator.StaticPropertyEnum\Generator.StaticPropertyEnum.csproj&quot;  OutputItemType=&quot;Analyzer&quot; ReferenceOutputAssembly=&quot;false&quot;/&gt;
    &lt;/ItemGroup&gt;
  
  &lt;/Project&gt;
  </code></pre>
  <p>Generator</p>
  <pre class="lang-cs prettyprint-override"><code>    [Generator]
      public class helloWorld : ISourceGenerator
      {
          public void Execute(GeneratorExecutionContext context)
          {
  
  
              context.AddSource(&quot;HelloWorld-generated.cs&quot;, @&quot;
              using System;
              namespace HelloWorld
              {
                  public static class Hello
                  {
                      public static string SayHello() {
                          return &quot;&quot;HelloWorld&quot;&quot;;
                      }
                  }
              }&quot;);
          }
  
          public void Initialize(GeneratorInitializationContext context)
          {
  #if DEBUG
              if(!Debugger.IsAttached) Debugger.Launch();
  #endif
          }
      }
  </code></pre>