简体   繁体   中英

C# Reading resource .resx file outside of assembly throws MissingManifestResourceException

I am working on a project which consists both Asp.Net web application and windows service application. These two can use a mutual project which I created just to contain resource files. I wanted to put the resource files out side of the assembly so when I want to change them, they could be editable without compiling all solution. I search for a method and find here one as;

ASP.NET Resourcemanager to read local .resx

It worked perfectly on the web application, but after a while I saw, the windows service application cannot read that resources and I got

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)

I dont understand the problem because, I project works correctly and the other is not. The other strange behaviour is that when i start the service on my machine with debuging to see what happens, it works.

Update: This is the code I am using as referenced

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");
        }
    }

Please have a look into this. Hope this helps.

http://support.microsoft.com/kb/839861

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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