An error occured while deserializing UCFG for method

Today we get an error this error “An error occured while deserializing UCFG for method”

It seems to coincide with this recent PR https://github.com/SonarSource/sonar-ucfg/commit/fc5d64d016ff2dc69da5402959a4ad97a51bb3e4

2018-07-31T11:45:52.4597797Z INFO: Importing 62 Roslyn reports
2018-07-31T11:45:52.5815715Z INFO: Sensor C# [csharp] (done) | time=1885ms
2018-07-31T11:45:52.5817450Z INFO: Sensor Zero Coverage Sensor
2018-07-31T11:45:52.6708414Z INFO: Sensor Zero Coverage Sensor (done) | time=88ms
2018-07-31T11:45:52.6709877Z INFO: Sensor JavaSecuritySensor [security]
2018-07-31T11:45:52.6713674Z INFO: Analyzing 0 ucfgs to detect vulnerabilities.
2018-07-31T11:45:52.6973603Z INFO: Sensor JavaSecuritySensor [security] (done) | time=28ms
2018-07-31T11:45:52.6974650Z INFO: Sensor CSharpSecuritySensor [security]
2018-07-31T11:45:52.9613489Z INFO: ------------------------------------------------------------------------
2018-07-31T11:45:52.9613992Z INFO: EXECUTION FAILURE
2018-07-31T11:45:52.9614269Z INFO: ------------------------------------------------------------------------
2018-07-31T11:45:52.9614502Z INFO: Total time: 30.185s
2018-07-31T11:45:53.0966695Z INFO: Final Memory: 32M/484M
2018-07-31T11:45:53.0967447Z INFO: ------------------------------------------------------------------------
2018-07-31T11:45:53.1052835Z ##[error]ERROR: Error during SonarQube Scanner execution
ERROR: An error occured while deserializing UCFG for method 
ERROR: Caused by: Protocol message had invalid UTF-8.
ERROR:
2018-07-31T11:45:53.1068635Z ERROR: Error during SonarQube Scanner execution
2018-07-31T11:45:53.1069196Z ERROR: An error occured while deserializing UCFG for method 
2018-07-31T11:45:53.1069687Z ERROR: Caused by: Protocol message had invalid UTF-8.
2018-07-31T11:45:53.1070107Z ERROR: 
2018-07-31T11:45:53.2131613Z ##[error]The SonarQube Scanner did not complete successfully
2018-07-31T11:45:53.2132423Z The SonarQube Scanner did not complete successfully
2018-07-31T11:45:53.2186036Z 12:45:53.217  Creating a summary markdown file...
2018-07-31T11:45:53.2225019Z ##[error]12:45:53.221  Post-processing failed. Exit code: 1
2018-07-31T11:45:53.2226944Z 12:45:53.221  Post-processing failed. Exit code: 1

I am also having this issue.

Looks like it will be fixed soon SonarCloud - VSTS - MSBuild now failing

Hi guys, problem is now fixed. Sorry for the inconvenience!

1 Like

After earlier this week, builds were working again, but now we kind of run into the same error I think.

Project that have “SonarAnalyzer.CSharp” installed will fail with the error:

CSC(0,0): Error AD0001: Analyzer ‘SonarAnalyzer.Rules.CSharp.UcfgGenerator’ threw an exception of type ‘SonarAnalyzer.ControlFlowGraph.UcfgException’ with message ‘Exception during creation of UCFG: Method name: ExtractSelectedFacetten Syntax node kind: MethodDeclaration File: D:\a\1\s\Website\PinHigh.MappingLayer\Services\ProductService.cs Line: 55,8 ## SonarAnalyzer.ControlFlowGraph.UcfgException: Unexpected state, method called as extension of a member but there is no member access available. ## at SonarAnalyzer.ControlFlowGraph.CSharp.UcfgInstructionFactory.ProcessInvocationExpression(InvocationExpressionSyntax invocationSyntax) ## at System.Linq.Enumerable.d__172.MoveNext() ## at Google.Protobuf.Collections.RepeatedField1.AddRange(IEnumerable1 values) ## at SonarAnalyzer.ControlFlowGraph.CSharp.UcfgBlockFactory.CreateBasicBlock(Block block) ## at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() ## at Google.Protobuf.Collections.RepeatedField1.AddRange(IEnumerable1 values) ## at SonarAnalyzer.ControlFlowGraph.CSharp.UcfgFactory.Create(SyntaxNode syntaxNode, IMethodSymbol methodSymbol, IControlFlowGraph cfg)’.

