Bug 7058 - [ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Default constructor not found for type fh.backend.transactions.FHOpSettingsDownloadResponse.
Summary: [ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Default con...
Status: RESOLVED NORESPONSE
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.4.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-09-11 05:44 UTC by Gabriel Dana
Modified: 2013-12-05 18:35 UTC (History)
3 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 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 NORESPONSE

Description Gabriel Dana 2012-09-11 05:44:59 UTC
Error appears in debug build, but in release works ok.


[ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Default constructor not found for type fh.backend.transactions.FHOpSettingsDownloadResponse.
  at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00095] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:329 
  at System.Activator.CreateInstance (System.Type type) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:224 
  at fh.backend.gw.FHGatewayBase.buildResponse (System.Type responseType) [0x00000] in /Users/quickwebwork/Desktop/Work/SVN/modules-ios/FileHopperSVN/fh.ios/fh.ios/library/fh.backend/gw/FHGatewayBase.cs:280 
  at fh.backend.gw.FHGatewayBase.process (fh.backend.transactions.IFHGWOpRequest op, fh.backend.transactions.IFHGWOpResponse& response) [0x00017] in /Users/quickwebwork/Desktop/Work/SVN/modules-ios/FileHopperSVN/fh.ios/fh.ios/library/fh.backend/gw/FHGatewayBase.cs:394 
  at fh.backend.gw.FHGateway.SettingsDownload (System.String workstation, System.String settingsName, System.String& fname) [0x000a0] in /Users/quickwebwork/Desktop/Work/SVN/modules-ios/FileHopperSVN/fh.ios/fh.ios/library/fh.backend/gw/FHGateway.cs:842 
  at fh.engines.SyncEngine.refreshServerHash (System.Boolean& isChanged, System.String& serverHash) [0x00022] in /Users/quickwebwork/Desktop/Work/SVN/modules-ios/FileHopperSVN/fh.ios/fh.ios/library/fh.engines/SyncEngine.cs:129 
  at fh.engines.SyncEngine.Sync () [0x0000d] in /Users/quickwebwork/Desktop/Work/SVN/modules-ios/FileHopperSVN/fh.ios/fh.ios/library/fh.engines/SyncEngine.cs:221 
  at fh.engines.FHCloudEngine.performFullSync (fh.engines.SyncEngineRequest item) [0x000ae] in /Users/quickwebwork/Desktop/Work/SVN/modules-ios/FileHopperSVN/fh.ios/fh.ios/library/fh.engines/FHCloudEngine.cs:104 
  at fh.engines.FHCloudEngine.processWorkItem (fh.engines.SyncEngineRequest item) [0x0002e] in /Users/quickwebwork/Desktop/Work/SVN/modules-ios/FileHopperSVN/fh.ios/fh.ios/library/fh.engines/FHCloudEngine.cs:47 
  at fh.core.threading.ThreadEx`1[fh.engines.SyncEngineRequest].runner () [0x00000] in <filename unknown>:0 
  at System.Threading.Thread.StartInternal () [0x0001d] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/Thread.cs:697
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-09-11 06:06:13 UTC
Do you have a test case we can use to reproduce this?
Comment 2 Gabriel Dana 2012-09-11 08:43:11 UTC
Thank you for rapid response.

Here is the line that crashes the application in debug mode (the one with Activator.Create....):

		private IFHGWOpResponse buildResponse (Type responseType)
		{
			object rawRespInst = Activator.CreateInstance(responseType);
			IFHGWOpResponse iresp = rawRespInst as IFHGWOpResponse;

			if(iresp==null)
			{
				throw new Exception("Invalid response type");
			}

			return iresp;
		}


The responseType is random (there are several object types that generate the error) - one of them is:

	public class FHOpSettingsDownloadResponse:IFHGWOpResponse
	{
		public enum Status
		{
			OK = 1,
			ERROR = 0x10
		};

		public Status opStatus;

		public FileDownloadParam content;

		public override bool process (ref byte[] rawResponseContent)
		{
                    return true;
		}	
	}

	public abstract class IFHGWOpResponse
	{
		public FHGWOpResponseStatus status;

		public virtual bool process(ref byte[] rawResponseContent)
		{
			return true;
		}

		public virtual bool processStream(IFHGWOpRequest req,object stream, string fsTarget)
		{
			return true;
		}
	};
Comment 3 Sebastien Pouliot 2012-09-11 08:48:17 UTC
Compare your Debug and Release settings. They likely have different "Link behavior" specified.

If your project (e.g. Debug) uses "Link all" then the linker will remove unused code from your application (to save space and minimize deployment time). That means unused default constructor will also be removed. Since this is static analysis the use of reflection (e.g. Activator) won't be seen as a need to keep them. 

You can either switch to "Link SDK" or add [Preserve] attributes on members (like your default .ctor) that your application needs to have at runtime.
Comment 4 Gabriel Dana 2012-09-11 08:57:49 UTC
Thank you Sebastien.

It works with the same settings.
Comment 5 Sebastien Pouliot 2012-09-11 09:06:55 UTC
We'll need more details to help, starting with:

* You linker settings: "Link all" or "Link SDK"

E.g. You can also have "#if DEBUG" region in your source code that could bring more code into Debug than inside Release. That can influence how reflection will be able to use them at runtime.

* Do you see the same results on the iOS simulator and on devices ? (for both Debug and Release configuration).

Also attach (you can mark them private) the full build logs (from MD "Build Output" in the "Error List" pad)  for both Debug and Release builds.
Comment 6 PJ 2013-11-19 17:05:31 UTC
This bug has been in the NEEDINFO state with no changes for the last 90 days. Can we put this back into the NEW or CONFIRMED state, or are we still awaiting response?

If there is no change in the status of this bug over the next two weeks, this bug will be marked as NORESPONSE.
Comment 7 PJ 2013-12-05 18:35:56 UTC
This bug has not been changed from the NEEDINFO state since my previous comment, marking as RESOLVED NORESPONSE.

Please feel free to REOPEN this bug at any time if you are still experiencing the issue. Please add the requested information and set the bug back to the NEW (or CONFIRMED) state.