c# - CA1303 从资源表中检索以下字符串而不是 : "Service Started"

标签 c# exception visual-studio-2015 fxcop

我在 FxCop 中违反了以下规定。当我在 Console.WriteLine("Service Started");

中对字符串进行硬编码时

Method 'method()' passes a literal string as parameter 'value' of a call to 'Console.WriteLine(string)'. Retrieve the following string(s) from a resource table instead: "Service Started"

所以我更改了如下类型的代码。

ResourceManager rm = new ResourceManager("Service Started", Assembly.GetExecutingAssembly());
string start = rm.GetString("Service Started");
Console.WriteLine(start);

现在我没有违反 FxCop。但是我在行 string start = rm.GetString("Service Started");

中得到了以下异常

如何解决这个异常?

Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Service Started.resources" was correctly embedded or linked into assembly "namespace name" at compile time, or that all the satellite assemblies required are loadable and fully signed.

最佳答案

看来您可能没有添加资源字符串和值。请验证以下链接以供引用:

Code Analysis using VS.Net 2010

How to create and use resources in .NET

关于c# - CA1303 从资源表中检索以下字符串而不是 : "Service Started",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43861367/

相关文章:

c# - 从另一个类访问私有(private)方法

c# - DataTable Linq where 子句与大写比较

c# - WPF:截取屏幕截图的方法

c# - Database.BeginTransaction() Entity Framework 回滚抛出异常

c# - 程序未运行/进入调试点

amazon-web-services - AWS 弹性 Beanstalk : Command Hooks Failed

java - 为什么这些 throw 语句没有给我一个编译器错误?

haskell - 在 happstack 中捕获纯函数的异常

exception - 使用 Clojure 处理异常

visual-studio-2015 - Visual Studio 2015工具提示颜色