Skip to content

NullReferenceException when calling Vector<float>.CopyTo in Release mode #19240

Closed

Description

@bbarry

I'm not sure if this is the right place to report this.

I have this program:

using System;
using System.Numerics;

namespace ConsoleApp1
{
    public class Program
    {
        public static Vector<int> ConvertToInt32(Vector<float> input)
        {
            var count = Vector<float>.Count;
            var inputs = new float[count];
            var outputs = new int[count]; // swap
            input.CopyTo(inputs);         // these
            for (int i = 0; i < count; i++)
            {
                outputs[i] = (int)inputs[i];
            }
            return new Vector<int>(outputs);
        }

        public static void Main(string[] args)
        {
            var v = new Vector<float>(123.123f);
            var values = ConvertToInt32(v);
            Console.WriteLine(v);
            Console.WriteLine(values);
        }
    }
}

project.json:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true,
    "optimize": true
  },
  "runtimes": {
    "win7-x64": {}
  },

  "dependencies": {
    "System.Numerics.Vectors": "4.1.1"
  },

  "frameworks": {
    "net461": {}
  }
  /*
  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    },
    "System.Numerics.Vectors": "4.1.1"
  },

  "frameworks": {
    "netcoreapp1.0": {}
  }
  */
}

test cases:

  1. targeting net461, compiling as shown, Release mode: null ref on input.CopyTo(inputs);
  2. targeting net461, swapping indicated lines, Release mode: incorrect console output
  3. targeting net461, as shown or swapped, Debug mode: no error, correct output
  4. targeting netcoreapp1.0, either as shown or swapped, Debug or Release: no error, correct output

version info:

Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3

Activity

  1. mellinoe commented on Nov 4, 2016

    @mellinoe
    Contributor

    @CarolEidt Note, only repro'ing on net461, not .NET Core.

  2. karelz commented on Nov 5, 2016

    @karelz
    Member

    In general we don't use GitHub to track full .NET Framework bugs. That's what Connect or MS support is.
    If you don't think there is any advice/workaround we can give, please close this bug.

  3. transferred this issue fromdotnet/corefxon Jan 31, 2020
  4. added this to the 2.0.0 milestone on Jan 31, 2020
  5. ghost locked as resolved and limited conversation to collaborators on Dec 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions