更改命名空间后 C# resx 文件不起作用

发布于 2024-11-08 20:16:24 字数 510 浏览 0 评论 0原文

我正在开发一个现有的 Windows 窗体应用程序。我只需要进行一些修改,在这些更改期间,我遇到了一个场景,我还需要重命名现有的命名空间。现在,重命名该名称空间后,我的项目未运行。虽然它编译得很好,但在下面的代码行处中断了。

ImageList il = new ImageList();
ImageList = il;            
il.Images.Add((Image)new Bitmap(GetType(), "Images.ImageFileName.png"));//when this line is executed a dialog box appears and says that "there is no source code available for current location"

现在,因为我是 .net 世界的新手,所以我研究了这个问题,并认为它是由于 namspace 的变化而产生的。我还尝试重命名 Resources.Designer.cs 中的命名空间 但这也没有解决我的问题

I am working on an existing windows form application. I only need to make few modification, during those changes i came across a scenario where i need to rename an existing namespace aswell. Now after renaming that namespace my project is not running. Although it compiles fine but breaks at the following line of code

ImageList il = new ImageList();
ImageList = il;            
il.Images.Add((Image)new Bitmap(GetType(), "Images.ImageFileName.png"));//when this line is executed a dialog box appears and says that "there is no source code available for current location"

Now since i am new to .net world so i study this problem and figure that it arises due to change in namspace. I also trying renaming the namespace in the Resources.Designer.cs
but it also didn't solve my problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

忆离笙 2024-11-15 20:16:24

谢谢大家。

我自己找到解决方案。在这里发布解决方案的目的是其他人可能会从中受益。
事实上,这是我的一种粗心,因为我忘记更改属性“默认命名空间”的值,该属性包含旧的命名空间,这就是为什么我的资源文件总是指向旧的命名空间

Thanks All.

I find the solution by myself. The purpose of posting solution here is that may be some one else benefit from it.
Infact its a sort of carelessness from my side because i forget to change the value of Property "Default NameSpace" this property contains the old namespace that's why my resource file alwasy point to old namespace

挽梦忆笙歌 2024-11-15 20:16:24

右键单击Resources.resx,选择Properties,找到Custom Tool Namespace,设置您需要的命名空间。

另外,为什么不以 Resources.ResrouceName 之类的类型化方式引用您的资源。

以下是如何设置资源的快速教程,这样您就不必进行转换和考虑命名空间:http://msdn.microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx

Right click on Resources.resx, select Properties, find Custom Tool Namespace, set the namespace that you need.

Also, why don't you reference your resources in the typed manner like Resources.ResrouceName.

Here is a quick tutorial how you can setup your resources so you don't have to cast and think about namespaces: http://msdn.microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx

意中人 2024-11-15 20:16:24

尝试去掉第二行ImageList = il;。它所做的就是用类的实例替换类。不好。

try getting rid of that second line, ImageList = il;. what it's doing is replacing a class with an instance of a class. not good.

三生殊途 2024-11-15 20:16:24

我也遇到过这个问题。我必须重命名应用程序的名称空间。此后,设计人员忽略了所有资源,尽管它们是在构建解决方案并运行应用程序后出现的。

我发现即使我重命名了命名空间,它也没有在“默认命名空间”文本框下的应用程序属性中被替换。我已经更改了旧的命名空间,该命名空间仍然与新的命名空间一起出现,并且之后它可以正常工作。

I have also came across this issue. I had to rename the namespace of my application. After that the designer was ignoring all resources, although they were appearing after building a solution and running the application.

I found that even though I had renamed the namespace, it wasn't replaced in Application Properties under "Default Namespace" textbox. I have changed the old namespace which was still appearing there with the new namepspace and it worked properly afterwards.

橙幽之幻 2024-11-15 20:16:24

位图构造函数的特定重载将给定类型的命名空间与资源的字符串名称组合在一起,并在程序集清单中查找匹配项。因此,在本例中,它将是类的命名空间 + ".Images.ImageFileName.png"。我猜这不存在。通过右键单击 Resources.resx 并选择属性来更改 Resources.resx 的命名空间,执行重建并查看它现在是否有效。

That specific overload of the bitmap constructor combines the namespace of the given type with the string name of the resource and looks for a match in the assembly manifest. So in this case it would be the namespace of your class + ".Images.ImageFileName.png". I'm guessing that does not exist. Change the namespace of the Resources.resx by right clicking on it and selecting properties, do a Rebuild and see if it works now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文