Bug 55584 - System.TypeLoadException : Could not load type 'App3.TestService' from assembly 'App3, Version=, Culture=neutral, PublicKeyToken=null'
Summary: System.TypeLoadException : Could not load type 'App3.TestService' from assemb...
Status: NEW
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: Macintosh Mac OS
: Normal major
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-04-25 19:11 UTC by Sid Dubey
Modified: 2017-06-01 21:12 UTC (History)
5 users (show)

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

Repro Project (100.39 KB, application/x-zip-compressed)
2017-04-25 19:11 UTC, Sid Dubey
Screenshot (280.37 KB, image/png)
2017-04-25 19:12 UTC, Sid Dubey

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 for Bug 55584 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Sid Dubey 2017-04-25 19:11:48 UTC
Created attachment 21773 [details]
Repro Project

The Repro project (App3 - attached) if builds on Xamarin Studio on Mac gives 

System.TypeLoadException : Could not load type 'App3.TestService' from assembly 'App3, Version=, Culture=neutral, PublicKeyToken=null'.

The App3 project was created in Visual Studio 2017 and it builds and runs the unit test just fine. However when you port the same code to Xamarin Studio it gives the unknown type project for Unit Test project. (screen attached) 

* You need to modify the MyUnitTest.csproj manually and change ToolsVersion="15.0" to ToolsVersion="4.0" to be able to open the project in Xamarin Studio.

* Open View > Pads > Unit Tests
* Run All Test
Expected: Test should pass.
Actual: Test fails with 

System.TypeLoadException : Could not load type 'App3.TestService' from assembly 'App3, Version=, Culture=neutral, PublicKeyToken=null'.

Steps to create Repro Project 

* On Visual Studio 2017 in Windows Create a new Project with File > New > Project > Cross-Platform > Cross Platform App
* Select Blank App using Xamarin.Forms and Portable Class Library (PCL)
Verify: Ensure that both Android and Ios project compiles and start. 
* Add a new class, TestService, to the PCL-project that is using HttpClient.
    public class TestService
        private HttpClient client;
        public TestService()
            client = new HttpClient();
            client.BaseAddress = new Uri("https://shop.qx.se/api/tickets/");
        public async Task<string> DoStuff()
            return await client.GetStringAsync("info?eventid=1&token=SANDBOX").ConfigureAwait(false);
Note that the project will not compile at this point because HttpClient is not available in Profile259. To resolve this we have to add nuget package Microsoft.Net.Http
* Right-click the solution node and pick Manage Nuget packages for solution.
* Browse for Microsoft.Net.Http (2.2.9), select all three project and Install. if you encounter issues with the install, add dependent package Microsoft.Bcl.Build (1.0.21) and Microsoft.Bcl (1.1.10) before Microsoft.Net.Http.
* In TestService file, import System.Net.Http.HttpClient and references.
* Compile solution 
* Add a new project named “MyUnitTest”to the solution. New Project > Class Library (.NET Framework)
* Right-click the new project and Manage Nuget Packages
* Browse for Nunit (3.6.1) and Install.
* Browse for Nunit3TestAdapter (3.7.0) and Install.
* Add a Unit Test class to MyUnitTest project:
    public class Test
        public async Task TestCase()
            var target = new TestService();
            var result = await target.DoStuff();
            Assert.That(result, Is.Not.Empty);
