为什么FireError在C#2012中失败,但是在VB中起作用,而FireInformation在这两者中都能起作用? [英] Why does FireError fail in C# 2012, but works in VB, while FireInformation works in both?

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

问题描述

我在Visual Studio 2014中拥有一个SSIS包,并且如果任何记录经过第三者转换后的特定路径,我想在脚本组件中引发错误.我在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#代码,例如

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的智能感知指示参数为pbCancel,而fireAgain对应于信息任务的参数.

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天全站免登陆