Projects that don’t have this package installed will succeed but will still get lots of wanrings like this one:

warning AD0001: Analyzer ‘SonarAnalyzer.Rules.CSharp.UcfgGenerator’ threw an exception of type ‘SonarAnalyzer.ControlFlowGraph.UcfgException’ with message 'Exception during creation of UCFG: Method name: Update Syntax node kind: MethodDeclaration File:

Hi @Boaz,

Thank you for reporting this issue. Would you mind sharing with us the line 55 of ProductService.cs? This exception is thrown in a case that is not expected to happen (i.e. we detect an extension method but it isn’t used as extension nor as static call).

Cheers,
Amaury

Line 55 is en empty line, in total we get 3 of those messages for this project and all on empty lines, in this case the empty line is preceded by the this method:

 public List<GolfbaanViewModel> GetLinkedGolfbanenFromProduct(int productid)
    {
        return _mapper.Map<List<GolfbaanViewModel>>(_productRepository.GetLinkedGolfbanenFromProduct(productid));
    }

Hi @Boaz,

The line numbers reported by Roslyn are zero-based, whereas the editor displays them as 1-based.

Are the messages on non-empty lines if you treat the line numbers as zero-based, and if so could you share one of the failing methods please?

Thanks,
Duncan

In that case it will be this line:

private ProductSearchResult<ProductViewModel> ExtractSelectedFacetten(ProductSearchResult<ProductViewModel> searchResult, ProductFilterViewModel filter)

the full method:

private ProductSearchResult<ProductViewModel> ExtractSelectedFacetten(ProductSearchResult<ProductViewModel> searchResult, ProductFilterViewModel filter)
    {
        searchResult.IsCountrySelected = !string.IsNullOrEmpty(filter.Land) && searchResult.Landen.Any();

        searchResult.IsRegionSelected = searchResult.IsCountrySelected && !string.IsNullOrEmpty(filter.Regio) && searchResult.Regios.Any();

        searchResult.SelectedFacets = searchResult.Facetten?.SelectMany(g => g.SubBuckets).Where(pf => filter.ProductFacetten?.Any(spf => pf.UrlSlug?.Equals(spf, StringComparison.OrdinalIgnoreCase) ?? false) ?? false).ToList() ?? new List<Bucket>();

        searchResult.SelectedProductPacketFacets = searchResult.PakketFacetten?.SelectMany(g => g.SubBuckets).Where(pf => filter.PakketFacetten?.Any(spf => pf.UrlSlug?.Equals(spf, StringComparison.OrdinalIgnoreCase) ?? false) ?? false).ToList() ?? new List<Bucket>();

        searchResult.IsSearchStringUsed = !string.IsNullOrWhiteSpace(filter.s); 

        return searchResult;
    }

Hi @Boaz,

Thanks for all your answers. Can you just confirm you have these warnings but no errors (i.e. even if you see these warnings the analysis is still complete and results are pushed to SonarCloud).

In this specific case the build will fail becasue (?) we configured the solution with: /WarnAsError

In other solutions/projects it are warnings and the analysis will complete.

Thank you @Boaz for reporting this issue, we are currently working on it and expect the situation to go back to normal during the afternoon.

@Boaz It now should work again. Please let me know if there still is something wrong.

Yes!
Thank you it works again!

1 Like