我有以下幾點:XAML 'System.TypeInitializationException' 在設計模式與靜態屬性
文件:UserControlTest.xaml
<UserControl
x:Class="MySolution.Views.UserControlTest"
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:local="clr-namespace:MySolution.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:MySolution.ViewModels"
d:DesignHeight="300"
d:DesignWidth="300"
mc:Ignorable="d">
<UserControl.DataContext>
<viewModels:MyViewModel/>
</UserControl.DataContext>
<Grid />
</UserControl>
文件:MyViewModel的.cs
namespace MySolution.ViewModels
{
public class MyViewModel : NotifyPropertyChanged
{
try
{
var test = Global.Test;
}
catch (Exception ex)
{
LogHelper.WriteLogFile(ex);
}
}
}
File:Global.cs
namespace Expert.Engine
{
public class Global
{
public static string Test { get; set; } = "Test Value";
}
}
當我調試XAML(附接至處理菜單=> XDesProc.exe相對於上述XAML文件),則調試器在MyViewModel的.cs Global.Test訪問燒製「System.TypeInitializationException」:
try
{
var test = Global.Test;
}
catch (Exception ex)
{
LogHelper.WriteLogFile(ex);
}
有誰知道爲什麼它不起作用? CLR似乎還沒有定義Static類,但它是如何工作的?
而且'Global.Test'的確如此陳述那麼簡單?此外,沒有什麼在該TypeInitializationException的內部異常? – Evk
不知道這是否適用於XAML,但值得一試:https://stackoverflow.com/questions/13698388/how-to-troubleshoot-and-debug-visual-studio-design-mode-errors/13698442#13698442 – user6144226