C# 使用变量参数调用函数时System.Windows.Markup.XamlParseException
我对WPF应用程序有问题。运行时,它会中断,并出现System.Windows.Markup.XamlParseException,给出:C# 使用变量参数调用函数时System.Windows.Markup.XamlParseException,c#,.net,wpf,C#,.net,Wpf,我对WPF应用程序有问题。运行时,它会中断,并出现System.Windows.Markup.XamlParseException,给出: Additional information: 'The invocation of the constructor on type 'myproject_csharp.MainWindow' that matches the specified binding constraints threw an exception.' Line number '7'
Additional information: 'The invocation of the constructor on type 'myproject_csharp.MainWindow'
that matches the specified binding constraints threw an exception.' Line number '7' and line
position '9'.
在此位置,我从外部DLL调用一个函数,该DLL需要一个变量参数列表:
int pos = 0;
res = myfunc_init(ref pos,__arglist(several parameters here));
此函数本身定义为
[DllImportAttribute("my.dll", EntryPoint = "myfunc_init_api", CharSet = CharSet.Ansi, CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
public static extern uint myfunc_init(ref int var, __arglist);
从我看来,一切都是正确的。那么,这一例外从何而来?变量参数列表有问题吗
需要注意的一点是:在IDE中,函数被标记为错误,并带有“无重载,因为方法需要2个参数”,但int编译时没有错误
谢谢 我会尝试在构造函数外部调用此函数。在引导程序的主窗口外调用它,或在构造函数后触发它,或在后台调用它,如: 在构造函数调用中:
Task.Run(() => Init());
然后
private static void Init() {
try {
int pos = 0;
res = myfunc_init(ref pos,__arglist(several parameters here));
//Call OnPropertyChanged() for relevant UI Elements
} catch(Exception ex) {
//Do error handling outside the constructor...
}
}
如果您这样做,XAML将加载,然后您可以分别处理错误。由于没有错误,因此很难准确地确定异常是如何引发的。。。但文章中显示的代码可能不起作用(假设您试图将数组作为单独的参数()传递)。。。