IntelliTrace Arguments By Reference

久未见 提交于 2019-12-12 03:47:43

问题


Using IntelliTrace, I'm unable to see the output of a string passed by reference into a method and the result of the method in the same event (or at all).

Method example:

public bool ByReferenceTestMethod(System.ArgumentNullException exception, ref string referenceArgument)
{
    referenceArgument = string.Format("referenceArgument{0}", exception.Message);
    return true;
}

collectionplan.xml example working without reference argument reference:

<DiagnosticEventSpecification>
    <CategoryId>stackoverflow.test.application</CategoryId>
    <SettingsName _locID="settingsName.Test.Application.Reference">VerifyIDFromBackEnd called</SettingsName>
    <SettingsDescription _locID="settingsDescription.Test.Application.Reference">VerifyIDFromBackEnd was called</SettingsDescription>
    <Bindings>
        <Binding onReturn="false">
            <ModuleSpecificationId>stackoverflow.test.application</ModuleSpecificationId>
            <MethodName>ByReferenceTestMethod</MethodName>
            <MethodId>Test.Application.TestClass.ByReferenceTestMethod(System.ArgumentException,System.String&amp;):System.Boolean</MethodId>
            <ShortDescription _locID="shortDescription.Test.Application.Reference.called">Method 'ByReferenceTestMethod' called</ShortDescription>
            <LongDescription _locID="longDescription.Test.Application.Reference.called">ByReferenceTestMethod called with ArgumentException parameter name "{0}" and message "{1}"</LongDescription>
            <TypeName>Test.Application.TestClass</TypeName>
            <DataQueries>
                <DataQuery index="1" maxSize="2048" type="String" name="Exception parameter" _locID="dataquery.Test.Application.Reference.exception.Paramname" query="m_paramName" />
                <DataQuery index="1" maxSize="2048" type="String" name="Exception message" _locID="dataquery.Test.Application.Reference.exc5eption.Message" _locAttrData="name" query="_message" />
        </DataQueries>
        </Binding>
        <Binding onReturn="true">
            <ModuleSpecificationId>stackoverflow.test.application</ModuleSpecificationId>
            <MethodName>ByReferenceTestMethod</MethodName>
            <MethodId>Test.Application.TestClass.ByReferenceTestMethod(System.Exception,System.String&amp;):System.Boolean</MethodId>
            <ShortDescription _locID="shortDescription.Test.Application.Reference.result">Method 'ByReferenceTestMethod' completed</ShortDescription>
            <LongDescription _locID="longDescription.Test.Application.Reference.result">ByReferenceTestMethod returned result "{0}" with an unknown referenceArgument</LongDescription>
            <TypeName>Test.Application.TestClass</TypeName>
            <DataQueries>
                <DataQuery index="-1" maxSize="0" type="Boolean" name="Reference Result" _locID="dataquery.Test.Application.Reference.result" _locAttrData="name" query="" />
            </DataQueries>
        </Binding>
    </Bindings>
</DiagnosticEventSpecification>

collectionplan.xml example not working with reference argument reference:

<LongDescription _locID="longDescription.Test.Application.Reference.result">ByReferenceTestMethod returned result "{0}" with referenceArgument "{1}"</LongDescription>
<TypeName>Test.Application.TestClass</TypeName>
<DataQueries>
    <DataQuery index="-1" maxSize="0" type="Boolean" name="Reference Result" _locID="dataquery.Test.Application.Reference.result" _locAttrData="name" query="" />
    <DataQuery index="2" maxSize="4096" type="String" name="referenceArgument" _locID="dataquery.Test.Application.Reference.Reference.Value" _locAttrData="name" query="" />
</DataQueries>

This shows the LongDescription without the resolved markers and if I change the order the message itself doesn't appear at all.

From what I understand, the ref should appear when onResult="true" because that event isn't evaluated until after the method returns. If I use place the same argument in the onResult="false" dataquery then it is evaluated before the value is possibly set by the method.

What am I doing wrong?


回答1:


As far as I know you can't do what you want. I tried to do the same thing a few times in the past and it didn't work. However, the problem is not with ref parameters. It will also not work with "normal" parameters.

If you use onReturn="true" then you can only refer to a value that was returned from a method i.e. index="-1". You cannot read values of parameters in this case. It is due to how IntelliTrace works under the hood and I don't know the workaround.

Programmable data queries will also not help. PDQ has two methods to implemented:

  • object[] EntryQuery(object thisArg, object[] args)
  • object[] ExitQuery(object returnValue)

The first one is called to analyse input parameters (onReturn="false") and the second one to analyse a return value (onReturn="false"). Again, in ExitQuery you only have access to a return value.



来源:https://stackoverflow.com/questions/39128665/intellitrace-arguments-by-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!