Skip to content
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

Could not load type 'System.Linq.ParallelEnumerable' #804

Closed
ryanthedev opened this issue Oct 30, 2019 · 1 comment
Closed

Could not load type 'System.Linq.ParallelEnumerable' #804

ryanthedev opened this issue Oct 30, 2019 · 1 comment

Comments

@ryanthedev
Copy link

When published trimmed.

code

public static Task ParallelForEachAsync<T>(this IEnumerable<T> source, Func<T, Task> funcBody, int maxDoP = 4)
{
	async Task AwaitPartition(IEnumerator<T> partition)
	{
		using (partition)
		{
			while (partition.MoveNext())
			{ await funcBody(partition.Current); }
		}
	}

	return Task.WhenAll(
		Partitioner
			.Create(source)
			.GetPartitions(maxDoP)
			.AsParallel()
			.Select(p => AwaitPartition(p)));
}

Exception

Application startup exception: System.AggregateException: One or more errors occurred. (Could not load type 'System.Linq.ParallelEnumerable' from assembly 'System.Console, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.)
 ---> System.TypeLoadException: Could not load type 'System.Linq.ParallelEnumerable' from assembly 'System.Console, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at AA.Hydra.Zombies.CrossCutting.HelperExtensions.ParallelForEachAsync[T](IEnumerable`1 source, Func`2 funcBody, Int32 maxDoP)
   at AA.Hydra.Zombies.CrossCutting.HelperExtensions.ParallelForEachAsync[T](T[] source, Func`2 funcBody, Int32 maxDoP)
   at AA.Hydra.Zombies.Infrastructure.Repos.FileSystemRepo.GetAllAsync[T](CancellationToken cancellation)
   at AA.Hydra.Zombies.Application.ZombiesApi.InitCachedZombies()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at AA.Hydra.Zombies.Application.ZombiesApi..ctor(IZombieProcessAdapterFactory zombieProcessAdapterFactory, IKeyValueRepo kvRepo, IArtifactAdapter artifactAdapter, IServiceMeshAdapter meshAdapter)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at AA.Hydra.Zombies.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.WebHost.BuildApplication()
@vitek-karas
Copy link
Member

Could you please try again with .NET 6+. All previous releases were only a preview of the trimming feature. In .NET 6+, publishing a trimmed app should either produce a warning, or the app should work.

Note that ASP.NET apps currently don't support trimming because the core ASP.NET libraries are not marked for trimming yet. The work is in progress (although slow): https://github.com/dotnet/aspnetcore/issues?q=is%3Aopen+is%3Aissue+label%3Alinker-friendliness

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

No branches or pull requests

2 participants