繁体   English   中英

使用了不正确的ExecutingAssembly

[英]Incorrect ExecutingAssembly being used

我有一个实用程序库(dll),其中包含用于处理嵌入式资源的类(如下所示)。 在Visual Studio 2013中,它可以按预期工作并从程序集中加载资源,该程序集在实用程序库中调用该函数。

在Visual Studio 2015中,当我调用函数时,代码尝试从实用程序库而不是调用库中加载资源。 它们是单独的程序集。

请您能帮我了解为什么会发生这种情况,以及如何使它在Visual Studio 2015中工作吗? 提前致谢。

public static class EmbeddedResources
{
    public static string[] GetAllResourceNames()
    {
        Assembly _assembly = Assembly.GetExecutingAssembly();
        return _assembly.GetManifestResourceNames();
    }

    public static string ReadQueryResource(string resourceName)
    {
        Assembly _assembly;
        StreamReader _textStreamReader;
        try
        {
            _assembly = Assembly.GetExecutingAssembly();
            _textStreamReader = new StreamReader(_assembly.GetManifestResourceStream(resourceName));
            if (_textStreamReader.Peek() != -1)
                return _textStreamReader.ReadToEnd();
        }
        catch
        {
            //MessageBox.Show("Error accessing resources!");
        }
        return null;
    }
}

Assembly.GetExecutingAssembly()

获取包含当前正在执行的代码的程序集。

Assembly.GetCallingAssembly()

返回调用当前正在执行的方法的方法的Assembly。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM