In an earlier blog about resource fallback essentials, I said that the resource diagnostic tool resview is included with the framework sdk. That was wrong – it turns out we previously released resview as a gotdotnet sample, but it’s no longer accessible.
Since resview is helpful in our own investigations, we decided to re-release resview on code gallery [download resview].
Resview looks specifically for resource embedding problems that can result in runtime resource lookup problems. It can tell you about critical errors; for example, if the assembly is missing resources or the embedded resource file name is incorrect. It also gives warnings about best practices – for example, reminding you to include NeutralResourcesLanguagesAttribute.
How to use resview
You can run resview on a .resources file, a main assembly, or a satellite assembly. Let’s run resview on assemblies from the ResourceManagerSample project, mentioned in the previous blog.
To view the resources embedded in the main assembly, run “resview Fallback.exe”.
To view the resources embedded in a satellite assembly, run “resview FallbackTest.resources.dll” on any of the satellite assemblies.
Let’s look at the output when running on the main assembly. I’ve added numbers to the end of interesting lines, which will be described afterwards.
Microsoft (R) Visual .resources Viewer Version 1.83 [CLR version 4.0.20209.0]
FallbackTest.exe is a main assembly.
ResView : warning: This assembly does not have a NeutralResourcesLanguageAttribute.
Using this attribute gives a slight perf optimization for one culture, and
is required for localizable ClickOnce apps. (1)
Public key token: null [This must not be a shipping binary] (2)
Processing FallbackStrings.resources… (3)
Resources from FallbackStrings.resources…
greeting = hello
eow = weekend
Found 2 resources in FallbackStrings.resources. (4)
Found 1 resource file, with a total of 2 resources.
Encountered 0 errors, 1 warning.
Total size of all .resources files: 244
Total length of keys (chars): 11 Average: 5.5
Total length of String values (chars): 12 Average: 6.0
Number of Strings: 2 Byte’s: 0 Streams: 0 Others: 0
# of unique Types: 1
file est. overhead: 221 bytes 110.5 bytes/resource 90.6% of the file
Output time: 31 ms
This tells us the following:
1. The main assembly didn’t use the NeutralResourcesLanguageAttribute. We strongly recommend that you add this attribute. About the NeutralResourcesLanguageAttribute.
2. There’s no public key token. This serves as a reminder, in case your assembly needs a strong name.
3. Resview found an embedded resources file named FallbackStrings.resources.
4. Lists the resources in that file
In addition to the general diagnostic information resview provides (for example, if the files were named incorrectly), 3 and 4 combined can be useful for debugging resource failures. For example, if you get an error during resource lookup, you can check whether the resources file the ResourceManager is searching for is actually embedded in the assembly. If so, you can check whether the key/value pair is actually in the resources file.