Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force logical name for generated resources #2899

Merged
merged 2 commits into from Oct 26, 2019

Conversation

DasSkelett
Copy link
Member

@DasSkelett DasSkelett commented Oct 22, 2019

Problem

I'm trying out JetBrain's .NET IDE, "Idea" (thanks free student license ;) )
I couldn't run CKAN built with it, it always threw MissingManifestResourceException exceptions.

Cause

When Rider builds the GUI, it uses a different naming scheme for generated .resources file (.resources files are generated from .resx files before bundling them in the final assembly). To be exact, it appears that it uses AssemblyName.ResourceFileNameBase instead of FullNamespace.ResourceFileNameBase > CKAN.Resources*.resources instead of CKAN.Properties.Resources*.resources.
But not for all .resx/.resources files, only for those in the CKAN-GUI/Properties/ directory, so CKAN-GUI/Properties/Resources*.resx.

However, this only affects runtime, not compile time.
When the first resource (ksp.png) should be loaded, Resources.ResourceManager is accessed, which tries to find the embedded resource.

[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null))
{
resourceMan = new SingleAssemblyResourceManager("CKAN.Properties.Resources", typeof(Resources).Assembly);
}
return resourceMan;
}
}

It can't find it because of the wrong name, but doesn't care and returns a valid ResourceManager object.
mscorlib tries to find ksp.png with the returned ResourceManager, but can't find it either, because there's nothing "in" it.

An exception similar to this one will be thrown:

System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "CKAN.Properties.Resources.resources" was correctly embedded or linked into assembly "CKAN-GUI" at compile time, or that all the satellite assemblies required are loadable and fully signed.
  at System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing (System.String fileName) [0x000bf] in <285579f54af44a2ca048dad6be20e190>:0
  [...]
  at CKAN.Properties.Resources.get_ksp () [0x00001] in /home/DasSkelett/git/CKAN/GUI/Properties/Resources.Designer.cs:172
  at CKAN.MainModInfo.InitializeComponent () [0x0194a] in /home/DasSkelett/git/CKAN/GUI/MainModInfo.Designer.cs:499
  at CKAN.MainModInfo..ctor () [0x0000f] in /home/DasSkelett/git/CKAN/GUI/MainModInfo.cs:29
  at at (wrapper remoting-invoke-with-check) CKAN.MainModInfo..ctor()
  at CKAN.Main.InitializeComponent () [0x002b1] in /home/DasSkelett/git/CKAN/GUI/Main.Designer.cs:92
  at CKAN.Main..ctor (System.String[] cmdlineArgs, CKAN.KSPManager mgr, CKAN.GUIUser user, System.Boolean showConsole) [0x000a3] in /home/DasSkelett/git/CKAN/GUI/Main.cs:178
  at at (wrapper remoting-invoke-with-check) CKAN.Main..ctor(string[],CKAN.KSPManager,CKAN.GUIUser,bool)
  at CKAN.GUI.Main_ (System.String[] args, CKAN.KSPManager manager, System.Boolean showConsole) [0x00047] in /home/DasSkelett/git/CKAN/GUI/Program.cs:36
  at CKAN.GUI.Main (System.String[] args) [0x00001] in /home/DasSkelett/git/CKAN/GUI/Program.cs:16

Solution

Thanks to https://blogs.msdn.microsoft.com/msbuild/2007/10/19/manifest-resource-names-changed-for-resources-files/
and especially https://stackoverflow.com/a/7090337 I found a way to force specific names for the generated resources.
They are now forced to FullNamespace.ResourceFileNameBase, as specified here: https://docs.microsoft.com/en-us/dotnet/api/system.resources.resourcemanager?view=netframework-4.8#exception

The baseName parameter in the ResourceManager(String, Assembly) constructor does not specify the name of a .resources file. The name should include the resource file's fully qualified namespace but not its file name extension. Typically, resource files that are created in Visual Studio include namespace names, but resource files that are created and compiled at the command prompt do not.

This won't change the name of the .resources files itself (see _build/out/CKAN-GUI/Debug/obj/), they are still named differently if generated by Rider. But the logical name does, and that's the one important to new SingleAssemblyResourceManager().


The normal build with the build script / cake still works on my system ;).
But it would be nice if someone using a different IDE (@HebaruSan with Visual Studio?) can test if it's still building fine too.

@DasSkelett DasSkelett added GUI Issues affecting the interactive GUI Build Issues affecting the build system Linux Issues specific for Linux labels Oct 22, 2019
@HebaruSan

This comment has been minimized.

@HebaruSan

This comment has been minimized.

@DasSkelett
Copy link
Member Author

Huh, the filter is totally Deutsch on my system.

Can you try again with the new commit? I weren't sure about this, so let's try what it does..

@HebaruSan
Copy link
Member

No change. I'll see if I can learn anything from inspecting the assembly...

@HebaruSan

This comment has been minimized.

@DasSkelett
Copy link
Member Author

DasSkelett commented Oct 24, 2019

Now that's interesting. My mono packs the dlls no problem, the manifests are the same until the very last bit, both have the CKAN.Properties.de-de.resources and CKAN.Properties.en-US.resources.
You are also using mono 6.4.0, right?

@HebaruSan

This comment has been minimized.

@DasSkelett
Copy link
Member Author

That's the exact same versions I have :/
Can you do a rm -r _build/out/, rebuild, and look if

  • CKAN.Properties.Resources.de-DE.resources
  • CKAN.Properties.Resources.en-US.resources
  • CKAN.Properties.Resources.resources
    are in _build/out/CKAN-GUI/Debug/obj/?

Also you already pulled the second commit, right?

@HebaruSan
Copy link
Member

Can you do a rm -r _build/out/, rebuild, and look if

  • CKAN.Properties.Resources.de-DE.resources
  • CKAN.Properties.Resources.en-US.resources
  • CKAN.Properties.Resources.resources
    are in _build/out/CKAN-GUI/Debug/obj/?

Yes, they're there. And somehow that fixed it:

image

Maybe the files weren't being overwritten properly? Maybe some old filenames were confusing it? Either way, it looks fine now.

Also you already pulled the second commit, right?

I've been testing this without a local branch, in "detached HEAD" state.

git fetch --all
git checkout DasSkelett/fix/idea-build

Kind of handy when I know I won't be adding my own commits.

@HebaruSan HebaruSan merged commit f80406d into KSP-CKAN:master Oct 26, 2019
@DasSkelett DasSkelett deleted the fix/idea-build branch October 26, 2019 21:57
@HebaruSan HebaruSan mentioned this pull request Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Issues affecting the build system GUI Issues affecting the interactive GUI Linux Issues specific for Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants