UnauthorizedAccessException on pdb trying to debug a unit test - visual-studio

If I put a single breakpoint on this method, on the last line, and debug via "Debug selected tests" in the Test Explorer, I get an UnauthorizedAccessException on the pdb of the test assembly and the test aborts.
module Tests
open System
open Xunit
[<Fact>]
let fact () =
let rng = Random ()
let a = rng.Next() % 2 = 0
let b = rng.Next() % 2 = 0
a && b // <- breakpoint here
If I put a breakpoint anywhere else, I can debug fine. I can put a breakpoint on that line and debug if there's a breakpoint somewhere else in the method; the last breakpoint just appears empty (no generated code matches it). Note that the && on the last line seems important, if I remove it the problem goes away. For example this version doesn't exhibit the problem:
[<Fact>]
let fact () =
let rng = Random ()
let a = rng.Next() % 2 = 0
let b = rng.Next() % 2 = 0
let result = a && b
result // can put a breakpoint anywhere and debug fine
I could not repro outside a particular solution containing many other projects that I work on, even using all the exact same references and App.config. I spent already quite some time trying to nail down the issue and am looking for tips at this point. Here they are anyway:
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="xunit.methodDisplay" value="method"/>
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="xunit.core" publicKeyToken="8d05b1bb7a6fdb6c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.3179" newVersion="2.1.0.3179" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FSharp.Core" version="4.0.0.1" targetFramework="net46" />
<package id="xunit" version="2.1.0" targetFramework="net46" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net46" />
<package id="xunit.assert" version="2.1.0" targetFramework="net46" />
<package id="xunit.core" version="2.1.0" targetFramework="net46" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net46" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net46" />
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net46" />
</packages>
Visual Studio Enterprise 2015 Update 3 (Version 14.0.25424.00)

It's a bit of guesswork, but the a && b is an expression rather than a statement, so the breakpoint doesn't get hit.
If the test runner has made a shadow copy of your assembly and PDB, then it might try to delete it after the test completes - but the debugger is still accessing it, leading to the exception.

Assuming you are on the same bitness (using 32bit xunit runner for a 32 bit project), I'm guessing the reason this is breaking is because unit tests should have signature: unit -> unit or in C# terms void.
If you change your first example to return unit, I was able to debug a && b with no issues. Now as to why your second example works even though it has the same return type, I have no idea. Maybe the bug is related to needing to assign a variable to be able do stuff with it in xunit?
[<Fact>]
let fact () =
let rng = Random ()
let a = rng.Next() % 2 = 0
let b = rng.Next() % 2 = 0
a && b // <- breakpoint here works
()

Related

Setting CustomBuild's OutputItemType in a target doesn't work

If you set "Add Outputs to Item Type" property in Custom Build Tool like this,
It will add the following line in .vcxproj file:
<OutputItemType>ClCompile</OutputItemType>
However, when I define my own target and try to use it, it doesn't work.
(...)
<Target Name="__SECompile" BeforeTargets="PreBuildEvent">
<ItemGroup>
<_SECompileMetadataSet Include="#(SECompile)">
<Message>Processing %(Identity)</Message>
<Outputs>$(ProjectDir)intermediate\%(Identity)</Outputs>
<Command>python (path to a python script) "%(FullPath)" "$(ProjectDir)intermediate\%(Identity)"</Command>
<OutputItemType>ClCompile</OutputItemType>
<LinkObjects>false</LinkObjects>
</_SECompileMetadataSet>
</ItemGroup>
(...)
(Below is just a copy-paste from Microsoft.CppCommon.targets)
<!-- Get out of date items (will create tlogs for all SECompile items) -->
<GetOutOfDateItems
Condition ="'$(SelectedFiles)' == ''"
Sources ="#(_SECompileMetadataSet)"
OutputsMetadataName ="Outputs"
DependenciesMetadataName ="AdditionalInputs"
CommandMetadataName ="Command"
TLogDirectory ="$(TLogLocation)"
TLogNamePrefix ="SECompile"
CheckForInterdependencies ="true"
>
<Output TaskParameter="OutOfDateSources" ItemName="_SECompile"/>
</GetOutOfDateItems>
<!-- Buidl items which can be built in parallel (ignored for selected files build)-->
<ItemGroup Condition="'$(SelectedFiles)' == ''">
<_ParallelSECompile Include="#(_SECompile)" />
</ItemGroup>
<ParallelCustomBuild
Condition ="'#(_ParallelSECompile)' != ''"
Sources ="#(_ParallelSECompile)"
MaxProcesses ="0"
MaxItemsInBatch ="0"
AcceptableNonZeroExitCodes =""
/>
(...)
The python script is running and the message is being output, so the other properties are functioning. But OutputItemType doesn't work.
What I'm trying to do is basically do the exact same thing CustomBuild does, with its arguments predefined with specific values.
So the question is:
Why doesn't it work when you set it manually in a target while it should be the same as it was set in the vcxproj file?
Got an answer through Visual Studio Feedback.
Putting
<ItemGroup Condition="'#(_SECompile)' != ''"> <ClCompile Include="%(_SECompile.Outputs)" Condition="'%(_SECompile.ExcludedFromBuild)' != 'true'" /> </ItemGroup>
in the target would work.
Original link: https://developercommunity.visualstudio.com/t/Setting-CustomBuilds-OutputItemType-in/1452940?entry=myfeedback&ref=native&refTime=1624191549072&refUserId=95d48ba8-b75f-4896-8bf5-5745bf012b77

Power Automate - Cloud Flow - Using xpath for parent node attributes

A RESTful API call returns the XML noted below.
I need to loop through various steps for each ShowSurveyAnswerKey. So in this case, 8 of them. Got that working with an "Apply to each" step expression of:
xpath(xml(body('HTTP_Get')),'//ShowSurveyAnswer')
In that "Apply to each", need to know values of ShowSurveyKey, ShowSurveyQuestionKey and ShowSurveyAnswerKey. The only one I can get working is ShowSurveyAnswerKey, which I happen to be testing with an action "Compose" with expression of:
xpath(item(),'string(/ShowSurveyAnswer/#ShowSurveyAnswerKey)')
So really, I can't figure out the parent or ancestor or ../ within Power Automate Compose Expression within the "Apply to each".
All help much appreciated. Thanks!
<?xml version="1.0" encoding="utf-8"?>
<Show ShowKey="123" >
<ShowSurveys>
<ShowSurvey ShowSurveyKey="230151" >
<SurveyQuestions>
<SurveyQuestion ShowSurveyQuestionKey="842125" >
<SurveyAnswers>
<ShowSurveyAnswer ShowSurveyAnswerKey="3316719" />
<ShowSurveyAnswer ShowSurveyAnswerKey="3316720" />
<ShowSurveyAnswer ShowSurveyAnswerKey="3316721" />
</SurveyAnswers>
</SurveyQuestion>
</SurveyQuestions>
</ShowSurvey>
<ShowSurvey ShowSurveyKey="217418" >
<SurveyQuestions>
<SurveyQuestion ShowSurveyQuestionKey="808668" >
<SurveyAnswers>
<ShowSurveyAnswer ShowSurveyAnswerKey="3192170" />
<ShowSurveyAnswer ShowSurveyAnswerKey="3192174" />
</SurveyAnswers>
</SurveyQuestion>
<SurveyQuestion ShowSurveyQuestionKey="808669" >
<SurveyAnswers>
<ShowSurveyAnswer ShowSurveyAnswerKey="3192175" />
<ShowSurveyAnswer ShowSurveyAnswerKey="3192176" />
<ShowSurveyAnswer ShowSurveyAnswerKey="3192177" />
</SurveyAnswers>
</SurveyQuestion>
</SurveyQuestions>
</ShowSurvey>
</ShowSurveys>
</Show>

SI <int-xml:xpath-filter /> behavior