* Add a reference to the PCL project in MyUnitTest project.
* Import namespace for nUnit attributes.
* Compile
* Click Test > Run > All Tests. Test should pass.
* Save all and close Visual Studio on Windows. 
* Copy all solution files over to a Mac.
* Open the solution in Xamarin Studio
* You might need to modify the MyUnitTest.csproj manually and change ToolsVersion="15.0" to ToolsVersion="4.0" to be able to open the project in Xamarin Studio.
* Compile
* Open View > Pads > Unit Tests
* Run All Test
Expected: Test should pass.
Actual: Test fails with 
System.TypeLoadException : Could not load type 'App3.TestService' from assembly 'App3, Version=, Culture=neutral, PublicKeyToken=null'.
* Add New Project > Other > .NET > NUnit Library Project in Xamarin Studio
* Add the unit test class above to the new project.
* Compile
Expected: Test should fail like in the unit test project created in Visual Studio 2017
Actual: Test passes!?!
* Remove reference to System.Net.Http in unit test project create in Visual Studio 2017
* Compile
* Run All test. Now they pass and there is no longer any TypeLoadException.
Customer's My CI server, that is also running on a Mac to be able to compile the ios-app, managed to compiled the Unit Test project without need to change ToolsVersion in the csproj-file. The reference to System.Net.Http in the unit tests projects csproj file did not cause any issues when running in Visual Studio on Windows but in Xamarin Studio on Mac it compiles but fails in runtime.
Comment 1 Sid Dubey 2017-04-25 19:12:26 UTC
Created attachment 21774 [details]
Comment 2 Sid Dubey 2017-04-25 19:15:48 UTC
Visual Studio 2017 on Windows
Microsoft Visual Studio Professional 2017 
Version 15.1 (26403.7) Release
Microsoft .NET Framework
Version 4.6.01586
Installed Version: Professional
Visual Basic 2017   00369-60000-00001-AA227
Microsoft Visual Basic 2017
Visual C# 2017   00369-60000-00001-AA227
Microsoft Visual C# 2017
Visual F# 4.1   00369-60000-00001-AA227
Microsoft Visual F# 4.1
Application Insights Tools for Visual Studio Package   8.6.00209.10
Application Insights Tools for Visual Studio
ASP.NET and Web Tools 2017   15.0.30320.0
ASP.NET and Web Tools 2017
ASP.NET Web Frameworks and Tools 2017   5.2.50303.0
For additional information, visit https://www.asp.net/
Azure App Service Tools v3.0.0   15.0.30209.0
Azure App Service Tools v3.0.0
Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.
Azure Data Lake Tools for Visual Studio   2.2.5000.0
Microsoft Azure Data Lake Tools for Visual Studio
Common Azure Tools   1.9
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.
JavaScript Language Service   2.0
JavaScript Language Service
JetBrains ReSharper Ultimate 2017.1.1    Build 108.0.20170407.122957
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2017 JetBrains, Inc.
KofePackagePackage Extension   1.0
KofePackagePackage Visual Studio Extension Detailed Info
Merq   1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.
Microsoft Azure Hive Query Language Service   2.2.5000.0
Language service for Hive query
Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.50131.1
Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers
Mono Debugging for Visual Studio   Mono.Debugging.VisualStudio
Support for debugging Mono processes with Visual Studio.
NuGet Package Manager   4.1.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.
SQL Server Data Tools   15.1.61702.140
Microsoft SQL Server Data Tools
ToolWindowHostedEditor   1.0
Hosting json editor into a tool window
TypeScript tools for Visual Studio
Xamarin (3f99c5a)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin.Android SDK (b16fb82)
Xamarin.Android Reference Assemblies and MSBuild support.
Xamarin.iOS and Xamarin.Mac SDK (7656cc6)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Xamarin Studio on Mac
=== Xamarin Studio Business ===
Version 6.3 (build 863)
Installation UUID: 07e8658e-f2f3-4971-8d83-ee823449b539
                Mono 4.8.1 (mono-4.8.0-branch/22a39d7) (64-bit)
                GTK+ 2.24.23 (Raleigh theme)
                Package version: 408010000
=== NuGet ===
=== Xamarin.Profiler ===
'/Applications/Xamarin Profiler.app' not found
=== Apple Developer Tools ===
Xcode 8.3.1 (12170)
Build 8E1000a
=== Xamarin.iOS ===
Version: (Xamarin Business)
Hash: a04678c2
Branch: d15-1
Build date: 2017-03-28 14:05:38-0400
=== Xamarin.Android ===
Version: (Xamarin Business)
Android SDK: /Users/fredrik/Library/Developer/Xamarin/android-sdk-mac_x86
                Supported Android versions:
                                2.3   (API level 10)
                                4.0.3 (API level 15)
                                4.1   (API level 16)
                                4.2   (API level 17)
                                4.4   (API level 19)
                                5.0   (API level 21)
                                6.0   (API level 23)
                                7.1   (API level 25)
SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.4
SDK Build Tools Version: 25.0.2
Java SDK: /usr
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
Android Designer EPL code available here:
=== Xamarin.Mac ===
Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.
=== Xamarin Inspector ===
Not Installed
=== Build Information ===
Release ID: 603000863
Git revision: a2163670efe259c85cd8f335d95b175068fbbe2a
Build date: 2017-04-03 14:33:15-04
Xamarin addins: 2045d688ea1420e0381b473360ca62a763eb7d04
Build lane: monodevelop-lion-d15-1
=== Operating System ===
Mac OS X 10.12.4
Darwin FredrikH-MacBook.local 16.5.0 Darwin Kernel Version 16.5.0
Comment 3 Marek Safar 2017-06-01 21:12:45 UTC
I tried to reproduce it with VSfM but could not so presumably this issue has been fixed between 4.8 and 5.2