Question

We are trying to get our C# application to compile and run with both

  • Visual Studio 10 (with the Microsoft compiler), on Windows, and
  • MonoDevelop with gmcs, on Linux

However, sections like this in the .csproj files (for Visual Studio):

<Compile Include="Foo\Bar.cs" />
<EmbeddedResource Include="Foo\Bar.resx">
    <DependentUpon>Bar.cs</DependentUpon>
</EmbeddedResource>

must be changed as follows before they will work with MonoDevelop/gmcs (if not, at runtime, resources.GetObject() will throw a MissingManifestResourceException):

<Compile Include="Foo\Bar.cs" />
<EmbeddedResource Include="Foo\Bar.resx">
    <DependentUpon>Foo\Bar.cs</DependentUpon>
</EmbeddedResource>

How to rewrite this into a form they will both accept? (Short of deleting the DependentUpon element, of course.)

Was it helpful?

Solution

Meanwhile I have researched a couple of ways to deal with the situation.

For instance, it is apparently possible to add Condition attributes with the value $(VisualStudioVersion) != '' in order to make them conditional on whether Visual Studio is being used.

However, on a whim (after reading this answer) I tried something entirely different: I replaced my nested namespaces

namespace Baz
{
    namespace Bar
    {
        [...]
    }
}

with dotted namespace notation:

namespace Baz.Bar
{
    [...]
}

and voilà, the MissingManifestResourceException no longer exists, even with the original DependentUpon clause.

Problem solved, but I don't know why.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top