便携式类库中引用资源文件时,ResourceMap未找到错误 [英] ResourceMap not found error when referencing a resource file within a portable class library

查看:618
本文介绍了便携式类库中引用资源文件时,ResourceMap未找到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临的问题有如下:

The problem I am facing has as follows:

我已经开发出一种便携式类库来封装服务连接。这里面类库存在包含字符串的一个Resources.resw文件。这些字符串仅由类库的方法调用(例如重写的ToString()方法)。

I have developed a portable class library to encapsulate a service connection. Inside this class library there is a Resources.resw file containing strings. These strings are called only by methods of the class library (for example to override ToString() methods).

正如我所说的,这是一个便携式类库。如果我引用它作为一个DLL,或者甚至在另一个解决方案的一个项目,它被建造和正确编译。然后,我让我的应用程序中使用这个库的方法的调用,比如

As I said this is a portable class library. If I reference it as a dll, or even as a project inside another solution, it gets built and compiles correctly. Then I make a call using a method of this library within my application, say

        ClientFacadeConnector connector = new ClientFacadeConnector();
        ICollection<SearchResult> results = null;
        string message = string.Empty;

        if (maxResults != -1) //Search with max Results
        {
            try
            {
                if (!contextQuery.Trim().Equals(string.Empty))
                {

                    results = await connector.GetConnected().SearchAsync(contextQuery, query, maxResults);
                    message = "Search with ContextQuery " + contextQuery + ", Query " + query + ", max results " + maxResults.ToString();
                }
                else
                {

                    results = await connector.GetConnected().SearchAsync(query, maxResults, true);
                    message = "...using normal Query search, Query " + query + ", max results " + maxResults.ToString();
                }
            }
            catch (IQserException ex)
            {
                message = ex.Message;
            }
        }


        if (results != null)
        {
            ICollection<LocalSearchResult> contentResults = new List<LocalSearchResult>();
            foreach (SearchResult s in results)
            {
                var q = s.ToString();
                var contentItem = await connector.GetConnected().GetContentAsync(s.ContentId);
                LocalSearchResult lContent = new LocalSearchResult(contentItem);
                lContent.Score = s.Score;
                lContent.Relevance = s.Relevance;
                lContent.MarkFullText(query);
                contentResults.Add(lContent);
            }

目前,我叫s.ToString()方法的地步,我得到一个。错误资源地图未找到

At the point where I call s.ToString() method, I get an error "Resource Map not found".

要说明在何处这个来自:

To explain where this comes from:

public static class AppResources
{
    private static ResourceLoader resourceLoader;

    static AppResources()
    {
        // Load local file Resources.resw by default
        resourceLoader = new ResourceLoader();            
    }

    public static string GetResources(string key)
    {
        if (string.IsNullOrEmpty(key))
            throw new ArgumentNullException("key");

        return resourceLoader.GetString(key);
    }

}



和重写的ToString()内方法有代码如下所示:

and inside the overridden ToString() method there is code that looks as follows:

    public override string ToString()
    {
        StringBuilder buf = new StringBuilder(AppResources.GetResources("InstrSearchResultContent"));

        if (ContentId != -1)
        {
            buf.Append(AppResources.GetResources("StringContent") + " ID:" + ContentId.ToString() + " | ");
        }
        else
        {
            buf.Append(AppResources.GetResources("StringNo") + AppResources.GetResources("StringContent") + "ID" + " | ");
        }
        ...

资源文件名为resources.resw和是的ResourceLoader如果没有其他被称为调用默认resw文件。

The resource file is called resources.resw and is the default resw file that ResourceLoader calls if no other is called.

奇怪的是,如果我复制的资源文件的客户端应用程序内本地,这是正确的,所有引用调用类库的资源文件,一切工作。

Strangely enough, if I copy the resource file inside the client application locally, it is referenced correctly by all calls to the class library resource file and everything works.

这类库应该完成时是一个SDK。我是否需要单独分发资源文件?

This class library is supposed to be an SDK when finished. Do I need to distribute the resource file separately?

这样的我从来没有与正常的类库和RESX文件中遇到的问题。 Resw是给我毛骨悚然。

Such a problem I have never experienced with normal Class libraries and resx files. Resw is giving me the creeps..

推荐答案

接受的答案可能不再是真实的。我试着和VS警告的ResourceLoader(字符串)已被弃用。在我的情况下,下面的工作:

Accepted answer posted by @Rory MacLeod may no longer be true. I tried and VS warned that ResourceLoader(String) is deprecated. The following worked in my case:

var loader = ResourceLoader.GetForCurrentView();
string localName = loader.GetString("someKey");

这篇关于便携式类库中引用资源文件时,ResourceMap未找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