xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.47k stars 514 forks source link

Retrieving a custom attribute value having type System.Type fails with a TypeLoadException #3788

Closed cwrea closed 4 years ago

cwrea commented 6 years ago

Steps to Reproduce

  1. Download, extract, and load the sample solution (see zip file at bottom).
  2. Build and run the iOS project, targeting either iPhone or iPhone Simulator.

    The sample project includes a .NET Standard library with a single class containing some xUnit-style tests. There are iOS and Android platform projects that use xUnit's device runners to run the tests. Each test body simply asserts true — the tests differ only in signature and xUnit attributes used.

Expected Behavior

Actual Behavior

EFCoreCPTest.XunitInlineDataTest.TheoryStyleTest_WithInlineDataAttribute_ShouldAlwaysSucceed : System.TypeLoadException : Could not load type System.String, netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 while decoding custom attribute: (null) at (wrapper managed-to-native) System.Reflection.CustomAttributeData.ResolveArgumentsInternal( System.Reflection.ConstructorInfo,System.Reflection.Assembly,intptr,uint,object[]&,object[]&)

Xamarin.Android also shows the same test failing in the same way. FWIW, this test succeeds in .NET Core, .NET Framework, and UWP. This issue was discovered while trying to adapt some of the unit tests from Entity Framework Core to run in iOS and Android apps. This kind of test is used in EF Core's own test suite. See method It_maps_strings_to_not_null_types() at: https://github.com/aspnet/EntityFrameworkCore/blob/2.0.2/test/EFCore.Sqlite.Tests/Storage/SqliteTypeMappingTest.cs

I thought perhaps as this is Reflection-related that it could be a known limitation in Xamarin, but in the Xamarin.iOS Limitations page, at bottom of the System.Reflection.Emit section, it mentions "But [except for Reflection.Emit] the entire Reflection API, including Type.GetType ("someClass"), listing methods, listing properties, fetching attributes and values works just fine."

While the attribute value in this case is not a simple type like string or int, having an attribute value of type System.Type is clearly of some use, and I think this ought to work.

Environment

Microsoft Visual Studio Community 2017 
Version 15.5.7
VisualStudio.15.Release/15.5.7+27130.2036
Microsoft .NET Framework
Version 4.7.02556

Installed Version: Community

Visual Basic 2017   00369-60000-00001-AA398
Microsoft Visual Basic 2017

Visual C# 2017   00369-60000-00001-AA398
Microsoft Visual C# 2017

Visual C++ 2017   00369-60000-00001-AA398
Microsoft Visual C++ 2017

Visual F# 4.1   00369-60000-00001-AA398
Microsoft Visual F# 4.1

Add New File   3.5
The fastest and easiest way to add new files to any project - including files that start with a dot

Application Insights Tools for Visual Studio Package   8.10.01106.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.0.31129.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services   1.0
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2012   4.0.20601.0
For additional information, visit https://www.asp.net/

ASP.NET Web Frameworks and Tools 2017   5.2.51007.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   15.0.31106.0
Azure App Service Tools v3.0.0

CodeMaid   10.4.53
CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, R, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.

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

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

JavaScript UWP Project System   2.0
JavaScript UWP Project System

JetBrains ReSharper Ultimate 2017.2.2    Build 109.0.20171006.122324
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2018 JetBrains, Inc.

Merq   1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Continuous Delivery Tools for Visual Studio   0.3
Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   4.8.4-pre (3fe64e3)
Support for debugging Mono processes with Visual Studio.

Node.js Tools   1.4.11025.7
Adds support for developing and debugging Node.js apps in Visual Studio

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

Open Command Line   2.1.179
Opens a command line at the root of the project. Support for all consoles such as CMD, PowerShell, Bash etc. Provides syntax highlighting, Intellisense and execution of .cmd and .bat files.

Search in Velocity by Silverlake Software LLC   0.7.1
Provides a command to search in Velocity the offline documentation and docset viewer for Windows

SQL Server Data Tools   15.1.61710.120
Microsoft SQL Server Data Tools

SQLite & SQL Server Compact Toolbox   4.7
SQLite & SQL Server Compact Toolbox adds scripting, import, export, rename, query execution and much more to SQL Server Compact & SQLite Data Connections.

Syntax Visualizer   1.0
An extension for visualizing Roslyn SyntaxTrees.

TypeScript Tools   15.5.11025.1
TypeScript Tools for Microsoft Visual Studio

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Universal Windows Apps   15.0.27130.2036
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

VSColorOutput   2.5.1
Color output for build and debug windows - http://mike-ward.net/vscoloroutput

Xamarin   4.8.0.760 (fc93f3f5b)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   4.8.188 (c5813fa34)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK   8.1.5.0 (HEAD/75f8c6838)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   11.6.1.4 (db807ec)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Build Logs

1>------ Rebuild All started: Project: XunitInlineDataIssue, Configuration: Debug Any CPU ------
1>XunitInlineDataTest.cs(10,83,10,92): warning xUnit1026: Theory method 'TheoryStyleTest_WithInlineDataAsType_ShouldAlwaysSucceed' on test class 'XunitInlineDataTest' does not use parameter 'typeValue'.
1>XunitInlineDataTest.cs(32,87,32,98): warning xUnit1026: Theory method 'TheoryStyleTest_WithInlineDataAsString_ShouldAlwaysSucceed' on test class 'XunitInlineDataTest' does not use parameter 'stringValue'.
1>XunitInlineDataIssue -> D:\Projects\XunitInlineDataIssueSoln\XunitInlineDataIssue\XunitInlineDataIssue\bin\Debug\netstandard2.0\XunitInlineDataIssue.dll
1>Done building project "XunitInlineDataIssue.csproj".
2>------ Rebuild All started: Project: XunitInlineDataIssue.iOS, Configuration: Debug iPhone ------
2>  Connecting to Mac server cwrea-mini...
2>  No way to resolve conflict between "System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  No way to resolve conflict between "System.Collections, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Collections, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  No way to resolve conflict between "System.Diagnostics.Debug, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Diagnostics.Debug, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Diagnostics.Debug, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  No way to resolve conflict between "System.Threading.Tasks, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Threading.Tasks, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  No way to resolve conflict between "System.Threading, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Threading, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Threading, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  No way to resolve conflict between "System.Globalization, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Globalization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Globalization, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  No way to resolve conflict between "System.Reflection, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Reflection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Reflection, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  No way to resolve conflict between "System.IO, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.IO, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  No way to resolve conflict between "System.Runtime.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Runtime.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Runtime.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  No way to resolve conflict between "System.Text.RegularExpressions, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Text.RegularExpressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Text.RegularExpressions, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  No way to resolve conflict between "System.Collections.Concurrent, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Collections.Concurrent, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Collections.Concurrent, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  No way to resolve conflict between "System.Text.Encoding, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Text.Encoding, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Text.Encoding, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>  Consider app.config remapping of assembly "System.Runtime, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll] to Version "4.1.0.0" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Runtime.dll] to solve conflict and get rid of warning.
2>  Consider app.config remapping of assembly "System.Text.RegularExpressions, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Text.RegularExpressions\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Text.RegularExpressions.dll] to Version "4.0.10.0" [] to solve conflict and get rid of warning.
2>  Consider app.config remapping of assembly "System.IO, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.IO\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.IO.dll] to Version "4.1.0.0" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.IO.dll] to solve conflict and get rid of warning.
2>  Consider app.config remapping of assembly "System.Globalization, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Globalization\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Globalization.dll] to Version "4.0.10.0" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Globalization.dll] to solve conflict and get rid of warning.
2>  Consider app.config remapping of assembly "System.Text.Encoding, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Text.Encoding\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Text.Encoding.dll] to Version "4.0.10.0" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Text.Encoding.dll] to solve conflict and get rid of warning.
2>  Consider app.config remapping of assembly "System.Runtime.Extensions, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Extensions\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Extensions.dll] to Version "4.1.0.0" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Runtime.Extensions.dll] to solve conflict and get rid of warning.
2>  Consider app.config remapping of assembly "System.Collections, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Collections\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Collections.dll] to Version "4.0.10.0" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Collections.dll] to solve conflict and get rid of warning.
2>  Consider app.config remapping of assembly "System.Threading, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Threading\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Threading.dll] to Version "4.0.10.0" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Threading.dll] to solve conflict and get rid of warning.
2>  Consider app.config remapping of assembly "System.Diagnostics.Debug, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Diagnostics.Debug\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Diagnostics.Debug.dll] to Version "4.0.10.0" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Diagnostics.Debug.dll] to solve conflict and get rid of warning.
2>  Consider app.config remapping of assembly "System.Reflection, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Reflection\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Reflection.dll] to Version "4.1.0.0" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Reflection.dll] to solve conflict and get rid of warning.
2>  Consider app.config remapping of assembly "System.Collections.Concurrent, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Collections.Concurrent\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Collections.Concurrent.dll] to Version "4.0.10.0" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Collections.Concurrent.dll] to solve conflict and get rid of warning.
2>  Consider app.config remapping of assembly "System.Threading.Tasks, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.0.0" [C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Threading.Tasks\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Threading.Tasks.dll] to Version "4.0.10.0" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Threading.Tasks.dll] to solve conflict and get rid of warning.
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2041,5): warning MSB3276: Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190.
2>  XunitInlineDataIssue.iOS -> D:\Projects\XunitInlineDataIssueSoln\XunitInlineDataIssue\XunitInlineDataIssue.iOS\bin\iPhone\Debug\XunitInlineDataIssue.iOS.exe
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Xamarin.Apple.Sdk.targets(57,5): warning : Portable PDB 'D:\Projects\XunitInlineDataIssueSoln\XunitInlineDataIssue\XunitInlineDataIssue\bin\Debug\netstandard2.0\XunitInlineDataIssue.pdb' can't be converted to mdb. Consider setting the project 'DebugType' property to 'Full'.
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Xamarin.Apple.Sdk.targets(57,5): warning :    at Pdb2Mdb.Converter.Convert(String filename) in C:\d\lanes\5409\fc93f3f5\source\xamarinvs\src\MSBuild\Xamarin.iOS.Tasks\Pdb2mdb\Driver.cs:line 44
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Xamarin.Apple.Sdk.targets(57,5): warning :    at Xamarin.iOS.Tasks.ConvertDebuggingFiles.Execute() in C:\d\lanes\5409\fc93f3f5\source\xamarinvs\src\MSBuild\Xamarin.iOS.Tasks\Tasks\ConvertDebuggingFiles.cs:line 27
2>  Detected signing identity:
2>    Code Signing Key: "iPhone Developer: [...] (...)" 
2>    Provisioning Profile: "cwrea iOS Dev Prov. Profile" (...)
2>    Bundle Id: com.yourcompany.XunitInlineDataIssue
2>    App Id: J7ADM89KY9.com.yourcompany.XunitInlineDataIssue
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): warning : The assembly 'System.IO.Compression.dll' was loaded from a different path than the provided path (provided path: /Users/cwrea/Library/Caches/Xamarin/mtbs/builds/XunitInlineDataIssue.iOS/5bac9afcccb30970a3b46c9e91dd09d6/bin/iPhone/Debug/System.IO.Compression.dll, actual path: /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/lib/mono/Xamarin.iOS/System.IO.Compression.dll).
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): warning : The assembly 'System.Net.Http.dll' was loaded from a different path than the provided path (provided path: /Users/cwrea/Library/Caches/Xamarin/mtbs/builds/XunitInlineDataIssue.iOS/5bac9afcccb30970a3b46c9e91dd09d6/bin/iPhone/Debug/System.Net.Http.dll, actual path: /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/lib/mono/Xamarin.iOS/System.Net.Http.dll).
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): warning : The assembly 'System.Runtime.InteropServices.RuntimeInformation.dll' was loaded from a different path than the provided path (provided path: /Users/cwrea/Library/Caches/Xamarin/mtbs/builds/XunitInlineDataIssue.iOS/5bac9afcccb30970a3b46c9e91dd09d6/bin/iPhone/Debug/System.Runtime.InteropServices.RuntimeInformation.dll, actual path: /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/lib/mono/Xamarin.iOS/Facades/System.Runtime.InteropServices.RuntimeInformation.dll).
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): warning : The assembly 'System.Security.Cryptography.Algorithms.dll' was loaded from a different path than the provided path (provided path: /Users/cwrea/Library/Caches/Xamarin/mtbs/builds/XunitInlineDataIssue.iOS/5bac9afcccb30970a3b46c9e91dd09d6/bin/iPhone/Debug/System.Security.Cryptography.Algorithms.dll, actual path: /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/lib/mono/Xamarin.iOS/Facades/System.Security.Cryptography.Algorithms.dll).
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): warning : The assembly 'System.Security.Cryptography.Encoding.dll' was loaded from a different path than the provided path (provided path: /Users/cwrea/Library/Caches/Xamarin/mtbs/builds/XunitInlineDataIssue.iOS/5bac9afcccb30970a3b46c9e91dd09d6/bin/iPhone/Debug/System.Security.Cryptography.Encoding.dll, actual path: /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/lib/mono/Xamarin.iOS/Facades/System.Security.Cryptography.Encoding.dll).
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): warning : The assembly 'System.Security.Cryptography.X509Certificates.dll' was loaded from a different path than the provided path (provided path: /Users/cwrea/Library/Caches/Xamarin/mtbs/builds/XunitInlineDataIssue.iOS/5bac9afcccb30970a3b46c9e91dd09d6/bin/iPhone/Debug/System.Security.Cryptography.X509Certificates.dll, actual path: /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/lib/mono/Xamarin.iOS/Facades/System.Security.Cryptography.X509Certificates.dll).
2>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip: removing global symbols from a final linked no longer supported.  Use -exported_symbols_list at link time when building: /Users/cwrea/Library/Caches/Xamarin/mtbs/builds/XunitInlineDataIssue.iOS/5bac9afcccb30970a3b46c9e91dd09d6/bin/iPhone/Debug/XunitInlineDataIssue.iOS.app/XunitInlineDataIssue.iOS
2>  bin/iPhone/Debug/XunitInlineDataIssue.iOS.app: valid on disk
2>  bin/iPhone/Debug/XunitInlineDataIssue.iOS.app: satisfies its Designated Requirement
2>  bin/iPhone/Debug/XunitInlineDataIssue.iOS.app: explicit requirement satisfied
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========

