首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅限NodaTime TypeInitializationException设备,仅限版本

仅限NodaTime TypeInitializationException设备,仅限版本
EN

Stack Overflow用户
提问于 2014-10-12 01:45:00
回答 1查看 305关注 0票数 2

我正在使用NodaTime获得一个TypeInitializationException,但只在发行版中,并且只在设备上使用。

下面是堆栈跟踪:

代码语言:javascript
复制
System.TypeInitializationException: The type initializer for 'Patterns' threw an exception. ---> System.TypeInitializationException: The type initializer for 'NodaTime.Text.ZonedDateTimePattern' threw an exception. ---> System.TypeInitializationException: The type initializer for 'NodaTime.DateTimeZone' threw an exception. ---> System.TypeInitializationException: The type initializer for 'NodaTime.Text.OffsetPattern' threw an exception. ---> System.Resources.MissingManifestResourceException: Exception of type 'System.Resources.MissingManifestResourceException' was thrown.
   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
   at NodaTime.Globalization.NodaFormatInfo.get_OffsetPatternLong()
   at NodaTime.Text.OffsetPatternParser.ParsePartialPattern(String patternText, NodaFormatInfo formatInfo)
   at NodaTime.Text.OffsetPatternParser.CreateGeneralPattern(NodaFormatInfo formatInfo)
   at NodaTime.Text.OffsetPatternParser.ParsePartialPattern(String patternText, NodaFormatInfo formatInfo)
   at NodaTime.Text.OffsetPatternParser.ParsePattern(String patternText, NodaFormatInfo formatInfo)
   at NodaTime.Text.FixedFormatInfoPatternParser`1.<>c__DisplayClass0.<.ctor>b__2(String patternText)
   at NodaTime.Utility.Cache`2.GetOrAdd(TKey key)
   at NodaTime.Text.OffsetPattern.Create(String patternText, NodaFormatInfo formatInfo)
   at NodaTime.Text.OffsetPattern..cctor()
   --- End of inner exception stack trace ---
   at NodaTime.TimeZones.FixedDateTimeZone.MakeId(Offset offset)
   at NodaTime.DateTimeZone.BuildFixedZoneCache()
   at NodaTime.DateTimeZone..cctor()
   --- End of inner exception stack trace ---
   at NodaTime.LocalDateTime.InUtc()
   at NodaTime.Text.ZonedDateTimePattern..cctor()
   --- End of inner exception stack trace ---
   at NodaTime.Text.ZonedDateTimePattern.CreateWithInvariantCulture(String patternText, IDateTimeZoneProvider zoneProvider)
   at NodaTime.Text.ZonedDateTimePattern.Patterns..cctor()
   --- End of inner exception stack trace ---
   at NodaTime.ZonedDateTime.ToString(String patternText, IFormatProvider formatProvider)
   at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
   at System.Text.StringBuilder.AppendFormat(String format, Object[] args)
   at Models.EventSummary.get_DisplayDate()
EN

回答 1

Stack Overflow用户

发布于 2015-03-04 18:54:45

workaround by Phil Hoff为我们解决了这个问题。创建以下WindowsRuntimeResourceManager类:

代码语言:javascript
复制
/// <summary>
/// from http://blogs.msdn.com/b/philliphoff/archive/2014/11/19/missingmanifestresourceexception-when-using-portable-class-libraries-in-winrt.aspx
/// </summary>
public class WindowsRuntimeResourceManager : ResourceManager
{
    private readonly ResourceLoader _resourceLoader;

    private WindowsRuntimeResourceManager(string baseName, Assembly assembly)
        : base(baseName, assembly)
    {
        _resourceLoader = ResourceLoader.GetForViewIndependentUse(baseName);
    }

    public static void InjectIntoResxGeneratedApplicationResourcesClass(Type resxGeneratedApplicationResourcesClass)
    {
        resxGeneratedApplicationResourcesClass.GetRuntimeFields()
          .First(m => m.Name == "resourceMan")
          .SetValue(null, new WindowsRuntimeResourceManager(resxGeneratedApplicationResourcesClass.FullName, resxGeneratedApplicationResourcesClass.GetTypeInfo().Assembly));
    }

    public override string GetString(string name, CultureInfo culture)
    {
        return _resourceLoader.GetString(name);
    }
}

在使用NodaTime之前(例如,在您的应用程序构造函数中),替换NodaTime程序集的资源管理器:

代码语言:javascript
复制
        Assembly nodaTimeAssembly = typeof(LocalDate).GetTypeInfo().Assembly;

        Type messagesResource = nodaTimeAssembly.GetType("NodaTime.Properties.Messages");
        Type patternResource = nodaTimeAssembly.GetType("NodaTime.Properties.PatternResources");

        WindowsRuntimeResourceManager.InjectIntoResxGeneratedApplicationResourcesClass(messagesResource);
        WindowsRuntimeResourceManager.InjectIntoResxGeneratedApplicationResourcesClass(patternResource);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26317446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档