为什么 FireError 在 C# 2012 中失败,但在 VB 中有效,而 FireInformation 在两者中都有效? [英] Why does FireError fail in C# 2012, but works in VB, while FireInformation works in both?

查看:19
本文介绍了为什么 FireError 在 C# 2012 中失败,但在 VB 中有效,而 FireInformation 在两者中都有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2014 中有一个 SSIS 包,如果有任何记录遍历 3rd 方转换的特定路径,我想在脚本组件中引发错误.我想要在 C# 2012 中这样做,但是 FireError 方法给出了一个错误:

I have an SSIS package in Visual Studio 2014, and I want to raise an error in a Script Component if any records traverse a particular path out of a 3rd party transformation. I WANT to do this in C# 2012, but the FireError method gives an error:

'Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100.FireError(int, string, string, string, int, out bool)'的最佳重载方法匹配有一些无效参数

The best overloaded method match for 'Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100.FireError(int, string, string, string, int, out bool)' has some invalid arguments

当我尝试这样做时:

    bool fireAgain = false;
    IDTSComponentMetaData100 myMetaData;
    myMetaData = this.ComponentMetaData;
    myMetaData.FireError(0, "Script Component", "Invalid Records", string.Empty, 0, ref fireAgain);

但是如果我将 FireError 更改为 FireInformation,它会编译并工作——当然,我需要引发错误,而不是信息事件.

but if I change FireError to FireInformation, it compiles and works -- except of course I need an error raised, not an informative event.

此外,如果我使用 Visual Basic 而不是 C#,则:

Also, if I use Visual Basic instead of C# as so:

    Dim pbFireAgain As Boolean = False
    Dim myMetaData As IDTSComponentMetaData100
    myMetaData = Me.ComponentMetaData
    myMetaData.FireError(0, "Script Component", "Invalid Records", String.Empty, 0, pbFireAgain)

我的意思是,字面上完全相同,但使用不同的语言,它工作正常.VB 也适用于 FireInformation.

Which is, I mean, literally the same exact thing but in a different language, it works fine. VB also works with FireInformation.

显然我可以通过使用 VB 来解决我眼前的问题,但有人能告诉我为什么会这样吗?这似乎是 C# 的一个特定问题.作为证据,我们在 MSDN 上有这个:https://msdn.microsoft.com/en-us/library/ms136031.aspx

Obviously I can solve my immediate problem by using VB, but can someone tell me WHY this is this way? It seems like a specific issue with C#. As evidence, we have this on MSDN: https://msdn.microsoft.com/en-us/library/ms136031.aspx

FireError 的脚本组件版本是八个示例中唯一没有 C# VB 版本(日志记录格式很差,但它们都是那里).

Where the Script Component version of FireError is the only of eight examples to not have C# and VB versions (the logging one is poorly formatted, but they're both there).

我想知道是否有调试器配置威胁以奇怪的方式运行 C# 代码,如 this stackoverflow question 已回答,但我得到的错误是在设计时 - Visual Studio 在之前弹出早期的无效参数"错误我编译,所以它知道有什么不对.

I'm wondering if there's a debugger configuration that threatens to run C# code in an odd way, as this stackoverflow question answered, but the error I get is at design time -- Visual Studio springs the earlier "invalid arguments" error before I compile, so it knows something is off.

想法?

推荐答案

您可能会混淆用于从脚本组件(数据流任务)和脚本任务(控制流)触发错误与信息事件的相似但不同的语法.Component的intellisense表示参数是pbCancel,而fireAgain对应的是Information Task的参数.

You may be confusing the similar but different syntax for firing error vs information events from Script Components (data flow task) versus Script Tasks (control flow). The intellisense for Component indicates that the parameter is pbCancel whereas the fireAgain corresponds to the Information Task's parameter.

C# 脚本组件示例

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
    bool cancel = false;
    bool fireAgain = false;
    this.ComponentMetaData.FireInformation(0, "My sub", "info", string.Empty, 0, ref fireAgain);
    this.ComponentMetaData.FireError(0, "My sub", "error", string.Empty, 0, out cancel);
}

VB 组件

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    Dim cancel As Boolean
    Dim fireAgain As Boolean
    Me.ComponentMetaData.FireInformation(0, "my sub", "info", String.Empty, 0, fireAgain)
    Me.ComponentMetaData.FireError(0, "I hate vb", "Error", String.Empty, 0, cancel)
End Sub

没有必要明确指定参数是按引用,因为这似乎是在定义中完成的,而 C# 要求也在调用时指定它.ByRef 与 ByVal 的澄清

There's no need to explicitly specify that a parameter is By Reference since that appears to be done in the definition versus the C# requirement to specify it also on invocation. ByRef vs ByVal Clarification

C#

    public void Main()
    {
        bool fireAgain = false;
        this.Dts.Events.FireInformation(0, "my sub", "info", string.Empty, 0, ref fireAgain);
        // Note, no cancel available
        this.Dts.Events.FireError(0, "my sub", "error", string.Empty, 0);
    }

VB

Public Sub Main()
    Dim fireAgain As Boolean = False
    Me.Dts.Events.FireInformation(0, "my sub", "info desc", String.Empty, 0, fireAgain)
    Me.Dts.Events.FireError(0, "my sub", "error desc", String.Empty, 0)

    Dts.TaskResult = ScriptResults.Success
End Sub

总结

  • C# 要求您指定 refout 关键字.它们不是同义词
  • VB 让你做任何事
  • 组件中的错误事件有一个取消参数
  • Summary

    • C# requires you to specify ref and out keywords. They are not synonyms
    • VB lets you do whatever
    • Error event in Components have a cancel parameter
    • 这篇关于为什么 FireError 在 C# 2012 中失败,但在 VB 中有效,而 FireInformation 在两者中都有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