question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

test without namespace causes null ref

See original GitHub issue

The following class

using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
    }
}

in this project

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.2.4" />
    <PackageReference Include="MSTest.TestFramework" Version="2.2.4" />
    <PackageReference Include="coverlet.collector" Version="3.0.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

produces

PS C:\Code\TestProject1> dotnet test
  Determining projects to restore...
  Restored C:\Code\TestProject1\TestProject1\TestProject1.csproj (in 205 ms).
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  TestProject1 -> C:\Code\TestProject1\TestProject1\bin\Debug\net48\TestProject1.dll
Test run for C:\Code\TestProject1\TestProject1\bin\Debug\net48\TestProject1.dll (.NETFramework,Version=v4.8)
Microsoft (R) Test Execution Command Line Tool Version 17.0.0-preview-20210512-01
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[MSTest][Discovery][C:\Code\TestProject1\TestProject1\bin\Debug\net48\TestProject1.dll] MSTestAdapter failed to discover tests in class 'UnitTest1' of assembly 'C:\Code\TestProject1\TestProject1\bin\Debug\net48\TestProject1.dll' because Object reference not set to an instance of an object..
No test is available in C:\Code\TestProject1\TestProject1\bin\Debug\net48\TestProject1.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

PS C:\Code\TestProject1>

Repro

Env

  • Windows 10
  • .NET SDK (6.0.100-preview.5.21302.13)

AB#1633111

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
SimonCroppcommented, Nov 11, 2022

@Evangelink yep it now works with test that have no namespace.

1reaction
SimonCroppcommented, Sep 27, 2022

@Evangelink thanks so much. please reach out if you need someone to do some beta testing of version 3

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# says my namespace causes a NullReferenceException
A namespace can never be null, it will never generate any runtime errors of any kind (in the way you are describing it)....
Read more >
NullReferenceException Class (System)
This exception occurs if you assume that each element of the array must contain a non-null value, and the value of the array...
Read more >
c# - Have the unit test "using" the project, or just have same ...
I've used unit tests project with the same namespace as the real project (by manually removing the Tests suffix on the test project...
Read more >
How to Stop NullReferenceExceptions in .NET
This article gives you a toolset for stopping NullReferenceExceptions in .NET code. The article centers around Nullable Reference Types ...
Read more >
Null Reference Exceptions
A NullReferenceException happens when you try to access a reference variable that isn't referencing any object. If a reference variable isn't referencing an ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found