Bug 4453 - Localization in common project fail unless some class is referenced
Summary: Localization in common project fail unless some class is referenced
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.2
Hardware: PC Mac OS
: --- normal
Target Milestone: 7.2.0 (iOS 7.1)
Assignee: Sebastien Pouliot
Depends on:
Reported: 2012-04-15 17:31 UTC by Ian
Modified: 2015-05-14 16:21 UTC (History)
3 users (show)

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

Common.Localization (33.19 KB, image/jpeg)
2012-04-15 17:31 UTC, Ian

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:

Description Ian 2012-04-15 17:31:07 UTC
Created attachment 1678 [details]

I have a common project with the localization info for all my apps, Common.Localization.csproj. In order for the localization, like fr.lproj to appear in the resulting build, I have to create a dummie class in the common project, wrap it with a [Preserve] attribute AND reference it in the app.

If there is no dummie class made, there is no common.localization.dll made and the localization files are not sent to the .app

Here's how I make it work:

Create a dummie class in common.localization.csproj

using System;
using MonoTouch.Foundation;

//Needed to make this DLL compile and have it's resources included
namespace Common.Localization
	public class DummieClass
		public DummieClass ()

Now in the AppDelegate

var d = new DummieClass();

Then it works.

I am hoping this is a bug as I'd rather not have write dummie references in all my apps just to get the localization copied over to the app. It's be ok if I just have a dummie class with [Preserve], but to have to reference it too?

Photo attached.

Version info:
	Mono 2.10.9 (tarball Tue Mar 20 15:31:37 EDT 2012)
	GTK 2.24.10
	GTK# (
Apple Developer Tools:
	 Xcode 4.3.1 (1176)
	 Build 4E1019
Monotouch: 5.2.10
Comment 2 Sebastien Pouliot 2012-04-16 09:18:19 UTC
That's likely a linker issue, i.e. removing an assembly without any code left inside it. I'll check this, thanks for the bug report.
Comment 3 Sebastien Pouliot 2012-04-16 14:38:06 UTC
So this is not a linker issue (the same thing occurs, on device, without linking). Once compiled there's no reference to the assembly and it is (presently) ignored (i.e. not copied) even if it contains resources.

Your workaround ensure a reference is compiled in (so it's not excluded for being extraneous) and the [Preserve] ensure the code is not linked out (which could remove the reference when linked).

> It's be ok if I just have a dummie class with [Preserve],

We might be able to remove this requirement. E.g. if there's no code but some resources are present then we could copy the assembly in the bundle. 

That needs some testing so we do not end up with SDK assemblies (that include resources) requiring extra space in applications (for unused resources).

> but to have to reference it too?

Sadly that requirement is harder to remove. 

Without a reference mtouch would not even know about the resource assembly (as it would not be on its command line) and the tool cannot just bring every .dll it finds (some solutions have a lot of extraneous assemblies that are not meant to be shipped with the app).

Now we could have another way to "mark" them but it would not be any simpler than the (existing) "add reference". Also there is IMO a reference between them - as the main app will refer to the resource-only assembly.
Comment 4 Ian 2012-04-16 15:29:44 UTC
In this case I would say the risk-reward is not favorable. I recommend leaving it as is.
Comment 7 PJ 2013-11-19 16:44:52 UTC
This bug was targeted for a past milestone, moving to the next non-hotfix active milestone.
Comment 8 Sebastien Pouliot 2015-05-14 16:21:44 UTC
It's now possible to preserve a type from another assembly, e.g.

> [assembly: Preserve (typeof (Common.Localization.DummieClass))]

which reduce a bit the code required in both the main and resource .dll. However it still requires a reference to exists.