Bug 44130 - Visual studio Error Running Code Analysis when Xamarin forms portable project contains XamlCompilationAttribute
Summary: Visual studio Error Running Code Analysis when Xamarin forms portable project...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.1
Hardware: PC Windows
: --- enhancement
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
: 57609 ()
Depends on:
Blocks:
 
Reported: 2016-09-08 22:14 UTC by jamie_seter
Modified: 2018-01-31 21:54 UTC (History)
7 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Clean project reproducing XAMLC issues when using static code analysis (228.08 KB, application/x-zip-compressed)
2016-10-04 17:26 UTC, jamie_seter
Details
Clean project reproducing XAMLC issues when using static code analysis (227.24 KB, application/x-zip-compressed)
2016-10-04 18:32 UTC, jamie_seter
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description jamie_seter 2016-09-08 22:14:18 UTC
*Description:

When running the "Build -> Run Code Analysis on Solution", the build fails when the solution contains a Xamarin forms project that utilizes XamlCompilation attribute.


38>MSBUILD : error : CA0001 : Member 'get_Assembly' could not be found in type 'System.Type' in assembly 'Company.Mobile.Forms.Shared, Version=7.0.0.0, Culture=neutral'.
38>MSBUILD : error : CA0001 : The following error was encountered while reading module 'Company.Mobile.Forms.Shared': Could not resolve member reference: [System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]System.Type::get_Assembly.
38>MSBUILD : error : CA0001 : Rule=Microsoft.Usage#CA2214, Target=Company.Mobile.Forms.Shared.App.#.ctor(Xamarin.Forms.Page) : The following error was encountered while reading module 'Company.Mobile.Forms.Shared': Could not resolve member reference: [System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]System.Type::get_Assembly.
38>MSBUILD : error : CA0001 : Rule=Microsoft.Design#CA1001, Target=Company.Mobile.Forms.Shared.App : The following error was encountered while reading module 'Company.Mobile.Forms.Shared': Could not resolve member reference: [System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]System.Type::get_Assembly.
38>  Code Analysis Complete -- 4 error(s), 0 warning(s)


This is tested using both the Assembly level syntax and per-class syntax.

*Version information
Microsoft Visual Studio Premium 2013
Version 12.0.40629.00 Update 5
Microsoft .NET Framework
Version 4.6.01055

Installed Version: Premium

Team Explorer for Visual Studio 2013
Microsoft Team Explorer for Visual Studio 2013

Microsoft Visual C# 2013

NuGet Package Manager   2.12.0.817

Xamarin   4.1.2.18 (fcbe082)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   6.1.2.21 (1cf254d)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS   9.8.2.22 (f37444a)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 1 Rui Marinho 2016-10-04 15:54:17 UTC
Needs Info

Thank you for taking the time to submit the bug. We tried to reproduce the issue you reported but were unable given the description. If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue, we would very much appreciate it.

For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d
Comment 2 jamie_seter 2016-10-04 17:26:47 UTC
Created attachment 17872 [details]
Clean project reproducing XAMLC issues when using static code analysis

Project created using Visual Studio 2013 using Template for default XAML application.  Upgraded xamarin forms nuget to latest and then added Xaml compilation attribute to the assembly on the forms portable project.
Did not reproduce get_Assembly but static code analysis errors with similar
assembly errors.

Workaround:  Wrap the attribute with #if !CODE_ANALYSIS to disable it during Static code analysis.


  



Microsoft Visual Studio Premium 2013
Version 12.0.40629.00 Update 5
Microsoft .NET Framework
Version 4.6.01055

Installed Version: Premium

LightSwitch for Visual Studio 2013
Team Explorer for Visual Studio 2013
Visual Basic 2013
Visual C# 2013
Visual C++ 2013
Visual F# 2013
Visual Studio 2013 Code Analysis Spell Checker
Windows Phone SDK 8.0 - ENU
Application Insights Tools for Visual Studio Package   1.0
ASP.NET and Web Tools   12.5.60612.0
ASP.NET Web Frameworks and Tools 2012.2
Common Azure Tools   1.4
Microsoft Advertising SDK for Windows Phone   
Microsoft Azure Mobile Services Tools   1.4
NuGet Package Manager   2.12.0.817
Office Developer Tools for Visual Studio 2013 ENU   12.0.31105
PreEmptive Analytics Visualizer   1.2
SQL Server Data Tools   12.0.41012.0
Windows Phone 8.1 SDK Integration   1.0
Workflow Manager Tools 1.0   1.0
Xamarin   4.1.2.18 (fcbe082)
Xamarin.Android   6.1.2.21 (1cf254d)
Xamarin.iOS   9.8.2.22 (f37444a)
Comment 3 Rui Marinho 2016-10-04 17:52:09 UTC
Can you try in VS 2015 ?
Comment 4 jamie_seter 2016-10-04 18:32:02 UTC
Created attachment 17874 [details]
Clean project reproducing XAMLC issues when using static code analysis

