Bug 47808 - System.MissingMethodException: Default constructor not found for type HPE.Xamarin.Forms.Utils.[Interface]
Summary: System.MissingMethodException: Default constructor not found for type HPE.Xam...
Status: RESOLVED INVALID
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-11-24 02:51 UTC by Sid Dubey
Modified: 2016-11-29 05:37 UTC (History)
6 users (show)

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


Attachments
Library Solution (HPE.Xamarin.Forms.Utils) (552.83 KB, application/x-zip-compressed)
2016-11-24 02:53 UTC, Sid Dubey
Details
Sample App for Repro (145.50 KB, application/x-zip-compressed)
2016-11-24 02:53 UTC, Sid Dubey
Details
Screenshot - UWP (Success) (70.02 KB, image/png)
2016-11-24 02:54 UTC, Sid Dubey
Details
Screenshot - Android (Failure) (88.66 KB, image/png)
2016-11-24 02:55 UTC, Sid Dubey
Details
Generated nuget package (95.11 KB, application/x-zip-compressed)
2016-11-24 02:56 UTC, Sid Dubey
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 INVALID

Description Sid Dubey 2016-11-24 02:51:21 UTC
Customer have created a library solution HPE.Xamarin.Forms.Utils (Attached) using Xamarin.Forms.Dependency to execute native code using a shared project. This solution on compiling generates a nuget package HPE.Xamarin.Forms.Utils.1.0.14.nupkg(Attached). 

The nuget package is consumed in XamarinTestApp (Attached) which is a Xamarin Forms Application. When XamarinTestApp us executed for UWP the native code is executed correctly (Screen Attached) , However for Android on Android it always crashes, (Screen Attached) with error System.MissingMethodException: Default constructor not found for type HPE.Xamarin.Forms.Utils.ILocalDevice. 

As code follows the documentation https://developer.xamarin.com/guides/xamarin-forms/dependency-service/introduction/ and appears everything is in place including the default constructor. (LocalDevice.cs in library project). 

#if __ANDROID__
    
public class LocalDevice : Java.Lang.Object, ILocalDevice

#else
    
public class LocalDevice : ILocalDevice

#endif

and also registering it manually via

Xamarin.Forms.DependencyService.Register<HPE.Xamarin.Forms.Utils.ILocalDevice>();

#if __ANDROID__
    
[Android.Runtime.Preserve]

#endif
    
public LocalDevice() // Necessary for Xamarin DependencyService to work
    {
    }

Install https://marketplace.visualstudio.com/items?itemName=NuProjTeam.NuGetPackageProject <https://marketplace.visualstudio.com/items?itemName=NuProjTeam.NuGetPackageProject before opening the library project.
Comment 1 Sid Dubey 2016-11-24 02:53:08 UTC
Created attachment 18633 [details]
Library Solution (HPE.Xamarin.Forms.Utils)
Comment 2 Sid Dubey 2016-11-24 02:53:47 UTC
Created attachment 18634 [details]
Sample App for Repro
Comment 3 Sid Dubey 2016-11-24 02:54:15 UTC
Created attachment 18635 [details]
Screenshot - UWP (Success)
Comment 4 Sid Dubey 2016-11-24 02:55:13 UTC
Created attachment 18636 [details]
Screenshot - Android (Failure)
Comment 5 Sid Dubey 2016-11-24 02:56:10 UTC
Created attachment 18637 [details]
Generated nuget package
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2016-11-24 03:03:56 UTC
Please provide version info for the environment where the issue was observed as part of the standard information on bug reports.  For this particular bug, please include at a minimum the Xamarin.Android version (or XamarinVS version) as well as the Xamarin.Forms version.  See also [1, 2].


[1] https://developer.xamarin.com/guides/cross-platform/troubleshooting/questions/howto-file-bug/
[2] http://open.xamarin.com/contribute
Comment 7 Brendan Zagaeski (Xamarin Team, assistant) 2016-11-24 03:09:16 UTC
Additionally, please clearly list the steps to replicate the problem, preferably using a numbered list.  As also linked on [1], please see the "Description" section on [2] for a rough template of the recommended content and format for the bug Description.


[1] https://developer.xamarin.com/guides/cross-platform/troubleshooting/questions/howto-file-bug/

