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

[Bug] Handling attributes with missed types passed as args #9796

Open
mikasoukhov opened this issue Mar 16, 2024 · 7 comments
Open

[Bug] Handling attributes with missed types passed as args #9796

mikasoukhov opened this issue Mar 16, 2024 · 7 comments
Labels
bug A bug to fix dotnet Generate .NET API reference docs

Comments

@mikasoukhov
Copy link

mikasoukhov commented Mar 16, 2024

Describe the bug

When assembly (placed as a .net ref source) contains type with TypeConverter attribute (I don't know, maybe any other attribute causes the same) applied to some property and this attribute accepts type from assembly that doesn't present in src folder we will get the following error:

System.IO.InvalidDataException
  HResult=0x80131501
  Message=Fail to parse id for symbol  in namespace .
  Source=Docfx.Dotnet
  StackTrace:
   at Docfx.Dotnet.YamlModelGenerator.AddSpecReference(ISymbol symbol, IReadOnlyList`1 typeGenericParameters, IReadOnlyList`1 methodGenericParameters, Dictionary`2 references, SymbolVisitorAdapter adapter) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\YamlModelGenerator.cs:line 129
   at Docfx.Dotnet.SymbolVisitorAdapter.AddSpecReference(ISymbol symbol, IReadOnlyList`1 typeGenericParameters, IReadOnlyList`1 methodGenericParameters) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\SymbolVisitorAdapter.cs:line 415
   at Docfx.Dotnet.SymbolVisitorAdapter.GetConstantValueForArgumentInfo(TypedConstant arg) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\SymbolVisitorAdapter.cs:line 807
   at Docfx.Dotnet.SymbolVisitorAdapter.GetArgumentInfo(TypedConstant arg) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\SymbolVisitorAdapter.cs:line 797
   at Docfx.Dotnet.SymbolVisitorAdapter.GetArguments(AttributeData attr) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\SymbolVisitorAdapter.cs:line 770
   at Docfx.Dotnet.SymbolVisitorAdapter.<GetAttributeInfo>b__32_3(AttributeData attr) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\SymbolVisitorAdapter.cs:line 749
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Docfx.Dotnet.SymbolVisitorAdapter.GetAttributeInfo(ImmutableArray`1 attributes) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\SymbolVisitorAdapter.cs:line 744
   at Docfx.Dotnet.SymbolVisitorAdapter.VisitNamedType(INamedTypeSymbol symbol) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\SymbolVisitorAdapter.cs:line 195
   at Docfx.Dotnet.SymbolVisitorAdapter.VisitDescendants[T](IEnumerable`1 children, Func`2 getChildren, Func`2 filter) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\SymbolVisitorAdapter.cs:line 505
   at Docfx.Dotnet.SymbolVisitorAdapter.VisitNamespace(INamespaceSymbol symbol) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\SymbolVisitorAdapter.cs:line 132
   at Docfx.Dotnet.SymbolVisitorAdapter.VisitDescendants[T](IEnumerable`1 children, Func`2 getChildren, Func`2 filter) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\SymbolVisitorAdapter.cs:line 505
   at Docfx.Dotnet.SymbolVisitorAdapter.VisitAssembly(IAssemblySymbol symbol) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\ManagedReference\Visitors\SymbolVisitorAdapter.cs:line 116
   at Docfx.Dotnet.DotnetApiCatalog.CreateManagedReference(List`1 assemblies, ExtractMetadataConfig config, DotnetApiOptions options) in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\DotnetApiCatalog.ManagedReference.cs:line 25
   at Docfx.Dotnet.DotnetApiCatalog.<<Exec>g__Build|3_0>d.MoveNext() in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\DotnetApiCatalog.cs:line 120
   at Docfx.Dotnet.DotnetApiCatalog.<Exec>d__3.MoveNext() in C:\StockSharp\docfx_sources\src\Docfx.Dotnet\DotnetApiCatalog.cs:line 72
   at Docfx.DefaultCommand.<>c__DisplayClass1_0.<Execute>b__0() in C:\StockSharp\docfx_sources\src\docfx\Models\DefaultCommand.cs:line 45
   at Docfx.CommandHelper.Run(LogOptions options, Action run) in C:\StockSharp\docfx_sources\src\docfx\Models\CommandHelper.cs:line 48
   at Docfx.DefaultCommand.Execute(CommandContext context, Options options) in C:\StockSharp\docfx_sources\src\docfx\Models\DefaultCommand.cs:line 31
   at Spectre.Console.Cli.Command`1.Spectre.Console.Cli.ICommand.Execute(CommandContext context, CommandSettings settings)
   at Spectre.Console.Cli.CommandExecutor.<Execute>d__2.MoveNext()

Expected behavior

  1. Show be displayed some more specific information. I think there must be an error catching somewhere higher on the stack. Now is no chanсe to understand what's wrong without run it under debugging in VS.
  2. Do not stop build process. Ignore it, write into log, but not stop it. It is not a critical error.

Context (please complete the following information):

  • OS: Windows
  • Docfx version: 2.75.3
@mikasoukhov mikasoukhov added the bug A bug to fix label Mar 16, 2024
@filzrev
Copy link
Contributor

filzrev commented Mar 17, 2024

Is it able to provide a minimum set of reproducible source files?

I've tried to reproduce the described condition, but without success.

assembly (placed as a .net ref source) contains type with TypeConverter attribute (I don't know, maybe any other attribute
causes the same) applied to some property and this attribute accepts type from assembly that doesn't present in src folder

@yufeih yufeih added the dotnet Generate .NET API reference docs label Mar 19, 2024
@mikasoukhov
Copy link
Author

Seems it is happened in case obfuscated assemblies only. Microsoft.CodeAnalysis.AttributeData will contains invalid values.

Anyway the issue related with docfx still is - doc building process shouldn't be stopped.

@filzrev
Copy link
Contributor

filzrev commented Apr 9, 2024

InvalidDataException seems thrown by following lines.

public string AddSpecReference(
ISymbol symbol,
IReadOnlyList<string> typeGenericParameters,
IReadOnlyList<string> methodGenericParameters,
Dictionary<string, ReferenceItem> references,
SymbolVisitorAdapter adapter)
{
var rawId = VisitorHelper.GetId(symbol);
var id = SpecIdHelper.GetSpecId(symbol, typeGenericParameters, methodGenericParameters);
if (string.IsNullOrEmpty(id))
{
throw new InvalidDataException($"Fail to parse id for symbol {symbol.MetadataName} in namespace {symbol.ContainingSymbol?.MetadataName}.");
}

And exception message text indicate both symbol.MetadataName and symbol.ContainingSymbol?.MetadataName are empty.

Seems it is happened in case obfuscated assemblies only. Microsoft.CodeAnalysis.AttributeData will contains invalid values.
Anyway the issue related with docfx still is - doc building process shouldn't be stopped.

If referencing obfuscated DLLs cause problems.
It need to determine exact condition that cause problems.
And need to fix specId resolver logics.


For Alternatives workaround.
It can be solved by changing return null' instead of throwing InvalidDataException'.
(In anyway, obfuscated code are internal logics. And it's useless for API docs)

But I can't be sure there won't be side effects by this changes.

@mikasoukhov
Copy link
Author

indalid.zip

Here is the invalid ref.

As I told obfuscation isn't real issue. Real issue - stopped build process. Docfx do not stop building process when some file or images missed. Think wrong parsed dll should be the same. Just say like - Hey, you have non dotnet assembly, so I ignore it. And continue.

@filzrev
Copy link
Contributor

filzrev commented Apr 9, 2024

Thanks for your reply.
But I can't open attached files because it's identified as Trojan:Win32/Wacatac.B!ml by Windows Defender.
Probably it's a false positive, but it's hard to test on my dev environment.

@mikasoukhov
Copy link
Author

Unfortunately I don't know any other way to transfer. Virustotal says it is fine. Maybe have other way to prevent delete it before send to analyze.

@filzrev
Copy link
Contributor

filzrev commented Apr 11, 2024

It can download attached files by updating definition files Windows Defender.
And debugger shows that the problem is caused by Kind = ErrorType symbol is passed to AddSpecReference method.

What' about following workaround to skip these error symbols.

1. Add "filter": "filterConfig.yml" setting to docfx.json's metadata section.

2. Add setting to exclude API symbol that don't have uid.

apiRules:
- exclude:
    uidRegex: "^$"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug to fix dotnet Generate .NET API reference docs
Projects
None yet
Development

No branches or pull requests

3 participants