I have a scenario where I am filtering a xml payload based on a xpath value.
<int:channel id="documentReceiptFilterChannel" />
<int:chain input-channel="documentReceiptFilterChannel" output-channel="nullChannel">
<!-- Filter to discard message if <statusCode> value is 'EMLOK' -->
<int-xml:xpath-filter match-type="regex" match-value="^(?!\bEMLOK\b).*$" discard-channel="nullChannel">
<int-xml:xpath-expression expression="//*[local-name()='statusCode']" />
</int-xml:xpath-filter>
<int:service-activator expression="#opsLogger.logError('TransactionId=' + headers.correlationId, ' Msg=' + #opsExceptionUtils.createOPSExceptionInstance(#root))" />
</int:chain>
Following is the payload:
<?xml version="1.0" encoding="UTF-8"?>
<GetDocumentReceiptReply xmlns="http://example.org"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<mergeReceiptDeliveryStatus>
<statusCode>EMLOK</statusCode>
</mergeReceiptDeliveryStatus>
</GetDocumentReceiptReply>
My requirement is that when <statusCode>EMLOK</statusCode> element is available, discard the message and hence nullChannel is mentioned as discard-channel.
But then there is any other value, proceed to the next step in the chain and do the error logging - <int:service-activator expression="#opsLogger.logError().
The above setup works fine as long as <statusCode> element is present in the payload. But doesn't work on the following situations:
<statusCode></statusCode>
<statusCode/>
<statusCode> is missing
Or any other xml payload
To get rid of namespace issues, the xpath expression is formed as <int-xml:xpath-expression expression="//*[local-name()='statusCode']" />. The xpath value is matched against regex expression match-type="regex" match-value="^(?!\bEMLOK\b).*$" (For value != 'EMLOK').
What happens when <int-xml:xpath-expression /> evaluation fails?
My only requirement is that if <statusCode>EMLOK</statusCode> is present, discard the message, else for all other, log an error in the log file. (And not to throw an exception that will propagate to error-channel).
You could write a custom subclass of AbstractXPathMessageSelector and delegate to a BooleanTestXPathMessageSelector and a RegexTestXPathMessageSelector, or simply use 2 filters...
<int:chain input-channel="documentReceiptFilterChannel" output-channel="errors">
<int-xml:xpath-filter discard-channel="errors">
<int-xml:xpath-expression expression="//*[local-name()='statusCode']" />
</int-xml:xpath-filter>
<int-xml:xpath-filter match-type="regex" match-value="^(?!\bEMLOK\b).*$">
<int-xml:xpath-expression expression="//*[local-name()='statusCode']" />
</int-xml:xpath-filter>
</int:chain>
<int:service-activator
expression="#opsLogger.logError('TransactionId=' + headers.correlationId, ' Msg=' + #opsExceptionUtils.createOPSExceptionInstance(#root))" />
Notice that you don't need to discard to nullChannel - just omitting the discard channel will cause discards. Messages that pass the second filter go to the chain's output channel.
The custom selector would be a little more efficient because only one conversion to node is needed.

SSIS For Loop resetting the variable value

