Skip to content

.net 5 works poorly with latest preview prerelase. #103

@powercode

Description

@powercode

When using a XUnit test project, System.Numerics.Vectors and System.Runtime.CompilerServices.Unsafe are already loaded in the process when the a module initializer is run. That is as early as can be.

	public static class ModInit
	{
		[ModuleInitializer]
		public static void Init()
		{
			try
			{				
				if (!MSBuildLocator.IsRegistered)
				{
					MSBuildLocator.RegisterDefaults();
				}
			}
			catch (InvalidOperationException ex)
			{
				System.Diagnostics.Trace.WriteLine(ex);
			}
		}
	}
Microsoft.Build.Locator.MSBuildLocator.RegisterInstance was called, but MSBuild assemblies were already loaded.
Ensure that RegisterInstance is called before any method that directly references types in the Microsoft.Build namespace has been called.
This dependency arises from when a method is just-in-time compiled, so if it breaks even if the reference to a Microsoft.Build type has not been executed.
For more details, see aka.ms/RegisterMSBuildLocator
Loaded MSBuild assemblies: System.Numerics.Vectors, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

So having these assemblies in the vector

        private static readonly string[] s_msBuildAssemblies =
        {
            "Microsoft.Build",
            "Microsoft.Build.Engine",
            "Microsoft.Build.Framework",
            "Microsoft.Build.Tasks.Core",
            "Microsoft.Build.Utilities.Core",
            "System.Runtime.CompilerServices.Unsafe",
            "System.Numerics.Vectors"
        };

seems like a bad idea.

If they are needed as a dependency, that should be separated from if there are msbuild assemblies loaded in the process.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions