Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#读取程序集外部的resource.resx文件会引发MissingManifestResourceException_C#_Asp.net_.net_Resx_Resourcemanager - Fatal编程技术网

C#读取程序集外部的resource.resx文件会引发MissingManifestResourceException

C#读取程序集外部的resource.resx文件会引发MissingManifestResourceException,c#,asp.net,.net,resx,resourcemanager,C#,Asp.net,.net,Resx,Resourcemanager,我正在从事一个由Asp.NETWeb应用程序和windows服务应用程序组成的项目。这两个可以使用我创建的一个共同项目来包含资源文件。我想把资源文件放在程序集之外,这样当我想更改它们时,它们就可以在不编译所有解决方案的情况下进行编辑。我寻找一种方法,在这里找到一种 它在web应用程序上运行得非常好,但过了一段时间,我发现windows服务应用程序无法读取这些资源,因此我得到了 System.Resources.MissingManifestResourceException: Could no

我正在从事一个由Asp.NETWeb应用程序和windows服务应用程序组成的项目。这两个可以使用我创建的一个共同项目来包含资源文件。我想把资源文件放在程序集之外,这样当我想更改它们时,它们就可以在不编译所有解决方案的情况下进行编辑。我寻找一种方法,在这里找到一种

它在web应用程序上运行得非常好,但过了一段时间,我发现windows服务应用程序无法读取这些资源,因此我得到了

System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.
baseName: abc  locationInfo: <null>  fileName: abc.resx
   at System.Resources.FileBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture)
   at yyyy.yyyyyy.yyyyyyy.GetGlobalResourceObject(String classKey, String resourceKey, Boolean getCommon)
   at xxx.xxx.xxx.Entities.xxxxxxxx.get_LocalizedName()
   at yyyyy.Adapters.ArchiverDtoAdapter.CreateArchiverInjectionsDto(InjectionProcedure procedure, INamingService namingService)
   at yyyyy.Adapters.ArchiverDtoAdapter.ConvertInjectionProcedureDto(InjectionProcedure procedure, INamingService namingService)
   at yyyy.Factories.ArchiverDtoFactory.<>c__DisplayClass1.<CreateInjectionProcedureSendRequestDto>b__0(IUnitOfWork unitOfWork)
   at Core.Data.NHibernate.Factory.UnitOfWorkFactoryBase.Create(Action`1 action, IUnitOfWork unitOfWork)
   at Core.Data.NHibernate.Factory.UnitOfWorkFactory.Create(Action`1 action)

请调查一下。希望这有帮助


读取清单资源是通过
Assembly
方法完成的:您需要包含资源的程序集的实例:请显示您的代码,以便我们可以看到您正在使用的程序集。您好,Richard,问题出现了,因为我不想使用程序集存储资源。我创建了“ResxResourceManager”,正如我在问题中给出的链接所建议的那样。我检查参数是否错误,但区域性、目录和文件名都正确给出。查看hat代码:它在自己的调用中使用反射,它自己的基类的构造函数。充其量,这将是脆弱的代码(在引用.NET更新后的四年内,可能会破坏这一点)。为什么不直接打电话呢?在一个小型的专注原型中(例如,没有NHibernate或UI)也可能值得这样做。使用默认构造函数,我们需要将资源嵌入程序集中,因此用户(最终用户)在不重新编译所有程序集并对其签名的情况下无法更改任何特定的内容。为了避免这种情况,我们希望在范围之外使用资源。问题是,如果它不工作,它就不应该在其他项目或调试模式上工作。抱歉,您误解了,我建议使用
..:base(baseName,resourceDir,typeof(ResXResourceSet))
而不是反射(因此不会在同一个对象上调用两个不同的
ResourceManager
构造函数)。反射的整个使用似乎是围绕
ResourceManager
的三参数构造函数不公开展开的:我只能假设它不在早期版本的.NET中,并且代码也没有更新(MSDN只返回到.NET 2:当时是公开的)。
public class ResxResourceManager : ResourceManager
    {
        public ResxResourceManager(string baseName, string resourceDir)
        {
            ObjectFactory.ResolveDependencies(this);

            Type[] paramTypes = new Type[] { typeof(string), typeof(string), typeof(Type) };
            object[] paramValues = new object[] { baseName, resourceDir, typeof(ResXResourceSet) };

            Type baseType = GetType().BaseType;

            ConstructorInfo ci = baseType.GetConstructor(
                BindingFlags.Instance | BindingFlags.NonPublic,
                null, paramTypes, null);

            ci.Invoke(this, paramValues);
        }

        protected override string GetResourceFileName(CultureInfo culture)
        {
            string resourceFileName = base.GetResourceFileName(culture);
            return resourceFileName.Replace(".resources", ".resx");
        }
    }