【问题标题】:Global ressources not reachable through Resources class无法通过 Resource 类访问全局资源
【发布时间】:2012-07-05 07:51:30
【问题描述】:

我创建了一个 Silverlight 业务应用程序并希望使用 App_GlobalResources。

资源位于同一个项目 (TestApp.Web) 中。试图通过 System.Resources 使用一些资源。在一个类中不起作用,因为没有列出类。

我只看到 RegistrationDataResources 和 ValidationErrorResources。

也许你有一个想法?

编辑: 使用 Resources.te23。出现错误。 “Type or Namspace te23 is not available in TestApp.Web.Resources”(翻译成英文)

“te23”资源的内容(我删除了 cmets)。

namespace Resources {
using System;
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Web.Application.StronglyTypedResourceProxyBuilder", "10.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class te23 {
    private static global::System.Resources.ResourceManager resourceMan; 
    private static global::System.Globalization.CultureInfo resourceCulture;

    [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    internal te23() {
    }
   [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
    internal static global::System.Resources.ResourceManager ResourceManager {
        get {
            if (object.ReferenceEquals(resourceMan, null)) {
                global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Resources.te23", global::System.Reflection.Assembly.Load("App_GlobalResources"));
                resourceMan = temp;
            }
            return resourceMan;
        }
    }
    [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
    internal static global::System.Globalization.CultureInfo Culture {
        get {
            return resourceCulture;
        }
        set {
            resourceCulture = value;
        }
    }
    internal static string test {
        get {
            return ResourceManager.GetString("test", resourceCulture);
        }
    }
}

}

【问题讨论】:

    标签: c# .net silverlight resources app-globalresources


    【解决方案1】:

    只是想一想,你有具体库的库引用吗?

    【讨论】:

    • 资源在同一个项目中。 (更新了我上面的帖子)
    • 我指的是你项目中的引用文件夹,我曾经遇到过同样的情况。我没有提及 System.Resources DLL。
    • 其实并没有引用System.Resources.dll。但我在“添加参考”窗口中找不到此参考:-/
    • 并且还右键单击资源文件并查看属性,然后将“构建操作”更改为“嵌入式资源”以便它可用
    • 属性“构建操作”设置为“内容”。将其设置为“嵌入式资源”后,我清理并重建了项目。没有任何改变。
    【解决方案2】:

    这通常是构建问题。验证 .resx 文件的 Custom Tool 属性是否设置为“GlobalResourceProxyGenerator”。

    (请注意,您将使用 Resources.MyResxFile.ResourceName 访问资源。)

    【讨论】:

    • 该属性已设置为“GlobalResourceProxyGenerator”。
    • @float 等等,你在 web 项目中创建了资源,对吧?您是尝试从该项目还是从 Silverlight 项目访问它们?
    • 我正在尝试从 Web 项目而不是 Silverlight 项目中访问它们。
    • @float hm,奇怪,似乎应该可以工作。让我问你这个问题:你在 Resource.designer.cs 文件中看到了什么?命名空间是 Resources 吗?类是 public 还是 internal?要尝试的另一件事可能是使用 PublicResXFileCodeGenerator 作为自定义工具。
    • 我已经更新了我的帖子。在那里你可以看到我的测试资源的 Designer.cs 文件以及如果我尝试使用它的错误消息。
    【解决方案3】:

    我已将命名空间从 Resources 编辑到 TestApp.Web.Resources。现在它们在 Resources 下列出。

    【讨论】:

      猜你喜欢
      • 2018-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 2020-04-13
      • 1970-01-01
      • 2020-01-11
      • 1970-01-01
      相关资源
      最近更新 更多