In SSIS (MS Visual Studio 2010) I have created a SQL Task with Single Row output (int32) that is passed to User::Variable. Then I have a "For Loop" that I want to run as many times as the integer from the SQL Task query equals to. I have setup the For Loop with the following:
InitExpression: #Start = 1
EvalExpression: #Variable >= #Start
AssignExpression: #Start = #Start+1
In my test example, the #Variable is set to 4 by SQL Task query, and the loop runs fine for the first loop, but then immediately finishes reporting package successfully executed (after just 1 loop when it should have looped 4 times).
It is like the #Variable resets to default value (0) after the first loop is done instead of keeping the original value (4).
How can I fix this?
What's more likely: using the name Variable, which SSIS defaults to for a new variable, is incompatible with anything in an SSIS package or that you've done something that you haven't shown?
I have created a package with two Variables, Variable and Start. I have populated Variable from a SQL Query with the value of 4 and then used a For Loop as described and I did not experience early termination.
My package, variables with design time values set to zero.
My For Loop Container
Last iteration of the loop
Reproducible results
Biml, the Business Intelligence Markup Language, describes the platform for business intelligence. Here, we're going to use it to describe the ETL. BIDS Helper, is a free add on for Visual Studio/BIDS/SSDT that addresses a host of shortcomings with it.
You will need to edit line 3 to be a valid OLE DB Connection Manager for your machine (point to a SQL Server installation and possibly update the Provider)
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<OleDbConnection Name="CM_OLE" ConnectionString="Data Source=localhost\dev2012;Initial Catalog=tempdb;Provider=SQLNCLI11;Integrated Security=SSPI;" />
</Connections>
<Packages>
<Package Name="so_25878932" ConstraintMode="Linear">
<Variables>
<Variable Name="Variable" DataType="Int32">0</Variable>
<Variable Name="Start" DataType="Int32">0</Variable>
</Variables>
<Tasks>
<ExecuteSQL ConnectionName="CM_OLE" Name="SQL Variable" ResultSet="SingleRow">
<DirectInput>SELECT 4 AS Variable;</DirectInput>
<Results>
<Result Name="0" VariableName="User.Variable"/>
</Results>
</ExecuteSQL>
<ForLoop ConstraintMode="Linear" Name="FLC Go">
<InitializerExpression>#Start = 1</InitializerExpression>
<LoopTestExpression>#Variable >= #Start</LoopTestExpression>
<CountingExpression>#Start = #Start + 1</CountingExpression>
<Tasks>
<!--
Pilfered from http://bimlscript.com/Snippet/Details/74
-->
<Script
ProjectCoreName="ST_232fecafb70a4e8a904cc21f8870eed0"
Name="SCR Emit Variable and Start">
<ReadOnlyVariables>
<ReadOnlyVariable VariableName="User.Variable" />
<ReadOnlyVariable VariableName="User.Start" />
</ReadOnlyVariables>
<ScriptTaskProject>
<ScriptTaskProject ProjectCoreName="ST_c41ad4bf47544c49ad46f4440163feae" Name="TaskScriptProject1">
<AssemblyReferences>
<AssemblyReference AssemblyPath="Microsoft.SqlServer.ManagedDTS.dll" />
<AssemblyReference AssemblyPath="Microsoft.SqlServer.ScriptTask.dll" />
<AssemblyReference AssemblyPath="System.dll" />
<AssemblyReference AssemblyPath="System.AddIn.dll" />
<AssemblyReference AssemblyPath="System.Data.dll" />
<AssemblyReference AssemblyPath="System.Windows.Forms.dll" />
<AssemblyReference AssemblyPath="System.Xml.dll" />
</AssemblyReferences>
<Files>
<File Path="AssemblyInfo.cs">
using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("ST_c41ad4bf47544c49ad46f4440163feae.csproj")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Varigence")]
[assembly: AssemblyProduct("ST_c41ad4bf47544c49ad46f4440163feae.csproj")]
[assembly: AssemblyCopyright("Copyright # Varigence 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.*")]
</File>
<File Path="ScriptMain.cs">
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
// if SSIS2012, use the following line:
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
// if earlier version, use the next line instead of the above line:
// [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
public void Main()
{
int i = 0;
MessageBox.Show(string.Format("{0}:{1}", Dts.Variables[i].Name, Dts.Variables[i].Value));
i++;
MessageBox.Show(string.Format("{0}:{1}", Dts.Variables[i].Name, Dts.Variables[i].Value));
Dts.TaskResult = (int)ScriptResults.Success;
}
}
</File>
</Files>
</ScriptTaskProject>
</ScriptTaskProject>
</Script>
<ExecuteProcess Executable="cmd.exe" Name="EP Do nothing" Arguments="/C">
</ExecuteProcess>
</Tasks>
</ForLoop>
</Tasks>
</Package>
</Packages>
</Biml>
Root cause guess
Variables can be created at different scopes within a package. I would presume that since a variable is created with the default name of Variable two, or more, such variables exist with the same name but at different application scopes. Thus, if I had defined a second SSIS variable named Variable on my ForLoop Container, it would start with a value of 0, unless defined otherwise. My package execution would begin, assign the value of 4 to my package level Variable. Control switches to my ForLoop Container. The Variable defined there wins from a scoping perspective so my value there is 0, not 4 because nothing has initialized it. In that case, the ForLoop would never fire as the terminal condition has already been met. For your case, I further presume that someone initialized that variable to 1.
Notice the Scope here, this is what I believe to be your root cause.
Solution:
DO NOT name SSIS variables #Variable. Doing so will unintentionally cause the variable value to pick up exit codes of other processes in the package as they run.
In my case the #Variable value would automatically change to 0 after a successfully run Execute Process Task with exit code 0; or change to -1073741510 when that process run failed.

Get children and subchildren together?

I am using lxml library in python and I am working with xpath.I have a an xml file example as follows:
<Root>
<Child1 name="child1">
<Child2 name="child2" />
</Child1>
<Child3 name="child3">
<Child4 name="child4" />
</Child3>
<Child5 name="child5" />
</Root>
i need to know if there is a way to get all children at once like child1,child2,child3,child4 at once... currently I am able to get only child1, child3, child5 using root.xpath('node()')

Resources