我有一个CustomAction,可以根据云数据库检查许可证密钥。这使用异步方法在继续之前等待响应。
当我在CustomAction之外测试下面的方法时,它工作正常;发送请求,任务等待完成,返回结果。
当我在CustomAction中使用相同的方法时,我可以看到(使用调试)一旦t.Wait()行被击中,Dialog立即进入“过早结束”页面。
是否有我缺少的东西或任务 - 特别是等待异步任务 - 在CustomActions中无法实现?
[CustomAction]
public static ActionResult LicenseCheck(Session session)
{
#if DEBUG
System.Diagnostics.Debugger.Launch();
#endif
// Default Values
ReturnActionResult = ActionResult.Success;
session["PIDACCEPTED"] = "0";
string key = session["PIDKEY"].Replace("-", "");
IEnumerable<ParseObject> results = ParseCustom.StartQueryRequest("Store", "Key", key);
// Not making it past this point
...
public static class ParseCustom
{
public static IEnumerable<ParseObject> StartQueryRequest(string className, string key, string value)
{
Task<IEnumerable<ParseObject>> t = DoWorkAsync(className, key, value);
t.Wait(); // Hitting this line in CustomAction causes instant Failure, doesnt get past this line
return t.Result;
}
private static Task<IEnumerable<ParseObject>> DoWorkAsync(string className, string key, string value)
{
return Task<IEnumerable<ParseObject>>.Factory.StartNew(() =>
{
var x = AsyncTaskHelper(className, key, value);
return x.Result;
});
}
private static Task<IEnumerable<ParseObject>> AsyncTaskHelper(string className, string key, string value)
{
return Task.Run(async () =>
{
IEnumerable<ParseObject> ParseResults = await AccessParseAsync(className, key, value);
return ParseResults;
});
}
private static async Task<IEnumerable<ParseObject>> AccessParseAsync(string className, string key, string value)
{
ParseQuery<ParseObject> query = ParseObject.GetQuery(className).WhereEqualTo(key, value);
IEnumerable<ParseObject> parseResults = await query.FindAsync();
return parseResults;
}
}
templog进行:
MSI (c) (0C:BC) [09:24:13:569]: Doing action: LicenseCheckAction
Action 9:24:13: LicenseCheckAction.
Action start 9:24:13: LicenseCheckAction.
MSI (c) (0C:04) [09:24:13:591]: Invoking remote custom action. DLL: C:\Users\dirt\AppData\Local\Temp\MSIFF5.tmp, Entrypoint: LicenseCheck
MSI (c) (0C:F0) [09:24:13:592]: Cloaking enabled.
MSI (c) (0C:F0) [09:24:13:592]: Attempting to enable all disabled privileges before calling Install on Server
MSI (c) (0C:F0) [09:24:13:592]: Connected to service for CA interface.
MSI (c) (0C!A4) [09:24:16:819]: PROPERTY CHANGE: Adding PIDACCEPTED property. Its value is '0'.
Action ended 9:24:16: LicenseCheckAction. Return value 3.
DEBUG: Error 2896: Executing action LicenseCheckAction failed.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2896. The arguments are: LicenseCheckAction, ,
Action ended 9:24:16: WelcomeDlg. Return value 3.
MSI (c) (0C:BC) [09:24:16:873]: Doing action: FatalError
Action 9:24:16: FatalError.
Action start 9:24:16: FatalError.
Action 9:24:16: FatalError. Dialog created
Action ended 9:32:02: FatalError. Return value 2.
Action ended 9:32:02: INSTALL. Return value 3.
MSI (c) (0C:BC) [09:32:02:489]: Destroying RemoteAPI object.
MSI (c) (0C:F0) [09:32:02:489]: Custom Action Manager thread ending.
答案 0 :(得分:0)
这最终与WiX无关,问题出在CustomAction代码本身,而不是正确初始化。
感谢@Stephan Cleary提醒我将代码放在try catch
块中,这给了我一些我遗漏的异常细节。