Is it possible to retrieve line numbers corresponding to source code when throwing an exception for a Power Platform Plugin Package?
Background
- Plugin Packages are built as
nuget
packages and registered on against the Power Platform - Packages are locked into .NET version
net462
as an SDK style project - Normally when throwing an exception, the stack trace is present, but line numbers are not
- In this process I’m building in
debug
mode
Code
- When using the following code: (link to github with full project below in the Links section)
try
{
logic.ThrowException();
}
catch (Exception ex)
{
var stackTrace = new StackTrace(ex, true);
var linenumber = stackTrace.GetFrame(0).GetFileLineNumber();
var file = stackTrace.GetFrame(0).GetFileName();
var method = stackTrace.GetFrame(0).GetMethod();
localPluginContext.Trace($@"
{nameof(linenumber)}: {linenumber},
{nameof(file)}: {file},
{nameof(stackTrace)}: {stackTrace}");
}
- I get the following trace output:
[+923ms] - [Execute] - Entered PluginStackTraceTest.StackTraceTestPlugin.Execute() Correlation Id: f12333aa-1894-4aa2-b5d5-f600e146e0ea, Initiating User: 1b4822ba-b1c5-eb11-8235-0022480a9839
[+0ms] - [ExecuteDataversePlugin] - Test 7
[+0ms] - [ExecuteDataversePlugin] -
linenumber: 0,
file: ,
stackTrace: at PluginStackTraceTest.Logic.StackTraceTestLogic.ThrowException()
at PluginStackTraceTest.StackTraceTestPlugin.ExecuteDataversePlugin(ILocalPluginContext localPluginContext)
[+0ms] - [Execute] - Exiting PluginStackTraceTest.StackTraceTestPlugin.Execute()
What I’ve Tried
- I’ve added a
Directory.Build.props
file as specified in this SO Post: Include pdb files into my nuget (nupkg) files - I’ve also set the properties in the
.csproj
file
<PropertyGroup>
<!-- Based on https://devblogs.microsoft.com/dotnet/producing-packages-with-source-link/ -->
<!-- Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<!-- Embed source files that are not tracked by the source control manager in the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<EmbedSources>True</EmbedSources>
<!-- Embed symbols containing Source Link in the main file (exe/dll) -->
<DebugType>embedded</DebugType>
<ExcludeGeneratedDebugSymbol>False</ExcludeGeneratedDebugSymbol>
</PropertyGroup>
- I’ve inspected the
nuget
package with dotpeek and confirmed that thepdb
metadata is present in the package - I’m assuming the metadata has been merged with the
dll
because when I unzip the package I see: - I’ve also tried adding the parameter:
<IncludeSymbols>true</IncludeSymbols>
to thePropertyGroup
, but then that just makes a separatesymbols
file:
Any suggestions / recommendations would be greatly appreciated and thanks in advance.
Links
cli-create-package
github repo – PluginStackTraceTest