2017-08-04 61 views
-2

爲什麼系統在這個Msg.Culture = new CultureInfo("zh-HK");行發生錯誤?Resx文化爲空?

Msg是一個resx(資源)文件。

這是一個控制檯程序,.net 3.5,c#。

我在我自己的電腦上測試過,沒有問題。它只給我錯誤,當我部署到客戶端PC與捕獲,它只給我錯誤,當它從Outlook讀取某些電子郵件,其他電子郵件沒有問題。

錯誤是:

System.NullReferenceException:對象不設置爲一個對象的一個​​實例。

if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["cultureInfo"].ToString())) 
{ 
    if (null != System.Threading.Thread.CurrentThread.CurrentUICulture) 
    { 
     object test = new CultureInfo("zh-HK"); 
     System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-HK"); 
    } 
    else if (null != Msg.Culture) 
    { 
     object test = new CultureInfo("zh-HK"); 
     Msg.Culture = new CultureInfo("zh-HK"); 
    } 
} 

我能找到使用Assembly.GetExecutingAssembly().GetManifestResourceNames()資源文件名。

+0

'(!(null == Msg.Culture))'你爲什麼要那樣做? '(Msg.Culture!= null)'是相同的但是可讀的 – EpicKip

回答

0

找到原因,有些代碼系統上面的代碼系統無法從數據庫獲取數據,並且沒有在那裏報告錯誤,然後在Msg.Culture = new CultureInfo("zh-HK");處報告錯誤。