J'essaie d'exécuter un script pour lire les valeurs d'une feuille Excel en utilisant EPPlus
et les charger dans une liste de tuples. Cependant quand je lance le script que je reçois deux erreurs, la première est:TypeInitializationException avec le script EPPlus
An unhandled exception of type 'System.TypeInitializationException' occurred in mscorlib.dll
Je l'ai vu dans d'autres postes que je dois vérifier l'exception intérieure, mais aucun est offert par Visual Studio 15. C'est tous les détails d'exception disponibles.
System.TypeInitializationException was unhandled
Message: An unhandled exception of type 'System.TypeInitializationException' occurred in mscorlib.dll
Additional information: The type initializer for 'CGCompare2.Program' threw an exception.
Puis, quand je ferme la fenêtre d'exception VS15 je reçois un pop up dialogue:
Cannot access a disposed object.
Object name: 'HwndSourceAdapter'
Je ne suis pas sûr que la question est, si cela est causé par mon code ou non. Toute aide, très appréciée.
Program.cs
using System;
using System.Collections.Generic;
using System.IO;
using OfficeOpenXml;
namespace CGComparer
{
class Program
{
private static List<Tuple<string, string>> _listTop;
private static List<Tuple<string, string>> _listGNED;
private static Base _baseCell;
private static ExcelPackage _package = new ExcelPackage(new FileInfo(_excelFile));
private static string _excelFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"Compare GNED and TOP V1.0.xlsx");
static void Main(string[] args)
{
_baseCell = new Base(1, 2);
_listTop = ColumnsToList(_baseCell.Column(),_baseCell.Row());
_baseCell = new Base(3, 2);
_listGNED = ColumnsToList(_baseCell.Column(),_baseCell.Row());
}
public static List<Tuple<string, string>> ColumnsToList(int column, int row)
{
var list = new List<Tuple<string, string>>();
var ws = _package.Workbook.Worksheets[1];
var ListIsValid = true;
do
{
var userEmail = (string)ws.Cells[column, row].Value;
var customerGroup = (string)ws.Cells[column + 1, row].Value;
if (!string.IsNullOrEmpty(userEmail))
{
list.Add(new Tuple<string, string>(userEmail, customerGroup));
row = row++;
}
else
{
ListIsValid = false;
}
} while (ListIsValid);
return list;
}
}
}
Base.cs
namespace CGComparer
{
public class Base
{
private static int _column;
private static int _row;
public Base(int column, int row)
{
_column = column;
_row = row;
}
public int Column()
{
return _column;
}
public int Row()
{
return _row;
}
}
}
le débogueur dans VS2015 est un sac de merde « o insectes, il ne vous laissera pas regarder le InnerException. Utilisez Outils> options> Debugging> général> cocher « Utiliser le mode de compatibilité Managed » et maintenant vous pouvez voir Attention, avec ces statiques, leur initialiseur peut vous mal dans l'arrière-plan. –
@HansPassant je vais vérifier cela quand je g et. Pouvez-vous élaborer ou afficher une «réponse» concernant l'avertissement de statique que vous avez mentionné? –
Je ne connais pas la réponse. Je devinerais à NullReferenceException puisque '_excelFile' est toujours nul, vous pouvez obtenir un fait en utilisant le tweak de débogueur que j'ai recommandé. –