Skip to content

Add-Migration failing with new Microsoft.CodeAnalysis.Workspaces v4.10.0 #33970

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
pocki opened this issue Jun 12, 2024 · 33 comments
Closed

Add-Migration failing with new Microsoft.CodeAnalysis.Workspaces v4.10.0 #33970

pocki opened this issue Jun 12, 2024 · 33 comments

Comments

@pocki
Copy link

pocki commented Jun 12, 2024

Bug Microsoft.CodeAnalysis.* version dependencies

ASP.NET Core Web API with EF Core 8.0
I need to reference Microsoft.CodeAnalysis.* directly with a newer version (instead of v4.5.0) because of other dependencies like Powershell.SDK - see #32070

This was working fine until v4.9.2 of Microsoft.CodeAnalysis.* packages. Except the warning about version mismatch.
After update to v4.10.0 the Add-Migration crashes.

Please make it working also with newer versions of Microsoft.CodeAnalysis. and don't stick to an (very) old version.

Directory.Packages.props:

    <PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.10.0" />
    <PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
    <PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.1" />
    <PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
    <PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6" />

Stack traces

PM> Add-Migration -Context MyContext -OutputDir Models\DbMigrations -Name "Add my field"
Build started...
Build succeeded.
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Method 'get_IsParamsArray' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Composition.Hosting.ContainerConfiguration.<>c.<WithAssemblies>b__16_0(Assembly a)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor(IEnumerable`1 types, AttributedModelProvider attributeContext)
   at System.Composition.Hosting.ContainerConfiguration.CreateContainer()
   at Microsoft.CodeAnalysis.Host.Mef.MefHostServices.Create(IEnumerable`1 assemblies)
   at Microsoft.CodeAnalysis.Host.Mef.MefHostServices.get_DefaultHost()
   at Microsoft.CodeAnalysis.AdhocWorkspace..ctor()
   at Microsoft.EntityFrameworkCore.Design.Internal.CSharpHelper..ctor(ITypeMappingSource typeMappingSource)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   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.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   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.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   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.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   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.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   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.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   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.VisitScopeCache(ServiceCallSite callSite, 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__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
System.TypeLoadException: Method 'get_IsParamsArray' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
Unable to load one or more of the requested types.
Method 'get_IsParamsArray' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationParameterSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.

Provider and version information

EF Core version: 8.0.6
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Windows 11 23H2 (Build 22631.3737)
IDE: Visual Studio 2022 17.10 and Visual Studio 2022 17.11 Preview 2.0

@flipZomb
Copy link

Have a similar issue. Going back to "4.9.2" fixed it for now.

@ajcvickers
Copy link
Contributor

Duplicate of #32926

@ajcvickers ajcvickers marked this as a duplicate of #32926 Jun 15, 2024
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Jun 15, 2024
@pocki
Copy link
Author

pocki commented Jun 15, 2024

Its not a duplicate, as it is a current problem and not in next major release in half a year

@roji
Copy link
Member

roji commented Jun 16, 2024

@pocki the problem has already been fixed for 9.0 - the remaining question is about whether to also backport a fix for 8.0. That discussion is happening as part of #32926.

@pocki
Copy link
Author

pocki commented Jun 16, 2024

@Roj At the mentioned PR there is only an update to v4.8 - this is still not the latest version. And there are breaking changes from 4.9.2 to 4.10

@peter-nguyen-contemi
Copy link

@roji Could you please consider the comment from @pocki . It seems that he mentioned a wrong person in his comment. Right now we cannot add any new EF Core migrations with Microsoft.CodeAnalysis.* packages version 4.10.0 because of this issue.
We had to downgrade them to version 4.9.2 for the EF Core tool to work properly.

@roji roji reopened this Jul 22, 2024
@roji
Copy link
Member

roji commented Jul 22, 2024

Ropening to make sure we do the right thing for 9.0 here.

@iscodand
Copy link

back to previous version solved the problem on my project

@roji roji added this to the 9.0.0 milestone Aug 11, 2024
@ajcvickers ajcvickers removed this from the 9.0.0 milestone Aug 12, 2024
@ajcvickers
Copy link
Contributor

@roji To update.

@roji
Copy link
Member

roji commented Aug 13, 2024

I've consulted about this internally, and we're not going to be changing the Microsoft.CodeAnalysis version in EF 9.0. IIUC upgrading to 4.10.0 would preclude usage of VS 17.8 and 17.9 for no good reason, and the recommendation in general is to not just upgrade unless our analyzers/source generators actually need a feature from the newer versions.

Note that EF 10 will very likely target the net10.0 TFM, at which point older VSs probably won't be supported anyway; there's a good chance we'll upgrade our Microsoft.CodeAnalysis as well. Until then, the workaround above of manually using 4.9.2 (or whatever works) seems very reasonable.

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2024
@pocki
Copy link
Author

pocki commented Aug 14, 2024

@roji Thanks for the update.
That means that now (.NET8) and .NET9 app with EF Core (Code first) can't use actual Microsoft.CodeAnalysis or any dependency that uses an actual version of it.

My case as example: I can't use .NET9 and EF Core together with Microsoft.Powershell.SDK 7.5 (Powershell 7.5 is based on .NET9)
This is a weird situation and should last for at least ~ 1,5 years. (as since june 2024 not the latest version is possible to use)

@roji
Copy link
Member

roji commented Aug 14, 2024

@pocki I understand, and it's indeed an unfortunate situation. The thing is that we're not seeing a lot of people using EF through Microsoft.Powershell.SDK, or running into other similar issues - this issue has only one vote... And upgrading to 4.10.0 brings its own problems as we've seen.

The good news is at least that this problem will at some point go away on its own, and until then there seems to be a decent workaround, with the user explicitly setting the version to 4.9.2 etc. Hopefully that's good enough for the time being.

@MartyIX
Copy link

MartyIX commented Sep 27, 2024

Hm, so to answer my question here #32070 (comment), it seems it's not possible to upgrade even in .NET 9. :-|

@AndrewZenith
Copy link

Same issue. Carter 9.0 requires 4.11, so I ran into this as well.

Had to downgrade carter to 8.21 to get EF migrations created.

@hades200082
Copy link

Another vote here - I'm also using Carter this dependency issue is causing me to not be able to use EF Core in my projects.

I must say, I don't expect this sort of dependency issue to be present in .NET. It's starting to feel like JavaScript/Node.

@roji
Copy link
Member

roji commented Nov 23, 2024

Everyone, it's indeed unfortunate that this issue exists - read above for the explanation/reasons. I can say almost with certainty that we won't be patching EF 9.0 to change the version, but EF 10.0 should be fine (I've opened #35187 to make sure we do the right thing there).

ze-dom referenced this issue in MUnique/OpenMU Nov 27, 2024
@hades200082
Copy link

Why can't the dependency be set so that it will at least accept/work with the newer version if it's installed while retaining backwards compatibility? i.e. set the dependency to "at least 4.9.2"

@nhwilly
Copy link

nhwilly commented Dec 30, 2024

Conflict with TimeWarpState, too. Currently blocking the entire project. I can't figure out how to configure around it. Nothing works.

@roji
Copy link
Member

roji commented Dec 30, 2024

Everyone, please note that as far as we know, using version 4.9.2 works around the problem - please read the issue from the beginning. Although the situation isn't great, we're not currently aware of a case that cannot be worked around with EF 9 - if there is one, we need to see a minimal repro.

@nhwilly
Copy link

nhwilly commented Dec 30, 2024

Everyone, please note that as far as we know, using version 4.9.2 works around the problem - please read the issue from the beginning. Although the situation isn't great, we're not currently aware of a case that cannot be worked around with EF 9 - if there is one, we need to see a minimal repro.

TimeWarpState currently requires 4.11.0.

TWS is used in a library that is nested deep in the project hierarchy.

The package author is reviewing a workaround on his end. In the meantime, I created an API project with no endpoints that references all the schemas in all the modules. It does not reference TWS because it doesn't need all the nested projects to do zero work.

I just now finished migrating all my databases, etc. using this new project. This workaround will be fine for me until EF 10.

Thanks for responding - huge fan of EF Core.

@roji
Copy link
Member

roji commented Dec 30, 2024

Good to hear that you've found a workaround. Everything should be fine for EF 10 in any case.

@Maxteabag
Copy link

After upgrading from .net6 to .net 9 I had to use 4.9.2 no less no more, when doing dotnet-ef migrations add ...
This is bad!

@rogmauri
Copy link

Version 4.12.0 and the problem still persists, forcing us to revert to 4.9.2 for 'dotnet ef migrations'.

Any expectations for a fix?

@roji
Copy link
Member

roji commented Feb 14, 2025

@rogmauri please read all of the above.

@hades200082
Copy link

Everyone, it's indeed unfortunate that this issue exists - read above for the explanation/reasons. I can say almost with certainty that we won't be patching EF 9.0 to change the version, but EF 10.0 should be fine (I've opened #35187 to make sure we do the right thing there).

Looks like #35187 has been closed as well with yet another issue opened at #34637 to supposedly address it in 10.0.0

@eqtr-ab
Copy link

eqtr-ab commented Mar 11, 2025

This issue has constituted a major time-sink for me today. I cannot readily downgrade the CodeAnalysis package because another in the same project relies on 4.10.0. Separating the context into a separate project with its own set of dependencies may technically be a "workaround", but it's not a very expedient one that presents its own problems.

@roji
Copy link
Member

roji commented Mar 11, 2025

Everyone, #35753 has just been merged, bumping Microsoft.CodeAnalysis.Workspaces to the recently released 4.13.0 for EF 10. Going forward, we have also decided to always targeted the latest .NET TFM (so EF 10 will target net10.0, EF 11 will target net11.0), allowing us to also keep the Microsoft.CodeAnalysis up to date and on the latest version (latest compiler/VS would be required in any case).

Re the current situation in 9.0, I don't have much to add beyond what's already written above. Changing the required Microsoft.CodeAnalysis version would break a lot of people.

@eqtr-ab
Copy link

eqtr-ab commented Mar 11, 2025

The status quo also breaks a lot of people, such as myself and previous commenters. Umbraco, a popular CMS package, has a dependency on v4.10.0 of CodeAnalysis specifically - this appears to present a situation where any Umbraco solution which also makes use of this version of EF Core cannot add any migrations. I'm sure there'll be other packages out there which are also dependent on this version.

@roji
Copy link
Member

roji commented Mar 11, 2025

The status quo also breaks a lot of people, such as myself and previous commenters.

It's very different to say that there's an incompatibility using EF with some other, unrelated package (Umbraco), and asking for a breaking change to be done in an EF 9.0; the latter would cause EF users upgrading to a new patch version (regardless of any other packages). There is an extremely high bar for us for introducing a breaking change in a patch version, and this doesn't seem anywhere close to it.

If you prefer, you can stay with EF 8.0 for now, until 10 is released in a few months. Otherwise, you can also file a request with Umbraco to support earlier versions of Microsoft.CodeAnalysis.

@eqtr-ab
Copy link

eqtr-ab commented Mar 11, 2025

EF8 is the version I am using, and the version both myself and OP encountered this issue in. I am not asking for any changes to be made to 9, 8 is the version exhibiting this issue. Can I assume your answer is the same in this circumstance, and this issue will not be resolved for this version either?

@roji
Copy link
Member

roji commented Mar 11, 2025

@eqtr-ab yes, that same logic holds - even more so - for EF 8.0, which is a long-term release. We'd be breaking existing EF 8.0 users by releasing an 8.0 patch version that changes the Microsoft.CodeAnalysis version.

@LennardF1989
Copy link

LennardF1989 commented Apr 7, 2025

If it's worth anything to anyone, I fixed my .NET 8 projects with the following:

    <PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.13.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.13.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.13.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />

Specifically, adding the first two packages was key - in my case, transitive dependencies were mixing 4.5.0 and 4.10.0, which caused the dotnet ef migrations add to fail.

@AndrewZenith
Copy link

AndrewZenith commented Apr 8, 2025

Just upgraded to
PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.13.0"

No more migration building issues.

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

No branches or pull requests