Skip to content

Support usage in Jupyter notebooks #1207

@ralfw

Description

@ralfw

Description

When using FluentAssertions in a C# Jupyter notebook and the assertion fails, the exception is not pertaining to the actual mismatch, but regarding missing infrastructure.

Complete minimal example reproducing the issue

fluentassertions failure in jupyter notebook

Expected behavior:

The expected exception for the above example is:

Expected value to be 99, but found 1.
   at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message)
   at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
   at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
   ...

Actual behavior:

The actual exception is:

Unhandled Exception
Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (0x80131058)
   at FluentAssertions.Common.AppSettingsConfigurationStore.GetSetting(String name)
   at FluentAssertions.Common.Configuration.get_ValueFormatterAssembly() in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Common\Configuration.cs:line 88
   at FluentAssertions.Common.Configuration.DetermineFormatterDetectionMode() in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Common\Configuration.cs:line 55
   at FluentAssertions.Common.Configuration.get_ValueFormatterDetectionMode() in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Common\Configuration.cs:line 40
   at FluentAssertions.Formatting.AttributeBasedFormatter.get_IsScanningEnabled() in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Formatting\AttributeBasedFormatter.cs:line 33
   at FluentAssertions.Formatting.AttributeBasedFormatter.CanHandle(Object value) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Formatting\AttributeBasedFormatter.cs:line 28
   at FluentAssertions.Formatting.Formatter.<>c__DisplayClass7_0.<Format>b__0(IValueFormatter f) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Formatting\Formatter.cs:line 138
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
   at FluentAssertions.Formatting.Formatter.Format(Object value, FormattingContext context, FormatChild formatChild) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Formatting\Formatter.cs:line 138
   at FluentAssertions.Formatting.Formatter.ToString(Object value, Boolean useLineBreaks) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Formatting\Formatter.cs:line 97
   at FluentAssertions.Execution.MessageBuilder.<FormatArgumentPlaceholders>b__6_0(Object a) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\MessageBuilder.cs:line 91
   at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
   at FluentAssertions.Execution.MessageBuilder.FormatArgumentPlaceholders(String failureMessage, Object[] failureArgs) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\MessageBuilder.cs:line 91
   at FluentAssertions.Execution.MessageBuilder.Build(String message, Object[] messageArgs, String reason, ContextDataItems contextData, String identifier, String fallbackIdentifier) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\MessageBuilder.cs:line 40
   at FluentAssertions.Execution.AssertionScope.<>c__DisplayClass30_0.<FailWith>b__0() in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\AssertionScope.cs:line 200
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\AssertionScope.cs:line 216
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\AssertionScope.cs:line 196
   at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\AssertionScope.cs:line 238
   at FluentAssertions.Numeric.NumericAssertions`1.Be(T expected, String because, Object[] becauseArgs) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Numeric\NumericAssertions.cs:line 51
   at Submission#7.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)

The behavior does not change if #r "nuget:System.Configuration.ConfigurationManager" is added to the cell before loading FluentAssertions.

Versions

  • Which version of Fluent Assertions are you using? The latest version downloaded by the #r statement.
  • Which .NET runtime and version are you targeting? The latest .NET Core version installed into the Jupyter Docker image.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions