开发者

Visual Studio 2010 Resources (WPF)

开发者 https://www.devze.com 2023-02-25 06:45 出处:网络
I was in visual studio and had a class file: Foo.cs ... I created a a resource (resx) file called Foo.resx because I also plan on having a Foo.es-SP.resx.

I was in visual studio and had a class file: Foo.cs ... I created a a resource (resx) file called Foo.resx because I also plan on having a Foo.es-SP.resx.

Visual studio, very nicely, tucked away the resource file the same way it tucks away code-behind files for xaml pages.

The problem is the application won't compile because the resource generator created a Foo.Designer.cs (designer) class that has an internal Foo class for the resource, which is the same class name as my Foo class:

Foo.cs

public class Foo { ... }

Foo.Designer.cs

internal class Foo { ... }

which is quite annoying because my application will not compile now. So, I figured I'd trick Visual Studio here and rename the file (not the class itself). I now have FooC.cs and FooC.resx and FooC.Designer.cs. This changed the resx class to internal class FooC { ... }

It compiles, but doesn't crashes when I run the application when I try to grab a resource.

  1. Why does Visual Studio create an internal class that collides with my existing class? It's obvious that creating a resource for you class should have the same name because it organizes it for you.

  2. Why is it that I get a runtime error when I try to use the resource that is marked as "Embedded Resource"?

Error Message:

System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. 开发者_开发百科Make sure "MyProj.FooC.resources" was correctly embedded or linked into assembly "MyProj" at compile time, or that all the satellite assemblies required are loadable and fully signed. at System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName)


Select Foo.es-SP.resx in the solution explorer, display its properties (F4), and clear the Custom Tool property


Change the name of you Foo.resx to, e.g., FooResources.resx.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号