2

I'm developing an application targeting .NET Standard 1.4, using the new csproj style (not project.json), and trying to get a localizable resources file to become available throughout the project. I get compiler errors when including a resources file currently, stating that the resources member I'm trying to access is not defined. (Note: my final solution will have to be consumed by a Xamarin Android project and a UWP project)

The csproj automatically includes the resources file as follows:

<ItemGroup>
    <Compile Update="Resources.Designer.cs">
        <DesignTime>True</DesignTime>
        <AutoGen>True</AutoGen>
        <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
</ItemGroup>

<ItemGroup>
    <EmbeddedResource Update="Resources.resx">
        <Generator>ResXFileCodeGenerator</Generator>
        <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    </EmbeddedResource>
</ItemGroup>

Did it miss a step in the generation? Why can't I access any of the members of my resources file throughout the assembly?

6
  • Wow - even more amazing, I made a separate test project to see what was available - it turns out intellisense just doesn't like the property accessor to the Resources class, but it compiles it successfully with one build error in this test project, and runs through in a unit test. I also tried the ResourceManager.GetString() method, and it worked as well. So my build is just being blocked by intellisense! Microsoft, what have you done to us?
    – Dagrooms
    Apr 17, 2017 at 16:03
  • This is an intellisense error in my test project, and a real build error in my main project. So I can't turn off intellisense reporting and work past it.
    – Dagrooms
    Apr 17, 2017 at 16:05
  • Definitely quacks like a bug, it just doesn't seem to realize that it needs to reparse the modified Designer.cs file. A simple workaround is to open the file in the text editor, now everything starts to work correctly. Use Help > Send Feedback > Report a Problem to file a bug report. Apr 17, 2017 at 16:57
  • I'm working around with Resources.ResourceManager.GetString("ResourceStringX")
    – Dagrooms
    Apr 17, 2017 at 17:00
  • 2
    Well, don't do that, this bug is too stoopid to let it compromise your coding style. It only goes wrong after you first add the .resx file to the project. More than one way to slap it over the head, closing the solution and re-opening it works around the bug as well. And right-click the project > Unload, right-click again > Reload. Any resource you add after this will now be properly recognized. Apr 17, 2017 at 17:32

1 Answer 1

3

After pasting resource XML, make an edit to the .resx file to generate the C# class.

.resx files generate the corresponding C# file after editing the .resx. Since I was pasting XML and not making any edits in the .resx file, the class never got generated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.