Skip to content

Does not work on .NET 6 #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hazzik opened this issue Dec 1, 2021 · 12 comments · Fixed by #158
Closed

Does not work on .NET 6 #157

hazzik opened this issue Dec 1, 2021 · 12 comments · Fixed by #158
Milestone

Comments

@hazzik
Copy link
Contributor

hazzik commented Dec 1, 2021

     [exec] Starting 'dotnet (async-generator)' in 'C:\Projects\Private\nhibernate-core\src'
     [exec] AsyncGenerator
     [exec] 
     [exec] Generating async code started
     [exec] System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
     [exec] Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec] Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec] Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec] Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec] Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec] Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec]    at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
     [exec]    at System.Reflection.RuntimeAssembly.get_DefinedTypes()
     [exec]    at System.Composition.Hosting.ContainerConfiguration.<>c.<WithAssemblies>b__16_0(Assembly a)
     [exec]    at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
     [exec]    at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor(IEnumerable`1 types, AttributedModelProvider attributeContext)
     [exec]    at System.Composition.Hosting.ContainerConfiguration.CreateContainer()
     [exec]    at Microsoft.CodeAnalysis.Host.Mef.MefHostServices.Create(IEnumerable`1 assemblies)
     [exec]    at Microsoft.CodeAnalysis.Host.Mef.MSBuildMefHostServices.get_DefaultServices()
     [exec]    at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create(IDictionary`2 properties)
     [exec]    at AsyncGenerator.AsyncCodeGenerator.CreateWorkspace(String targetFramework) in C:\Workspace\Git\AsyncGenerator\Source\AsyncGenerator\AsyncCodeGenerator.cs:line 108
     [exec]    at AsyncGenerator.AsyncCodeGenerator.GenerateAsync(AsyncCodeConfiguration configuration, CancellationToken cancellationToken) in C:\Workspace\Git\AsyncGenerator\Source\AsyncGenerator\AsyncCodeGenerator.cs:line 76
     [exec]    at AsyncGenerator.CommandLine.Program.Main(String[] args) in C:\Workspace\Git\AsyncGenerator\Source\AsyncGenerator.CommandLine\Program.cs:line 59
     [exec] System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec] File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
     [exec] System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec] File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
     [exec] System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec] File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
     [exec] System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec] File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
     [exec] System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec] File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
     [exec] System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
     [exec] File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

@maca88 maca88 linked a pull request Dec 5, 2021 that will close this issue
@maca88 maca88 added this to the 0.20.0 milestone Dec 5, 2021
@maca88
Copy link
Owner

maca88 commented Dec 5, 2021

Published version 0.20.0 which works also with .NET 6.

@hazzik
Copy link
Contributor Author

hazzik commented Dec 7, 2021

Having some issues converting NHibernate.Tests:

 [exec] info: AsyncCodeGenerator[0]
 [exec]       Opening project 'C:\Projects\Private\nhibernate-core\src\NHibernate.Test\NHibernate.Test.csproj' started
 [exec] warn: AsyncCodeGenerator[0]
 [exec]       One or more warnings occurred while opening the project:
 [exec]       Found project reference without a matching metadata reference: C:\Projects\Private\nhibernate-core\src\NHibernate\NHibernate.csproj
 [exec]       Found project reference without a matching metadata reference: C:\Projects\Private\nhibernate-core\src\NHibernate.DomainModel\NHibernate.DomainModel.csproj
 [exec]
 [exec] info: AsyncCodeGenerator[0]
 [exec]       Opening project 'C:\Projects\Private\nhibernate-core\src\NHibernate.Test\NHibernate.Test.csproj' completed
 [exec] info: AsyncCodeGenerator[0]
 [exec]       Configuring project prior analyzation started
 [exec] info: AsyncCodeGenerator[0]
 [exec]       Configuring project prior analyzation completed
 [exec] info: AsyncCodeGenerator[0]
 [exec]       Compiling project 'NHibernate.Test' started
 [exec] info: AsyncCodeGenerator[0]
 [exec]       Compiling project 'NHibernate.Test' completed
 [exec] info: AsyncCodeGenerator[0]
 [exec]       Initializing registered plugins for project 'NHibernate.Test' started
 [exec] crit: AsyncGenerator.CommandLine[0]
 [exec]       Unable to find NUnit.Framework.Assert type
 [exec]       System.InvalidOperationException: Unable to find NUnit.Framework.Assert type
 [exec]          at AsyncGenerator.Core.Plugins.NUnitPlugin.Initialize(Project project, IProjectConfiguration configuration, Compilation compilation) in C:\Workspace\Git\AsyncGenerator\Source\AsyncGenerator.Core\Plugins\NUnitPlugin.cs:line 61
 [exec]          at AsyncGenerator.AsyncCodeGenerator.GenerateProject(ProjectData projectData, ILoggerFactory loggerFactory, ILogger logger, CancellationToken cancellationToken) in C:\Workspace\Git\AsyncGenerator\Source\AsyncGenerator\AsyncCodeGenerator.cs:line 0
 [exec]          at AsyncGenerator.AsyncCodeGenerator.GenerateAsync(AsyncCodeConfiguration configuration, CancellationToken cancellationToken) in C:\Workspace\Git\AsyncGenerator\Source\AsyncGenerator\AsyncCodeGenerator.cs:line 84
 [exec]          at AsyncGenerator.CommandLine.Program.Main(String[] args) in C:\Workspace\Git\AsyncGenerator\Source\AsyncGenerator.CommandLine\Program.cs:line 51

@maca88
Copy link
Owner

maca88 commented Dec 7, 2021

I am able to get this error only on nhibernate/nhibernate-core/pull/2951 pull request. By removing netcoreapp2.0 from the NHibernate test project, the targetFramework inside AsyncGenerator.yml for the test project needs to be changed to either net6.0 or net461. By changing it to net6.0, I noticed that there is a bug with Assert.That that I will fix tomorrow, for ignoring .NET 6 only methods, the following configuration can be added to the test project configuration:

    ignoreSearchForAsyncCounterparts:
    - name: Wait
      containingTypeName: Task
    - name: Prepare
      containingTypeName: DbCommand
    - name: Close
      containingTypeName: DbConnection
    - name: Close
      containingTypeName: DbDataReader

@hazzik
Copy link
Contributor Author

hazzik commented Dec 8, 2021

Thanks

@maca88
Copy link
Owner

maca88 commented Dec 8, 2021

With the newly released version 0.20.1 the mentioned bug for Assert.That method is fixed.

@bahusoid
Copy link

bahusoid commented Dec 13, 2021

Hm.. Installing .NET 6 breaks async generation. I see the same exception as hazzik for master branch. So for master it seems 0.20.1 will solve the problem. What about 5.3 branch? Any workarounds? Trick with global.json no longer works for me with .NET 6 installed

@maca88
Copy link
Owner

maca88 commented Dec 13, 2021

Yea you are right, for some reason global.json does not work for lower .NET Core versions anymore, even when using "rollForward": "disable". I was not able to find any workaround yet. For now, the easiest way to fix the issue would be to port nhibernate/nhibernate-core/pull/2605 in 5.3.x branch. I tried to run 0.20.1 version on 5.3.x branch and it does not produce any code changes.

@bahusoid
Copy link

Alternatively you can publish 0.18.3 version with MsBuildLocator restricted to .NET Core 2.1. So instead of:

var instance = MSBuildLocator.QueryVisualStudioInstances()
.OrderByDescending(o => o.Version)
.FirstOrDefault();

Use something like:

			var instance = MSBuildLocator.QueryVisualStudioInstances()
#if NETCOREAPP2_1
				.Where(o => o.Version.Major == 2)
#endif
				.OrderByDescending(o => o.Version)
				.FirstOrDefault();

@maca88
Copy link
Owner

maca88 commented Dec 14, 2021

In Windows QueryVisualStudioInstances() will return the installed Visual Studios, in my case I get two instances, one for VS2019 and one for VS2022. If VS2019 is selected, then the global.json works and so the code generation. So basically this means that if a developer has only VS2022 installed, it won't work. Based on that, I still think that porting the mentioned PR is a better alternative, but if you disagree I can publish a new version with the proposed logic that would work also on Windows (if VS2019 is installed).

@bahusoid
Copy link

bahusoid commented Dec 14, 2021

In Windows QueryVisualStudioInstances() will return the installed Visual Studios

Did you run it under .NET Core or NetFx? It seems true for NetFx only.

Here is example I run under .NET 6 on Windows with latest Microsoft.Build.Locator 1.4.1:

using Microsoft.Build.Locator;

var instance = MSBuildLocator.QueryVisualStudioInstances()
    //.Where(o => o.Version.Major == 2)
    .OrderByDescending(o => o.Version)
    .ToList();

foreach (var i in instance)
{
    Console.WriteLine(i.Version);
    Console.WriteLine(i.MSBuildPath);
}    

Output I see lists all .NET Core SDKs:

6.0.100
C:\Program Files\dotnet\sdk\6.0.100\
5.0.201
C:\Program Files\dotnet\sdk\5.0.201\
2.1.602
C:\Program Files\dotnet\sdk\2.1.602\
2.1.601
C:\Program Files\dotnet\sdk\2.1.601\
2.1.504
C:\Program Files\dotnet\sdk\2.1.504\
2.1.503
C:\Program Files\dotnet\sdk\2.1.503\
2.1.502
C:\Program Files\dotnet\sdk\2.1.502\
2.1.500
C:\Program Files\dotnet\sdk\2.1.500\
2.1.202
C:\Program Files\dotnet\sdk\2.1.202\
2.1.201
C:\Program Files\dotnet\sdk\2.1.201\

P.S. I have only VS 2019 installed.

@maca88
Copy link
Owner

maca88 commented Dec 15, 2021

Did you run it under .NET Core or NetFx?

My bad, I didn't noticed that I had net472 for the target framework.

I published version 0.18.3 which avoids selecting not supported MSBuild versions.

@bahusoid
Copy link

Thanks!

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

Successfully merging a pull request may close this issue.

3 participants