Exception when accessing resources

(Bartosz Antosik) #1

After compiling some old academic code, which is supposed to work with older version of Oxygene, I constantly run into the System.Resources.MissingManifestResourceException exception in the line, which loads an icon for the form:

self.Icon := (resources.GetObject('$this.Icon') as System.Drawing.Icon)

When I remove the line it fails elsewhere while trying to load a string from resources, so it seems quite constant problem when accessing resources.

Searching for a resolution I have found this which lead to reviewing Build Action settings for the .resx files in the project, which lead to two conclusions:

  1. For .resx files tight to the module (main.resx displayed as sub folder of main.pas) I can only choose Compile or Content from the VS 2017 GUI.
  2. I have manually changed this field in the project source to (suggested in the thread mentioned above) EmbeddedResource and it seems when using ILSpy tool that the resource finally IS embedded in the assembly, however

It still fails with the same exception.

I have also found this thread on your talk board which does not help but references this post, which subject sounds promising but when I try to click displays Sorry, you don't have access to that topic!.

Please help!

(marc hoffman) #2


This seems to be a bug in VS, I’ll log an issue. thanx.

The name of the resource file will depend on it’s path relative to the project, and also on it’s DependentUpon/DesignableClassName name.

If this is the .resx for a WinForms class, make sure the .resx has a DependentUpon tag inside the project that points to the form code file; and that the form code file has a DesignableClassName tag that has the form’s name.


    <Compile Include="Main.pas">
    <EmbeddedResource Include="Main.resx">

If these are not present, the resource file will get a “wrong” name, and the resource cannot be fondant runtime. You can see the name of the resource with ILSpy. For a Winforms resx, it should get the class name fo your form, from the DesignableClassName tag.

(Bartosz Antosik) #3

Thank you. It has indeed resolved the issue.

Two things to (just) notice to anyone revieving this later:

  1. The missing section was the reverse dependency (from EmbeddedResource to the pas module. No idea whay this was not present in the original code.
  2. Filenames are case sensitive.

(marc hoffman) #4

Do you recall where these files were created? from template, or manually? in VS?

I’ll review if that’s something we want to change (Elements supports operating systems with case sensitive filenames, where ion tear the case could matter, but that does seem like a rather corner-case scenario…

(Bartosz Antosik) #5

No idea really. Sorry. The history of this code is long an convoluted.

I do not postulate anything like it. Just for a reference to anyone who will se this later.

(marc hoffman) #6

I’ve made it case insensitive; seams only reasonable. The chance that someone has two forms with the same name and only differing in case is low, and that’d be insane, anyways :wink:

(Bartosz Antosik) #7

Yes, quite reasonable! :wink: Thanks for all the support in this thread.

(marc hoffman) #8

Any time!