zoukankan      html  css  js  c++  java
  • 格式太旧或是类型库无效。 (Exception from HRESULT: 0x80028019 (TYPE_E_UNSUPFORMAT))

    错误提示信息

    格式太旧或是类型库无效。 (Exception from HRESULT: 0x80028019 (TYPE_E_UNSUPFORMAT)) 。

    Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))。

    出现时间

    并行大批量数据处理操作时随机出现(使用的是ArcGIS COM库)。

    原因:

    这是网络中找到的使用Excel进行COM对象互操作时的解释:

    After digging the internet I found out that there is a bug in Microsoft Interop with COM objects (at least with my case which is MS Excel 2010).

    The bug is that .NET checks that your thread (C# or VB code) localization is suitable to MS Excel localization you installed earlier, and if not it tells that the Microsoft.Office.Interop library is old or invalid.

    Your thread localization is derived from your computer regional settings (from the control panel --> regional and language)

    Then there are two options to solve this problem:

    1. To change your thread localization (by code)
    2. Install language pack for your Office

    解决方案:

    线程启动时,设置当前线程的CultureInfo与互操作库一致。

    When a thread is started, its culture is initially determined by using GetUserDefaultLCID from the Windows API. I found no way (I assume there is no way) to override this behavior. Only thing you can do is to set the thread culture afterwards.

    I wrote an extension. For that:

    public static class ParallelQueryCultureExtensions
    {
        public static ParallelQuery<TSource> SetCulture<TSource>(this ParallelQuery<TSource> source, CultureInfo cultureInfo)
        {
            SetCulture(cultureInfo);
            return source
                .Select(
                    item =>
                        {
                            SetCulture(cultureInfo);
                            return item;
                        });
        }
    
        private static void SetCulture(CultureInfo cultureInfo) {
            if (Thread.CurrentThread.CurrentCulture != cultureInfo) {
                Thread.CurrentThread.CurrentCulture = cultureInfo;
            }
        }
    } 
    

    So if you use it just after splitting up the original source using .AsParallel() you will get what you want.

    注:

    当内存溢出时,也可能导致该错误的出现。

  • 相关阅读:
    将博客搬至CSDN
    小啃机器学习(1)-----ID3和C4.5决策树
    然爸读书笔记(2014-12)----20个月赚130亿
    然爸读书笔记(2014-11)----小米的尖叫
    然爸读书笔记(2014-10)----Bootsrap用户手册
    然爸读书笔记(2014-9)----互联网思维到底是什么
    然爸读书笔记(2014-8)----结果第一
    论文阅读(2014-2)----The YouTube Video Recommendation System
    然爸读书笔记(2014-7)----平台战略
    扎克伯格谈Facebook创业过程
  • 原文地址:https://www.cnblogs.com/dadream/p/4843937.html
Copyright © 2011-2022 走看看