Projects build report:
  Status    | Project [Config|platform]
 -----------|---------------------------------------------------------------------------------------------------
  Succeeded | XunitInlineDataIssue\XunitInlineDataIssue\XunitInlineDataIssue.csproj [Debug|Any CPU]
  Succeeded | XunitInlineDataIssue\XunitInlineDataIssue.iOS\XunitInlineDataIssue.iOS.csproj [Debug|iPhone]

Time Elapsed 00:00:45.595

Example Project (If Possible)

XunitInlineDataIssueSoln.zip

mandel-macaque commented 6 years ago

Taking a look at the project. Thanks for reporting the issue, will get back ASAP with some feedback.

spouliot commented 6 years ago

System.String, netstandard, Version=2.0.0.0

Sadly the type references for custom attributes are not encoded as other type references :( and this can cause issues with type forwarders.

It seems the linker did not re-write this case so it points to something that's not available (netstandard.dll) at runtime.

mandel-macaque commented 6 years ago

App ran and confirmed bug.

spouliot commented 6 years ago

Yes, disabling the linker (default on simulator but not on this project) works fine.

The custom attributes have encoded the reference to netstandard types and, since they are encoded separately than normal type references, it was not updated by the linker. We do cover similar cases so I need to investigate why this case does not work.

spouliot commented 6 years ago
.custom instance void [xunit.core]Xunit.InlineDataAttribute::.ctor(object[]) = (

The signature, taking an array of System.Object, not System.Type might be the cause why the linker did not resolve the type (from the data) and re-write it (to the final destination/asembly)

spouliot commented 6 years ago

Theory confirmed. Adding Console.WriteLine (typeof (string).AssemblyQualifiedName); in a test shows

System.String, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e

i.e. assembly is mscorlib not netstandard

Also if I write my own attribute with a .ctor like

        public MyAttribute (params Type[] data)
        {
            this.data = data;
        }

then

    var x = typeof (XunitInlineDataTest).GetMethod ("Foo").GetCustomAttribute<MyAttribute> ();
    Console.WriteLine ((x.Data [0] as Type).AssemblyQualifiedName);

also shows

System.String, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e

so resolving/re-writting works - it just apply to System.Type, not System.Object

rolfbjarne commented 6 years ago

The signature, taking an array of System.Object, not System.Type might be the cause why the linker did not resolve the type (from the data) and re-write it (to the final destination/asembly)

Sounds like a variation/duplicate of https://bugzilla.xamarin.com/show_bug.cgi?id=57825.

spouliot commented 6 years ago

It's a variation, the type is marked (and available) but still points to netstandard.dll so the attribute cannot be re-constructed at runtime.

spouliot commented 4 years ago

The attached test case works fine with master. This was a linker issue and likely fixed in mono/linker (in one of the milestones since this was filed here).