15

I'm developing a Windows Phone 8.1 app that also targets Android(Xamarin)

As ever I added my string resources(.resx) on a PCL and referenced them on my launcher project to use it on my views, this all works fine on WP 8.1 silverlight but on the WinRt when I configure the project to release and run it on a device, for some reason I always get a MissingManifestResourceException. I've tried every solution for this problem out there without any success.

Note that on the emulator everything works fine, when the solution configurator is set to Debug it also works on both device and emulator. The only combination here is device and Release.

The app source code is on Github.

I was able to create a simple project to replicate this issue, basically it is a WP 8.1 app and a PCL project with the embedded resources, Download Link

Anyone has any ideas?

EDIT: After making some more testing I tried running an old Windows 8.1 app that I've done with the same localisation model and the same issue appeared so it seams to be a tool issue and not a configuration issue, since the Windows 8.1 app is on the market and everything went fine back there.

DVD
  • 1,744
  • 3
  • 17
  • 34
  • I think you should localization/globalization like in Windows Store apps and not like we did in WP8.0... You should use a Resources.resw file that will be converted to a pri, which will be load. – saramgsilva Oct 01 '14 at 13:09
  • The thing is that my portable view models use the resources files, changing to resw would mean that the other modules of my app couldn't use any globalized resources without a huge effort on abstracting the resources. – DVD Oct 01 '14 at 13:13
  • I use DI for define the locationservice and localized resource everywhere... is not complicate – saramgsilva Oct 01 '14 at 13:34
  • I didn't say it was complicated but it takes a huge effort since you have to implement for the 4 platforms, pass one more service via constructor (or have it statically somewhere) and as always can be error prone. XD – DVD Oct 01 '14 at 13:38

4 Answers4

11

Our team ran into a similar issue which was tracked down to the runtime and not the PCL, WinRT component, or application package. That is, the resources exist within the PCL assembly, within the application package resources.pri file, but just cannot be found at runtime.

There is an active Microsoft Connect report here:

https://connect.microsoft.com/VisualStudio/feedback/details/991028/issue-using-resx-files-on-winrt-apps-windows-phone-and-windows

Our workaround was for the WinRT component to inject into each generated Resources class of each referenced PCL our own derived ResourceManager which redirected the call to the WinRT ResourceLoader instead. I've written a blog post that describes that workaround:

http://blogs.msdn.com/b/philliphoff/archive/2014/11/19/missingmanifestresourceexception-when-using-portable-class-libraries-in-winrt.aspx

Phil Hoff -- MSFT
  • 2,006
  • 12
  • 9
  • Thanks for the reply. Your solution worked perfectly (both win8 and wp8.1) ;). The MS connect report is actually from me also lool. One thing that is still bothering me is what did they change to make this error popup. I had to do this workaround to all my old Win 8.1 apps... Again many Thanks! – DVD Nov 24 '14 at 17:39
9

I got to the bottom of this today. While bundling the app package, resources in dependencies that are not for a language being used by the app are stripped out. To prevent this from happening, add the following assembly-level attribute to your application.

using System.Resources;

[assembly: NeutralResourcesLanguage("en")]
bricelam
  • 28,825
  • 9
  • 92
  • 117
  • Try this simpler solution first. This worked for me. – ezaspi Oct 28 '15 at 12:21
  • FYI: don't forget to set the PCL's Neutral language to the same otherwise this solution won't work. You can do this by modifying the PCL's AssemblyInfo.cs and addig this line: [assembly: NeutralResourcesLanguage("en")]. Or right click on the project -> Properties -> Library -> Assembly Information -> Neutral language. http://imgur.com/XPEojAP – Adam Ivancza Mar 03 '16 at 17:38
  • For those who are, like me, creating an UWP app from a Xamarin.Forms app and using a PCL for string resources, this is the way to go. Thanks, you made my day, after losing many hours on this. – Theos May 26 '16 at 08:30
  • Add to which assembly -- the UWP app assembly? The resource assembly? Every assembly in the project? – William Jockusch Nov 26 '16 at 16:52
  • @WilliamJockusch I only needed to add it to the PCL assembly that had the resources. It worked without the attribute on the UWP assembly or anything else. – RandomEngy May 12 '17 at 17:33
0

I had the same behaviour. Today I created a new PCL Library (with another name) and copied the resx file to this project. I modified all references and everything just works fine in my WinRt (Windows Store) App now!

There was the string 'resources' in the portable class library name. Perhaps this was the problem!

dschüsä
  • 657
  • 5
  • 16
  • Not the case since in here I can replicate the issue creating new project and solutions. Please recheck it, sometimes it works at the first time but the subsequent deploys the same error appears ;). I ended up submitting an issue on http://social.msdn.microsoft.com/Forums/windowsapps/en-US/ea01b44b-f0d5-4ed1-a044-93cddfe88941/missingmanifestresourceexception-on-windows-phone-81-with-resx-resources?forum=wpdevelop – DVD Oct 06 '14 at 14:35
  • It still works in my Windows Store App. No idea why this hasn't worked before. – dschüsä Oct 08 '14 at 05:42
  • Can you tell me your vs environment ? – DVD Oct 08 '14 at 09:03
  • 1
    Visual Studio Premium 2013 Update 3. Project is a C# PCL (.NET 4.5.1, WP 8.1, WinStore 8.1) without 'resources' in its name and no file has 'resources' (with 'resources' in project name I got a MissingManifestResourceException but I didn't try to reproduce it). If I read your post title and your post content I'm not sure if you get the Exception in your Windows Store App or in your Windows Phone App? I got the exception in my Windows Store App. This is perhaps the difference between our configurations - that's also why I mention it in my answer several times. – dschüsä Oct 09 '14 at 06:13
  • I get the exception on both xDD, if you can please try to download my project (http://1drv.ms/1rLdoHw test.rar) and try it out ;) – DVD Oct 09 '14 at 07:58
  • Your application works fine on my system. Even the second and third time I publish this one... – dschüsä Oct 09 '14 at 11:28
  • Now this is strange lool, tried on a bunch of pcs none of them worked, guess i will did into this issue again. – DVD Oct 09 '14 at 11:38
  • How about to rename your resx file in something without 'Resources' in its name? – dschüsä Oct 09 '14 at 13:35
  • Just tried same outcome (note I tested in 3 pcs) :S – DVD Oct 09 '14 at 14:52
0

I am able to reproduce this issue launching DVD sample and unfortunately in my project. I have an WP Silverlight 8.1 project registering a Windows Runtime Component Background Task and both of them using a Portable Class Library sharing some common localized strings as resources (.resx), among other things. The exception is thrown from Background Task when calling any property to get strings on generated .Design.cs class (only Release + Device).

In order to fix this I tried, without success, to use directly ResourceManager and/or to add .resx files directly into the Background Task.

I ended-up porting needed strings to .resw files and use the new "WinRT preferred" way via Windows.ApplicationModel.Resources.ResourceLoader in the Background Task project.

Seems to me that ResourceManager is not compatible with Windows Runtime anymore in release.

This is not necessary an answer, but is better than nothing since I do not have 50 reputation points for a comment.

cosmo
  • 187
  • 2
  • 11
  • Hi, thanks for posting, I'm trying to avoid that because it will break all the previous Windows 8 projects that I had, but the new ones that I will begin I will definitely use the resw to avoid more wasted time. – DVD Oct 13 '14 at 14:28