[2] https://bugzilla.xamarin.com/page.cgi?id=bug-writing.html
Comment 8 Sid Dubey 2016-11-24 03:20:03 UTC
-----------------------------------
Xamarin.Forms version=2.3.3.168
-----------------------------------
Visual Studio Info 
-------------------
Microsoft Visual Studio Enterprise 2015
Version 14.0.25421.03 Update 3
Microsoft .NET Framework
Version 4.6.01586

Installed Version: Enterprise

Architecture and Modeling Tools   00322-90200-21579-AA533
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   00322-90200-21579-AA533
Microsoft Visual Basic 2015

Visual C# 2015   00322-90200-21579-AA533
Microsoft Visual C# 2015

Visual C++ 2015   00322-90200-21579-AA533
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ENU   00322-90200-21579-AA533
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   7.12.01115.4
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015 (RC1 Update 1)   14.1.20203.0
ASP.NET and Web Tools 2015 (RC1 Update 1)

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/

Azure App Service Tools v2.9   14.0.20316.0
Azure App Service Tools v2.9

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.0.6000.0
Microsoft Azure Data Lake Tools for Visual Studio

Command Bus, Event Stream and Async Manager   Merq
Provides ICommandBus, IEventStream and IAsyncManager MEF services for loosely coupled Visual Studio extension components communication and integration.

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

GitHub.VisualStudio   2.1.1.0
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

GradleBindings.VisualStudio   1.0
Creates Xamarin Android Binding projects from a gradle file.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

Microsoft Azure HDInsight HQL Service   2.0.6000.0
Language service for Hive query

Microsoft Azure HDInsight Tools for Visual Studio   2.0.6000.0
An integrated development environment for HDInsight application development.

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2015 - v2.9.40323.3

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

NuProjPackage   1.0
NuGet Package Project System

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

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript   1.8.34.0
TypeScript tools for Visual Studio

Visual Studio Tools for Apache Cordova   Update 10
Visual Studio Tools for Apache Cordova

Visual Studio Tools for Universal Windows Apps   14.0.25420.01
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.

Xamarin   4.2.1.60 (47830f6)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Inspector Support   0.8.0.0 (dc081aa)
Adds support for inspecting Xamarin and WPF apps.

Xamarin.Android   7.0.2.37 (ce955cc)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS   10.2.1.5 (44931ae)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 9 Sid Dubey 2016-11-24 03:26:38 UTC
Steps to replicate 
-------------------
1. Download the attached nuget package file on the local drive. 
2. Open XamarinTestApp in Visual Studio 2015 
3. Using Tools -> Nuget Package Manager -> Package Manager Settings -> Package Source : Add a new source by Naming it and browsing the nuget package file in Step 1
4. Build the Solution. 
5. Set UWP as startup -> Run -> It Runs fine (Screen Attached) 
6. Set Android as startup -> Run -> It fails (Screen Attached) 




(In reply to Brendan Zagaeski from comment #7)
> Additionally, please clearly list the steps to replicate the problem,
> preferably using a numbered list.  As also linked on [1], please see the
> "Description" section on [2] for a rough template of the recommended content
> and format for the bug Description.
> 
> 
> [1]
> https://developer.xamarin.com/guides/cross-platform/troubleshooting/
> questions/howto-file-bug/
> 
> [2] https://bugzilla.xamarin.com/page.cgi?id=bug-writing.html
Comment 10 Brendan Zagaeski (Xamarin Team, assistant) 2016-11-24 04:13:17 UTC
## Confirmation status: invalid test case

1. In the attached app test case from Comment 2, the "XamarinTestApp.Droid" project does not include a reference to the platform-specific Xamarin.Android assembly from the NuGet package:
> HPE.Xamarin.Forms.Utils.Droid.dll
2. Removing and re-adding the NuGet package "HPE.Xamarin.Forms.Utils" successfully added the reference to "HPE.Xamarin.Forms.Utils.Droid.dll" into the "XamarinTestApp.Droid" project.

3. Rebuilding and redeploying the project fixed the error message from Comment 4.


In short, the error message was accurate and pointed to the cause of the problem.


If adding the NuGet package to the Xamarin.Android package consistently fails to add the Android-specific package as a reference in some Visual Studio environment, that would be a behavior of the NuGet Package Manager extension.  It could indicate that the NuGet package is not conforming to all of the conventions that other NuGet packages for Xamarin.Android use.