Search code examples
xamarin.androidvisual-studio-2017

'Resource.Designer.cs' keeps old namespace after it has been changed throughout entire solution


At some point project identity was modified and i reflected that in code by renaming the solution, project, assembly and default namespace, with all corresponding folders - all instances of a name that i could find. I also used Notepad2 to fix the contents of solution and project files.
Project Properties - Application tab Note: Namespace in code was changed using VStudio's Rename feature.

Since then every time Resource.Designer.cs file gets re-generated, it pulls the old namespace in (?!), breaking the reference to automatic Resource class, which defines resource IDs: Resource.Designer.cs - auto-generated

Obviously, i try to fix this: Resource.Designer.cs - edited

And in some cases it will immediately get re-generated again - you guessed it - with the old name, but sometimes(!) it will accept my edit, save it and let the project be actually compiled and run: Compilation happily on the merry way!

I've tried Clean and Rebuild commands multiple times for both project and solution, restarted VStudio, rebooted Windows.. No dice, it keeps happening.

App's TargetPlatform is 7.1, MinimumVersion is 4.3, all 5 supported architectures are enabled. VStudio - 15.5.4, .NET - 4.7.03056, Xamarin - 4.8.0.757, Xamarin.Android SDK - 8.1.3.0.

Just found this in the Similar Questions list: Ambiguous reference intellisense error from Resource.Designer.cs. Looked promising, so i did the following:

  1. Closed solution in VisualStudio.
  2. Removed entirely \bin and \obj subfolders in File Explorer.
  3. Edited Resource.Designer.cs, so it has correct (new) namespace: J7987ca.
  4. Added 'AndroidUseManagedDesignTimeResourceGenerator' to J7987ca.csproj, as advised.
  5. Opened the solution, and here's the result - old namespace is back: Re-opening solution after purging \bin and \obj subfolders

I guess, i can start with a clean slate and re-create entire solution from scratch with a new name, but for the Love of God, why do i have to do that? And where does it pull the old name from?!


Solution

  • My last image shows <RootNamespace>J7980ca</RootNamespace> - the old name. I did not pay much attention to re-check that tab after re-opening solution, because such an awful glitch would never occure to me: i never had problems saving values in those VS "dialogs" previously.

    It turns out that changing Default Namespace in Project Properties does not take effect!
    I verified it twice.

    Mind you, Assembly Name was saved, so i'm at a loss of wits to explain, how all this is happening.

    As soon as i edited .csproj in Notepad2 re-opening the solution happily put proper namespace into Resources.Designer.cs and allowed compilation.