1

我有一个针对云数据库检查许可证密钥的 CustomAction。这使用异步方法在继续之前等待响应。

当我在 CustomAction 之外测试以下方法时,它工作正常;发送请求,任务等待完成,返回结果。

当我在 CustomAction 中使用相同的方法时,我可以看到(使用调试)只要点击 t.Wait() 行,对话框就会立即转到“提前结束”页面。

是否有我遗漏的东西或者任务 - 特别是等待异步任务 - 在 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;
    }
}

临时日志:

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.
4

1 回答 1

0

这最终与 WiX 无关,问题出在 CustomAction 代码本身并且没有正确初始化某些东西。

感谢@Stephan Cleary 提醒我将代码放入try catch块中,这给了我缺少的异常详细信息,我能够解决这个问题。

于 2013-10-14T12:21:55.903 回答