Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Generator fails after updating to .NET 5 RC 1 with Method 'Initialize' missing #47699

Closed
trampster opened this issue Sep 15, 2020 · 15 comments

Comments

@trampster
Copy link

trampster commented Sep 15, 2020

Version Used:
5.0.100-rc.1.20452.10

Steps to Reproduce:

  1. Clone https://github.com/trampster/JsonSrcGen
  2. cd UnitTests
  3. dotnet-sdk.dotnet test

Expected Behavior:
Generates source code for json

Actual Behavior:

CSC : warning CS8032: An instance of analyzer JsonSrcGen.Generator.JsonGenerator cannot be created from /home/daniel/Work/JsonSrcGen/JsonSrcGen.Generator/bin/Debug/netstandard2.1/JsonSrcGen.Generator.dll : Method 'Initialize' in type 'JsonSrcGen.Generator.JsonGenerator' from assembly 'JsonSrcGen.Generator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.. [/home/daniel/Work/JsonSrcGen/UnitTests/UnitTests.csproj]

The Method 'Initialize' exists, and it hasn't changed since the code was working with the Previews.

@Youssef1313
Copy link
Member

Youssef1313 commented Sep 15, 2020

Try changing the Initialize method argument to GeneratorInitializationContext instead of InitializationContext.

See https://github.com/dotnet/roslyn/blob/4602d5d227f19c59665deb3583d7c2abfe8e8611/docs/features/source-generators.cookbook.md#breaking-changes

@trampster
Copy link
Author

trampster commented Sep 15, 2020

error CS0246: The type or namespace name 'GeneratorInitializationContext' could not be found (are you missing a using directive or an assembly reference?)

ISourceGenerator requires the old names, unless I also need to update my nuget references:

<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.6.0-3.20207.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.0.0-beta2.final" PrivateAssets="all" />

@b-straub
Copy link

see #47681

add the following key to your NuGet.config:
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
and update Microsoft.CodeAnalysis.CSharp to 3.8.0-4.20464.1.

@trampster
Copy link
Author

I don't have a package reference to Microsoft.CodeAnalysis.CSharp at all, or do you mean Microsoft.CodeAnalysis.CSharp.Workspaces?

@trampster
Copy link
Author

I updated my NuGet.config found in ~/.config/NuGet

And added a PackageReference

<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0-4.20464.1" PrivateAssets="all" />

But that just resulted in this error

/home/daniel/Work/JsonSrcGen/JsonSrcGen.Generator/JsonSrcGen.Generator.csproj : error NU1102: Unable to find package Microsoft.CodeAnalysis.CSharp with version (>= 3.8.0-4.20464.1) [/home/daniel/Work/JsonSrcGen/UnitTests/UnitTests.csproj]
/home/daniel/Work/JsonSrcGen/JsonSrcGen.Generator/JsonSrcGen.Generator.csproj : error NU1102: - Found 214 version(s) in https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json [ Nearest version: 3.7.0-3.20271.4 ] [/home/daniel/Work/JsonSrcGen/UnitTests/UnitTests.csproj]
/home/daniel/Work/JsonSrcGen/JsonSrcGen.Generator/JsonSrcGen.Generator.csproj : error NU1102: - Found 97 version(s) in nuget.org [ Nearest version: 3.8.0-2.final ] [/home/daniel/Work/JsonSrcGen/UnitTests/UnitTests.csproj]

@b-straub
Copy link

You must add the package source for the dotnet-tools preview packages.
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json
you can either do this in VS globally or by project or solution scope.
nuget.config reference

@b-straub
Copy link

I don't have a package reference to Microsoft.CodeAnalysis.CSharp at all, or do you mean Microsoft.CodeAnalysis.CSharp.Workspaces?

Both will work, Microsoft.CodeAnalysis.CSharp.Workspaces depends on Microsoft.CodeAnalysis.CSharp. Means updating Microsoft.CodeAnalysis.CSharp.Workspaces should do the trick as well.

@trampster
Copy link
Author

OK I have it working,

My generator .csproj has the following line:

<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json ;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>

Which had to be changed to:

<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json ;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>

Note the difference is dotnett5 -> dotnet-tools

Here is my working project for for anyone else who runs into this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>preview</LangVersion>
  </PropertyGroup>

  <PropertyGroup>
    <RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json ;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0-4.20464.1" PrivateAssets="all" />
    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.0.0" PrivateAssets="all" />
  </ItemGroup>

  <ItemGroup>
    <Compile Include="..\JsonSrcGen\StringBuilderExtension.cs" Link="StringBuilderExtension.cs" />
  </ItemGroup>

</Project>

See this commit for the full fix:
trampster/JsonSrcGen@b9bffda

I do have a question though, will this PackageSource be required in the .NET 5 full release or is just a work around to a temporary problem?

@jasonmalinowski
Copy link
Member

@chsienki Do we have public packages now with the changed APIs that people can reference?

@chsienki
Copy link
Member

We're just waiting on the 16.8p3 packages to be released. We're in a slightly odd situation where a few things are out of sync :/

@chsienki
Copy link
Member

Version 3.8.0-3.final is now available on the public feeds https://www.nuget.org/packages/Microsoft.CodeAnalysis/3.8.0-3.final

@chsienki
Copy link
Member

chsienki commented Sep 17, 2020

Closing this, as it should be resolved with the public packages. Please let us know if you're not seeing the expected resolution.

@glennawatson
Copy link

The public packages have some warnings

1>C:\Users\Glenn\source\repos\ReactiveMarbles.ObservableEvents\ReactiveMarbles.ObservableEvents.SourceGenerator\ReactiveMarbles.ObservableEvents.SourceGenerator.csproj : warning NU1603: Microsoft.CodeAnalysis.Common 3.8.0-3.final depends on System.Collections.Immutable (>= 5.0.0-preview.8.20371.14) but System.Collections.Immutable 5.0.0-preview.8.20371.14 was not found. An approximate best match of System.Collections.Immutable 5.0.0-preview.8.20407.11 was resolved.
1>C:\Users\Glenn\source\repos\ReactiveMarbles.ObservableEvents\ReactiveMarbles.ObservableEvents.SourceGenerator\ReactiveMarbles.ObservableEvents.SourceGenerator.csproj : warning NU1603: Microsoft.CodeAnalysis.Common 3.8.0-3.final depends on System.Reflection.Metadata (>= 5.0.0-preview.8.20371.14) but System.Reflection.Metadata 5.0.0-preview.8.20371.14 was not found. An approximate best match of System.Reflection.Metadata 5.0.0-preview.8.20407.11 was resolved.

Seems they are relying on unreleased nuget packages.

Can open an issue if it makes sense to do so.

@jasonmalinowski
Copy link
Member

@333fred The issue above is fixed by your further upgrading of packages, I'd hope?

@333fred
Copy link
Member

333fred commented Sep 18, 2020

Yes, that will be fixed in RC2/16.8p4. The change didn't quite make RC1/16.8p3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants