Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Result builder throwing null reference exception #892

Closed
blair55 opened this issue Feb 25, 2019 · 5 comments
Closed

Result builder throwing null reference exception #892

blair55 opened this issue Feb 25, 2019 · 5 comments

Comments

@blair55
Copy link

blair55 commented Feb 25, 2019

I'm not sure if this is the right place but I've eliminated all libraries other than Expecto which I'm sure is not related. It only exists to help demonstrate.

Repro steps

Checkout this repo and run dotnet run -p tests.
https://github.com/blair55/ResultBuilder-IssueRepro

Expected behavior

The test case should pass.

Actual behavior

The test case fails with System.NullReferenceException: Object reference not set to an instance of an object.

Known workarounds

The issue can be resolved by moving all the code from src/Program.fs into tests/Main.fs and re-pointing the test at the new function.

Related information

Provide any related information

  • Operating system: MacOS Sierra 10.12
  • Version: dotnet core 2.1.302
@dsyme
Copy link
Contributor

dsyme commented Feb 25, 2019

This is an unfortunate known issue when unit-testing Exe projects that don't have an explicit [<EntryPoint>] main method.

Either

  1. Change your project to a Library, or
  2. Give your Exe project an explicit [<EntryPoint>]

@dsyme
Copy link
Contributor

dsyme commented Feb 25, 2019

cc @cartermp for visibility. It would be great if we could somehow give a proper error/warning about this

@blair55
Copy link
Author

blair55 commented Feb 26, 2019

Thanks @dsyme, have resolved with option 2.

However, I couldn't get option 1 to work?

Happy to close if issue is a dupe.

@cartermp
Copy link
Member

@blair55 if your project file is like this it should work:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>

  <Import Project="..\.paket\Paket.Restore.targets" />
</Project>

@blair55
Copy link
Author

blair55 commented Feb 26, 2019

@cartermp yep, you're right. Not sure what I was doing earlier but works with that tweak now 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants