Bug 28755 - Unable to load classes from external assembly (StyleCop)
Summary: Unable to load classes from external assembly (StyleCop)
Status: REOPENED
Alias: None
Product: Tools
Classification: Mono
Component: xbuild ()
Version: unspecified
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-04-03 17:04 UTC by Cody Beyer (MSFT)
Modified: 2015-07-21 00:20 UTC (History)
7 users (show)

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

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 28755 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:
Status:
REOPENED

Description Cody Beyer (MSFT) 2015-04-03 17:04:46 UTC
### Description

When attempting to compile a simple app which loads the StyleCop library from NuGet, an error is given stating: 

Error: Error initializing task StyleCopTask: The classes in the module cannot be loaded. (TestStyleCop)

### Regression Status

This application builds in 8.8.2.4

### Build Log

https://gist.github.com/CodyBeyer/07f02ba107fb8c47b8eb

### Test Case

https://www.dropbox.com/s/7vyrzi0rpxtj8rg/TestStyleCop%202.zip?dl=0

### Steps to Reproduce

1. Open attached test case
2. Attempt to build test case

### Expected Results

The app should build with packages included

### Actual Results

App fails with the above error

### Version

=== Xamarin Studio ===

Version 5.9 (build 388)
Installation UUID: 48d20a9d-ef72-44de-8690-d8fa00873cc7
Runtime:
	Mono 4.0.0 ((detached/21d849b)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000121

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: 8.10.0.197 (Business Edition)
Hash: 4dac6bf
Branch: master
Build date: 2015-04-01 21:55:11-0400

=== Xamarin.Android ===

Version: 5.1.0.100 (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.2   (API level 17)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.0.197 (Business Edition)

=== Build Information ===

Release ID: 509000388
Git revision: 027c5efa6f92249fd2e614535965159c0a7c0fe6
Build date: 2015-04-01 19:12:53-04
Xamarin addins: a6779639267bbe31df3fd6958be4ecae82665b7e

=== Operating System ===

Mac OS X 10.10.2
Darwin Codys-MBP 14.1.0 Darwin Kernel Version 14.1.0
    Thu Feb 26 19:26:47 PST 2015
    root:xnu-2782.10.73~1/RELEASE_X86_64 x86_64
Comment 1 Udham Singh 2015-04-06 14:20:56 UTC
I have checked this issue with the help of sample app and test steps given in bug description and able to reproduce the reported behaviour. Please refer the screencast : http://www.screencast.com/t/8j3mToSRSV45

Build Output : https://gist.github.com/Udham1/b2e5cacb586f5eb20006
Ide Log : https://gist.github.com/Udham1/0a347789bf5624e3821b

Environment Info :

=== Xamarin Studio ===

Version 5.9 (build 397)
Installation UUID: ce927b2a-2c07-44c5-b186-09cfdafba6dc
Runtime:
	Mono 4.0.0 ((detached/21d849b)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000121

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.Mac ===

Version: 2.0.0.141 (Business Edition)

=== Xamarin.iOS ===

Version: 8.10.0.203 (Business Edition)
Hash: 1487cb5
Branch: master
Build date: 2015-04-03 17:55:12-0400

=== Xamarin.Android ===

Version: 5.1.0.103 (Business Edition)
Android SDK: /Users/xamarin76/Desktop/android-sdk-macosx
	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.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Build Information ===

Release ID: 509000397
Git revision: 1bdd327e84c6c816f639d99a5a72ef4b7f2737ce
Build date: 2015-04-04 05:49:53-04
Xamarin addins: 0ae4a1cee0fa2721e8f5e4bdaded0ebc95fe7d57

=== Operating System ===

Mac OS X 10.9.5
Darwin Xamarin76s-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 2 Jeffrey Stedfast 2015-04-07 14:49:54 UTC
Looks like a StyleCop bug to me:

	Target StyleCop:
: error : Error initializing task StyleCopTask: The classes in the module cannot be loaded.
		Build FAILED.
		Errors:
		
		/Users/codybeyer/Downloads/TestStyleCop/TestStyleCop/TestStyleCop.csproj (Build) ->
/Users/codybeyer/Downloads/TestStyleCop/packages/StyleCop.MSBuild.4.7.49.1/build/StyleCop.MSBuild.Targets (StyleCop target) ->
Comment 3 chorsfield 2015-04-07 19:16:12 UTC
Note this does work on prev versions of xamarin just not with this latest alpha bits.
Comment 4 Jeffrey Stedfast 2015-04-07 19:36:07 UTC
Yea, I get that, but it's the StyleCopTask that is failing, not any of the Xamarin.iOS build tasks.
Comment 5 Sebastien Pouliot 2015-04-07 21:12:40 UTC
This works correctly for me with XI 8.11 (master) [1] as well XI 8.8 (stable). In both cases I was using XS 5.8 (build 443).

@Udham or Cody: can you confirm (all) the versions (not just XI) used in the case this worked ? 

I'm curious to see if it's something related to XI or XS. We might not be able to support 3rd party tasks but if they expose bugs in our code then it's worth investigating.


[1] https://gist.github.com/spouliot/27e3b08c9d48f0bf66e6
Comment 6 Cody Beyer (MSFT) 2015-04-07 21:36:53 UTC
(In reply to comment #5)

> @Udham or Cody: can you confirm (all) the versions (not just XI) used in the
> case this worked ? 

Works: https://gist.github.com/CodyBeyer/e98bb054ae39fe8c1ce0

Fails: https://gist.github.com/CodyBeyer/453468c806dc5447953a

I should also note that the same components that failed in the link above, also failed running XS 5.8.2 (build 7). 

Thank you!
Comment 7 Sebastien Pouliot 2015-04-07 21:56:05 UTC
Thanks @Cody

I'll rebuild 8.10 tomorrow and see if it works for me. It's possible that the alpha build had a bug that was fixed since then (or is fixed only in master).
Comment 8 Sebastien Pouliot 2015-04-08 13:28:59 UTC
it's still works fine for me using a more recent XI 8.10 build.

$ mtouch --version
mtouch 8.10.0.223 (a643a13)

https://gist.github.com/spouliot/5624bbeff9cb75fac661


It looks like the current/published alpha had an issue that might already be fixed. 

I'm changing this to RESOLVED/FIXED and setting the milestone to 8.10 so that QA (not just me) will verify this again with a build that comes out from our bots. QA will re-open the bug if it still happens (in case it's something else specific to my setup).
Comment 10 chorsfield 2015-04-16 00:41:25 UTC
Could you have a new look at this.

The Problem is still happening on the new alpaha bits updated today

/Developer/MonoTouch/usr/bin/mtouch --version
mtouch 8.10.0.258 (c2c0012)



=== Xamarin Studio ===

Version 5.9 (build 427)
Installation UUID: ed9952d3-8924-4493-8ee2-e84801ce13f8
Runtime:
    Mono 4.0.0 ((detached/d136b79)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 400000143

=== Apple Developer Tools ===

Xcode 6.3 (7569)
Build 6D570

=== Xamarin.iOS ===

Version: 8.10.0.258 (Business Edition)
Hash: c2c0012
Branch: master
Build date: 2015-04-14 17:26:21-0400

=== Xamarin.Android ===

Version: 5.1.0.113 (Business Edition)
Android SDK: /Users/craighorsfield/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        2.3   (API level 10)
        4.0.3 (API level 15)
        4.4   (API level 19)
        5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)

=== Xamarin Android Player ===

Not Installed

=== Xamarin.Mac ===

Not Installed

=== Build Information ===

Release ID: 509000427
Git revision: 04666fd43a57b4782529cad9723ce1f54926fe6c
Build date: 2015-04-14 18:06:43-04
Xamarin addins: 791954691dfbc403676a103e52a0bb9754b9af29

=== Operating System ===

Mac OS X 10.10.3
Darwin Craigs-Mac-mini.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 11 Sebastien Pouliot 2015-04-16 08:24:03 UTC
The current bug status/milestone means it will be verified by QA before being closed.
Comment 12 Jeffrey Stedfast 2015-04-17 13:54:08 UTC
I added the following XML to the StyleCop targets file just above the <StyleCopTask ... bit:

    <Message Text="StyleCopTask" Importance="Normal" />
    <Message Text="  ProjectFullPath: $(MSBuildProjectDirectory)" Importance="Normal" />
    <Message Text="  SourceFiles:" Importance="Normal" />
    <Message Text="    %(StyleCopFiles.Identity)" Importance="Normal" />
    <Message Text="  AdditionalAddinPaths:" Importance="Normal" />
    <Message Text="    %(StyleCopAdditionalAddinPaths.Identity)" Importance="Normal" />
    <Message Text="  ForceFullAnalysis: $(StyleCopForceFullAnalysis)" Importance="Normal" />
    <Message Text="  DefineConstants: $(DefineConstants)" Importance="Normal" />
    <Message Text="  TreatErrorsAsWarnings: $(StyleCopTreatErrorsAsWarnings)" Importance="Normal" />
    <Message Text="  CacheResults: $(StyleCopCacheResults)" Importance="Normal" />
    <Message Text="  OverrideSettingsFile: $(StyleCopOverrideSettingsFile)" Importance="Normal" />
    <Message Text="  MaxViolationCount: $(StyleCopMaxViolationCount)" Importance="Normal" />


Here's the output of those lines:

StyleCopTask
  ProjectFullPath: /Users/fejj/Downloads/TestStyleCop/TestStyleCop
  SourceFiles:
    Main.cs
    AppDelegate.cs
    obj/iPhoneSimulator/Debug/Xamarin.iOS,Version=v1.0.AssemblyAttribute.cs
  AdditionalAddinPaths:
  ForceFullAnalysis: false
  DefineConstants: __UNIFIED__;__MOBILE__;__IOS__;DEBUG;
  TreatErrorsAsWarnings: true
  CacheResults: true
  OverrideSettingsFile: 
  MaxViolationCount: 0


And then I get:

: error : Error initializing task StyleCopTask: The classes in the module cannot be loaded.
Error initializing task StyleCopTask: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (System.Reflection.Assembly,bool)
 at System.Reflection.Assembly.GetExportedTypes () [0x00000] in <filename unknown>:0 
 at Microsoft.Build.BuildEngine.TaskDatabase.RegisterTask (System.String classname, Mono.XBuild.Framework.AssemblyLoadInfo assemblyLoadInfo) [0x00000] in <filename unknown>:0 
  at Microsoft.Build.BuildEngine.UsingTask.Load (Microsoft.Build.BuildEngine.TaskDatabase db) [0x00000] in <filename unknown>:0 
  at Microsoft.Build.BuildEngine.TaskDatabase.GetTypeFromClassName (System.String classname) [0x00000] in <filename unknown>:0 
  at Microsoft.Build.BuildEngine.BuildTask.get_Type () [0x00000] in <filename unknown>:0 
  at Microsoft.Build.BuildEngine.BuildTask.InitializeTask () [0x00000] in <filename unknown>:0 
  at Microsoft.Build.BuildEngine.BuildTask.Execute () [0x00000] in <filename unknown>:0


This is with git master (commit bce037d353e1c0be49d6298a8954a21beb69c013) of maccore, so it does not appear that this has been fixed.

The stack trace is all inside the MSBuild engine (aka xbuild) and so looks more like a Mono bug than a Xamarin.iOS MSBuild targets bug.

Here's my Mono version info:

Mono JIT compiler version 4.0.0 ((detached/d136b79 Mon Apr 13 14:40:59 EDT 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug 
	LLVM:          yes(3.6.0svn-mono-(detached/a173357)
	GC:            sgen
Comment 13 Jeffrey Stedfast 2015-04-17 13:55:55 UTC
I suspect the problem is that it is failing to load (one of?) the StyleCop assemblies that are bundled as part of the NuGet. Either because it is trying to load them from the wrong place or some other reason I don't know of.
Comment 14 Jeffrey Stedfast 2015-05-08 11:34:22 UTC
BTW, users on the forums have noted that downgrading to Mono 3.12 fixes this (it's only broken with Mono 4.0 apparently).