The following stack trace is from me trying to run "Release" instead of "Debug"
I've set my warning level to the highest, and there are no warnings or messages. The application works fine in Debug, but crashes without errors in Release
I am assuming it has something to do with the XAML I've written, so it has been pasted far below
System.Windows.Markup.XamlParseException
HResult=0x80131501
Message=Aktiveringen af konstruktøren på typen 'Guideviewer.MainWindow', som svarer til de angivne bindingsbegrænsninger, udløste en undtagelse.
Source=PresentationFramework
StackTrace:
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
at System.Windows.Application.DoStartup()
at System.Windows.Application.<.ctor>b__1_0(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at Guideviewer.App.Main()
Inner Exception 1:
FormatException: Inputstrengen var ikke i et korrekt format.
The markup below is the used XAML
<Window x:Class="Guideviewer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow"
Height="350"
Width="1600"
ResizeMode="NoResize"
SizeToContent="WidthAndHeight">
<Grid>
<DataGrid Name="MyDataGrid"
Margin="0,39,4,-39"
Padding="1"
Background="#FF212121"
SelectionUnit="Cell"
VerticalGridLinesBrush="Black"
VerticalScrollBarVisibility="Hidden"
GridLinesVisibility="None"
HeadersVisibility="Column"
MaxWidth="1600"
MaxHeight="900"
MaxColumnWidth="320" CanUserReorderColumns="False" CanUserSortColumns="False"/>
<Menu HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="1590" IsMainMenu="True">
<MenuItem Header="Options" x:Name="Options">
<MenuItem Header="Save" Click="SaveToFile_OnClick"></MenuItem>
<MenuItem Header="Load" Click="LoadFile_OnClick"></MenuItem>
</MenuItem>
<MenuItem Header="Delete first row" Click="DeleteFirstRow_OnClick">
</MenuItem>
<Label Content="Progress:" Height="17" Margin="0" Padding="0"/>
<TextBox Height="23" TextWrapping="Wrap" Width="68" Text="" Padding="0,2,0,0"/>
</Menu>
</Grid>
</Window>
The code below is the MainWindow.xaml.cs file
using Google.Apis.Auth.OAuth2;
using Google.Apis.Sheets.v4;
using Google.Apis.Sheets.v4.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.Win32;
namespace Guideviewer {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow {
// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/sheets.googleapis.com-dotnet-quickstart.json
static string[] Scopes = { SheetsService.Scope.SpreadsheetsReadonly };
private const string ApplicationName = "GuideViewer";
private float widthDef = 1600 / 5;
private float widthMed = 1600 / 5 / 5 * 3.7f;
private float widthSm = 1600 / 5 / 4.6f;
private int deletedFirstRows;
public IList<IList<Object>> Values;
public ValueRange Response;
public List<string> ColumnAList = new List<string>();
public List<string> ColumnBList = new List<string>();
public List<string> ColumnCList = new List<string>();
public List<string> ColumnDList = new List<string>();
public List<string> ColumnEList = new List<string>();
public List<string> ColumnFList = new List<string>();
SaveFileDialog sfd = new SaveFileDialog {
Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
};
OpenFileDialog ofd = new OpenFileDialog {
Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
};
public Binding[] Bind = {
new Binding("Qt"),
new Binding("L"),
new Binding("Mqc"),
new Binding("Cp"),
new Binding("Tcp"),
new Binding("Im")
};
public string[] Header = {
"Quest / Train to",
"Lamps",
"Master Quest Cape",
"Completionist Cape",
"Trimmed Completionist Cape",
"Ironman"
};
public DataGridTextColumn[] Colu = {
new DataGridTextColumn(),
new DataGridTextColumn(),
new DataGridTextColumn(),
new DataGridTextColumn(),
new DataGridTextColumn(),
new DataGridTextColumn()
};
public struct MyData {
public string Qt { set; get; }
public string L { set; get; }
public string Mqc { set; get; }
public string Cp { set; get; }
public string Tcp { set; get; }
public string Im { set; get; }
}
public MainWindow() {
InitializeComponent();
StreamReader sr = new StreamReader("deletedrows.txt");
deletedFirstRows = Convert.ToInt32(sr.ReadToEnd());
var style = new Style(typeof(TextBlock));
var headerstyle = new Style(typeof(DataGridColumnHeader));
var cell = new Style(typeof(DataGridCell));
style.Setters.Add(new Setter(TextBlock.TextWrappingProperty, TextWrapping.Wrap));
style.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));
style.Setters.Add(new Setter(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center));
headerstyle.Setters.Add(new Setter(DataGridColumnHeader.HorizontalContentAlignmentProperty, HorizontalAlignment.Center));
cell.Setters.Add(new Setter(DataGridCell.BackgroundProperty, Brushes.Black));
cell.Setters.Add(new Setter(DataGridCell.PaddingProperty, new Thickness(3)));
#region GoogleRequest
String myUrl = "https://api.myjson.com/[REDACTED]/[REDACTED].json";
System.Net.WebClient client = new System.Net.WebClient();
{
client.DownloadFile(myUrl, "\\client_secret.json");
}
UserCredential credential;
using (var stream =
new FileStream("\\client_secret.json", FileMode.Open, FileAccess.Read)) {
string credPath = Environment.GetFolderPath(
Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath,
".credentials/sheets.googleapis.com-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer {
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define request parameters.
String spreadsheetId = "1uLxm0jvmL1_FJNYUJp6YqIezzqrZdjPf2xQGOWYd6ao";
String range = "TestSheet!A2:F";
SpreadsheetsResource.ValuesResource.GetRequest request =
service.Spreadsheets.Values.Get(spreadsheetId, range);
File.Delete("\\client_secret.json");
#endregion
ValueRange response = request.Execute();
Response = request.Execute();
IList<IList<Object>> values = response.Values;
Values = response.Values;
if (values != null && values.Count > 0) {
foreach (var col in values) {
if (col[0] != null) {
ColumnAList.Add(col[0].ToString());
}
if (col[1] != null) {
ColumnBList.Add(col[1].ToString());
}
if (col[2] != null) {
ColumnCList.Add(col[2].ToString());
}
if (col[3] != null) {
ColumnDList.Add(col[3].ToString());
}
if (col[4] != null) {
ColumnEList.Add(col[4].ToString());
}
if (col[5] != null) {
ColumnFList.Add(col[5].ToString());
}
}
}
for (var i = 0; i < 6; i++) {
Colu[i].Header = Header[i];
Colu[i].Binding = Bind[i];
Colu[i].ElementStyle = style;
Colu[i].HeaderStyle = headerstyle;
Colu[i].CellStyle = cell;
switch (i) {
case 0:
Colu[i].Foreground = Brushes.Aqua;
break;
case 1:
Colu[i].Foreground = Brushes.White;
Colu[i].MinWidth = widthSm;
//Colu[i].Width = 1600 / 5 / 4.6;
Colu[i].MaxWidth = widthSm;
break;
case 2:
Colu[i].Foreground = Brushes.CornflowerBlue;
Colu[i].MinWidth = widthMed;
//Colu[i].Width = 1600 / 5 / 5 * 3.7;
Colu[i].MaxWidth = widthMed;
break;
case 3:
Colu[i].Foreground = Brushes.Brown;
break;
case 4:
Colu[i].Foreground = Brushes.DarkOrange;
break;
case 5:
Colu[i].Foreground = Brushes.DarkGray;
break;
default:
Colu[i].MinWidth = widthDef;
//Colu[i].Width = 1600 / 5;
Colu[i].MaxWidth = widthDef;
break;
}
MyDataGrid.Columns.Add(Colu[i]);
}
if (values != null) {
for (int i = 0; i < values.Count; i++) {
MyDataGrid.Items.Add(new MyData {
Qt = ColumnAList[i],
L = ColumnBList[i],
Mqc = ColumnCList[i],
Cp = ColumnDList[i],
Tcp = ColumnEList[i],
Im = ColumnFList[i]
});
}
}
}
private void DeleteFirstRow_OnClick(object sender, RoutedEventArgs e) {
MyDataGrid.Items.RemoveAt(1);
deletedFirstRows++;
}
private void SaveToFile_OnClick(object sender, RoutedEventArgs e) {
bool? result = sfd.ShowDialog();
if (result == true) {
string path = sfd.FileName;
StreamWriter sw = new StreamWriter(File.Create(path));
sw.WriteAsync(deletedFirstRows.ToString());
sw.Dispose();
}
}
private void LoadFile_OnClick(object sender, RoutedEventArgs e) {
if (ofd.ShowDialog() == true) {
string path = ofd.FileName;
using (StreamReader sr = new StreamReader(File.OpenRead(path))) {
MyDataGrid.Items.Clear();
if (Values != null) {
for (int i = 0; i < Values.Count; i++) {
MyDataGrid.Items.Add(new MyData {
Qt = ColumnAList[i],
L = ColumnBList[i],
Mqc = ColumnCList[i],
Cp = ColumnDList[i],
Tcp = ColumnEList[i],
Im = ColumnFList[i]
});
}
}
int removeCount = Convert.ToInt32(sr.ReadToEnd());
for (int i = 0; i < removeCount; i++) {
MyDataGrid.Items.RemoveAt(i);
}
}
}
}
}
}
User contributions licensed under CC BY-SA 3.0