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

Support or ignore attributes on type parameters #63

Closed
jskeet opened this issue Jun 28, 2019 · 7 comments · Fixed by #65
Closed

Support or ignore attributes on type parameters #63

jskeet opened this issue Jun 28, 2019 · 7 comments · Fixed by #65
Milestone

Comments

@jskeet
Copy link

jskeet commented Jun 28, 2019

C# 8 uses attributes on type parameters for nullability, and this causes problems for the tool at the moment.

Example:

Foo.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>preview</LangVersion>
    <NullableContextOptions>enable</NullableContextOptions>
  </PropertyGroup>
</Project>

Class1.cs:

namespace Foo
{
    public class Class1<T> where T : class
    {
    }
}

Invocation:

$ generate-public-api --project-path Foo.csproj --target-frameworks netcoreapp3.0 --assembly Foo.dll

Error:

Failed: System.Exception: dotnet exit code -532462766. Directory: C:\Users\skeet\AppData\Local\Temp\evz1pbfi.oin. Args: run --configuration Release --framework netcoreapp3.0 -- C:\Users\skeet\AppData\Local\Temp\evz1pbfi.oin\bin\Release\netcoreapp3.0\Foo.dll C:\Users\skeet\AppData\Local\Temp\evz1pbfi.oin\bin\Release\netcoreapp3.0\Foo.netcoreapp3.0.received.txt c:\Users\jon\Test\Foo. Output: . Error:
Unhandled Exception: System.NotImplementedException: Attributes on type parameters is not supported. And weird
   at PublicApiGenerator.ApiGenerator.PopulateGenericParameters(IGenericParameterProvider publicType, CodeTypeParameterCollection parameters)
   at PublicApiGenerator.ApiGenerator.CreateTypeDeclaration(TypeDefinition publicType, String[] whitelistedNamespacePrefixes, HashSet`1 excludeAttributes)
   at PublicApiGenerator.ApiGenerator.CreatePublicApiForAssembly(AssemblyDefinition assembly, Func`2 shouldIncludeType, Boolean shouldIncludeAssemblyAttributes, String[] whitelistedNamespacePrefixes, HashSet`1 excludeAttributes)
   at PublicApiGenerator.ApiGenerator.GeneratePublicApi(Assembly assembly, Type[] includeTypes, Boolean shouldIncludeAssemblyAttributes, String[] whitelistedNamespacePrefixes, String[] excludeAttributes)
   at Program.Main(String[] args) in C:\Users\skeet\AppData\Local\Temp\evz1pbfi.oin\Program.cs:line 14

   at PublicApiGenerator.Tool.Program.RunDotnet(String workingArea, Boolean verbose, String arguments) in C:\projects\apiapprover\src\PublicApiGenerator.Tool\Program.cs:line 136
   at PublicApiGenerator.Tool.Program.GeneratePublicApi(String assembly, String package, String workingArea, String framework, String outputDirectory, Boolean verbose) in C:\projects\apiapprover\src\PublicApiGenerator.Tool\Program.cs:line 93
   at PublicApiGenerator.Tool.Program.Main(String targetFrameworks, String assembly, String projectPath, String package, String packageVersion, String generatorVersion, String workingDirectory, String outputDirectory, Boolean verbose, Boolean leaveArtifacts) in C:\projects\apiapprover\src\PublicApiGenerator.Tool\Program.cs:line 56
@danielmarbach
Copy link
Member

You are such a troublemaker 😉🤣 I hope I can give this a look before my long vacation break

@jskeet
Copy link
Author

jskeet commented Jun 28, 2019

No hurry!

@danielmarbach
Copy link
Member

Looks like Mono.Cecil is working on this

jbevain/cecil#594

related to

dotnet/roslyn#29997

@danielmarbach
Copy link
Member

Ok I have a workaround that I can push soon and I also found a way of at least presenting, for now, the nullable attributes. After that, we can start looking into pretty printing those attributes

@danielmarbach
Copy link
Member

danielmarbach commented Jun 30, 2019

This enables for now support of Type attributes

#65

I can release this as a minor soon

@danielmarbach danielmarbach added this to the 9.1.0 milestone Jun 30, 2019
@danielmarbach
Copy link
Member

Done. Should be available on nuget soonish

@jskeet
Copy link
Author

jskeet commented Jun 30, 2019

Thanks, you're a star :)

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

Successfully merging a pull request may close this issue.

2 participants