Visual Studio 2015

Microsoft Visual Studio Enterprise 2015
Version 14.0.25425.01 Update 3
Microsoft .NET Framework
Version 4.6.01055

Installed Version: Enterprise

Architecture and Modeling Tools   
Microsoft Architecture and Modeling Tools
    
UML® and Unified Modeling Language™ are trademarks or registered trademarks of the Object Management Group, Inc. in the United States and other countries.

Visual Basic 2015   
Microsoft Visual Basic 2015

Visual C# 2015   
Microsoft Visual C# 2015

Visual C++ 2015   
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ENU   
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   7.8.00927.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015.1 (Beta8)   14.1.11107.0
ASP.NET and Web Tools 2015.1 (Beta8)

ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.40314.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.8
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Debugging Tools for Windows   10.0.10011.16384
Integrates the Windows Debugger functionality (http://go.microsoft.com/fwlink/?linkid=223405) in Visual Studio.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

NuGet Package Manager   3.4.4
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   14.0.60519.0
Microsoft SQL Server Data Tools

TypeScript   1.8.36.0
TypeScript tools for Visual Studio

Windows Driver Kit   10.0.10011.16384
Headers, libraries, and tools needed to develop, debug, and test Windows drivers (msdn.microsoft.com/en-us/windows/hardware/gg487428.aspx)

Xamarin   4.1.2.18 (fcbe082)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   6.1.2.21 (1cf254d)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS   9.8.2.22 (f37444a)
Visual Studio extension to enable development for Xamarin.iOS.

Errors:
Severity	Code	Description	Project	File	Line	Suppression State
Error	CA0001	CA0001 : Member 'IsInstanceOfType' could not be found in type 'System.Type' in assembly 'ForestPath, Version=1.0.0.0, Culture=neutral'.				Active
Error	CA0001	CA0001 : An error was encountered while parsing IL for method: 'ForestPath.MainPage.InitializeComponent', instruction at offset '0x92' with opcode 'Callvirt'.				Active
Error	CA0001	CA0001 : Rule=Microsoft.Usage#CA2214, Target=ForestPath.MainPage.#.ctor() : An error was encountered while parsing IL for method: 'ForestPath.MainPage.InitializeComponent', instruction at offset '0x92' with opcode 'Callvirt'.				Active
Comment 5 Rui Marinho 2016-10-04 18:35:10 UTC
Ok this is a feature request, as we don't own those tools we will need to reach out for more information.

Will add this to our backlog.

Thanks for your report.

Warm Regards
Xamarin Forms this
Comment 6 jamie_seter 2016-10-04 18:44:26 UTC
I don't understand what tools you are referencing.  The project only requires visual studio 2015 and the Xamarin visual studio extension.  I do not believe I installed anything outside of what came with visual studio and Xamarin.
Do you believe this issue only occurs with some specific component I have in VS?
Comment 7 Rui Marinho 2016-10-04 18:46:55 UTC
I was referring to the built in code analysis tools .. remember we are just the Xamarin.Forms team, this doesn't seem a direct issue with XamlC as we do create a valid assembly and you can use it. 
But the code analysis tools might need extra bits.. We will need to reach out and investigate.
Comment 8 Stefan.Wert 2017-01-20 19:49:04 UTC
Has there been any progress on this?
Comment 9 Stephane Delcroix 2017-06-27 09:32:32 UTC
*** Bug 57609 has been marked as a duplicate of this bug. ***
Comment 10 Karol S 2017-08-10 13:42:47 UTC
We also have this problem.
Comment 11 stefan.wagner 2017-10-13 14:54:42 UTC
Same Problem here (the report is over one year old).

I cannot use the Visual Studio 2017 Code Analysis with Xamarin Forms project. I would say a big bug in Xamarin...
Comment 12 Stephane Delcroix 2018-01-24 08:35:19 UTC
I was able to get a Code Analysis error with your repro (the first one) while building the ForgeRunner Portable project. But it goes away once I update XF to 2.5 (latest stable).

Could you please confirm:
 - that the problem goes away for you with 2.5

Thanks
Comment 13 Stephane Delcroix 2018-01-25 09:48:00 UTC
got a repro failing on 2.5

a fix is coming
Comment 14 Stephane Delcroix 2018-01-25 10:05:49 UTC
https://github.com/xamarin/Xamarin.Forms/pull/1656
Comment 15 Stefan.Wert 2018-01-25 14:54:52 UTC
Thanks!
Comment 16 Rui Marinho 2018-01-31 17:44:55 UTC
Should be fixed on 2.6.0-pre1
Comment 17 Melbourne Developer 2018-01-31 21:54:11 UTC
Good to hear!