Closed kennethskantz closed 1 month ago
Hello @kennethskantz,
I had a similar issue previously with a breaking change in EntityFrameworkCore between .NET 6 and .NET 8 which was handled and resolved here : #179
I'm referencing 6.0.6 of Microsoft.EntityframeworkCore.SqlServer assuming most people are using .NET 6 until Optimizely confirms full support for .NET 8 (Which I believe is not promised until CMS 13). I have noted that Microsoft.EntityframeworkCore.SqlServer 7.20.0 is .NET 6.0 compatible. So I'll look at updating that dependency and see what happens.
I manage this package in my free time, so if you can give me a couple of days to look into this, that would be great.
Hello @kennethskantz
I've managed to reproduce the issue you raised and it's due to a breaking change in Microsoft.EntityframeworkCore.SqlServer v7.x.x
I have created a hotfix package that updates the dependencies as follows:
I've installed this into my test solutions for .NET 6.0 and .NET 8.0 and executed them both with existing databases and fresh databases and they appear to work.
I've published this to nuget.org as a 2.7.1-beta release because obviously I can't test in your specific scenario. But if you can install this and let me know how that works for you, that would be great.
Hi and thanks for your quick response @GeekInTheNorth! Unfortunately we're currently on EPiServer.CMS.UI.Core 12.27.0 och not ready to update to the required 12.31.0, since that requires updating both EPiServer.CMS.Core and EPiServer.Framework, which would require regression testing of the site.
We'll have to postpone using this package until we are ready to update the core CMS packages.
Hi @kennethskantz,
I can roll back the dependency for EPiServer.CMS.UI.Core to 12.27.0 if that helps. I've not merged the hotfix branch in and that's also why I've made it a -beta release.
Yes please do, if possible, that would be very helpful.
@kennethskantz I have uploaded a 2.7.2-beta release onto nuget.org now. The only difference between this and 2.7.0 is the following dependency ranges:
EPiServer.CMS.UI.Core : >= 12.27.0 & < 13.0.0 Microsoft.EntityFrameworkCore.SqlServer (.NET 6.0) : >= 7.0.0 & < 8.0.0 Microsoft.EntityFrameworkCore.SqlServer (.NET 8.0) : >= 8.0.1 & < 9.0.0
I don't want to bother you too much, but I must be doing something wrong. The nuget-installation went fine, but I get an error on startup.
In csproj:
<PackageReference Include="Stott.Security.Optimizely" Version="2.7.2-beta" />
On startup (restarted PC, cleaned bin- and obj-folders):
ArgumentException: Unable to find a module by assembly 'Stott.Security.Optimizely, Version=2.7.2.0, Culture=neutral, PublicKeyToken=null' (Parameter 'moduleAssembly')
EPiServer.Shell.Paths.ToResource(Assembly moduleAssembly, string moduleRelativeResourcePath)
ArgumentException: Unable to find a module by assembly 'Stott.Security.Optimizely, Version=2.7.2.0, Culture=neutral, PublicKeyToken=null' (Parameter 'moduleAssembly')
EPiServer.Shell.Paths.ToResource(Assembly moduleAssembly, string moduleRelativeResourcePath)
EPiServer.Shell.ViewComposition.IFrameComponentAttribute.CreateComponentDefinition(Type attributedType)
EPiServer.Shell.ViewComposition.AttributedComponentProvider+<>c.<GetComponentDefinitions>b__5_1(<>f__AnonymousType15<Type, ComponentAttribute> cat)
System.Linq.Enumerable+SelectEnumerableIterator<TSource, TResult>.ToList()
System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)
EPiServer.Shell.ViewComposition.AttributedComponentProvider.GetComponentDefinitions()
EPiServer.Shell.ViewComposition.ComponentManager.ListAll()
The dll in my bin-folder:
@kennethskantz
Can you check that the nuget package has installed this file in your web project:
\modules\_protected\Stott.Security.Optimizely\module.config
It should look like this:
<?xml version="1.0" encoding="utf-8" ?>
<module loadFromBin="true" clientResourceRelativePath="" viewEngine="Razor" authorizationPolicy="Stott:SecurityOptimizely:Policy" moduleJsonSerializerType="None" prefferedUiJsonSerializerType="Net">
<assemblies>
<add assembly="Stott.Security.Optimizely" />
</assemblies>
<clientModule>
<moduleDependencies>
<add dependency="CMS" />
</moduleDependencies>
</clientModule>
</module>
I'm also wondering if the -beta is interfering, but I didn't observe such an issue when testing both my .NET 6 and 8 solutions.
I'm a bit embarassed, the error was caused because this line was missing:
services.AddStottSecurity()
Thanks for your help, it seems to be working perfectly now.
@kennethskantz I'm glad the issue was resolved for you and that it is working. I think I will merge this into a new major release, just because there is a breaking change with the dependencies. Thank you for reaching out so we can solve this issue together.
Just upgraded to 2.7.0, and getting this exception:
System.ArgumentException: Unable to find a module by assembly 'Stott.Security.Optimizely, Version=2.7.0.0, Culture=neutral, PublicKeyToken=null' (Parameter 'moduleAssembly')
at EPiServer.Shell.Paths.ToResource(Assembly moduleAssembly, String moduleRelativeResourcePath)
at EPiServer.Shell.ViewComposition.IFrameComponentAttribute.CreateComponentDefinition(Type attributedType)
at EPiServer.Shell.ViewComposition.AttributedComponentProvider.<>c.<GetComponentDefinitions>b__5_1(<>f__AnonymousType15`2 cat)
at System.Linq.Enumerable.SelectEnumerableIterator`2.ToList()
at EPiServer.Shell.ViewComposition.AttributedComponentProvider.GetComponentDefinitions()
at EPiServer.Shell.ViewComposition.ComponentManager.ListAll()
at EPiServer.Shell.ViewComposition.DefaultViewManager..ctor(IEnumerable`1 viewProviders, IEnumerable`1 viewTransformers, IComponentManager componentManager)
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.InvokeWithFewArgs(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.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
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 EPiServer.Shell.Modules.ModuleInitializer.RegisterServerRoutes(ShellModule shellModule, IEndpointRouteBuilder routeBuilder)
at EPiServer.Shell.Modules.ModuleInitializer.RegisterModules(IEnumerable`1 modules, IEndpointRouteBuilder routeBuilder)
at EPiServer.Shell.Routing.ShellEndpointRoutingExtension.InitializeModules(IEndpointRouteBuilder routeBuilder, IEnumerable`1 modules)
at EPiServer.Shell.Routing.ShellEndpointRoutingExtension.MapEndpoints(IEndpointRouteBuilder endpointRouteBuilder)
at EPiServer.Web.Routing.EndpointRouteBuilderExtensions.MapEPiServerExtensionEndpoints(IEndpointRouteBuilder defaultEndpointRouteBuilder)
at EPiServer.Web.Routing.ContentEndpointRouteBuilderExtensions.MapContent(IEndpointRouteBuilder defaultEndpointRouteBuilder)
at AlloyTours.Startup.<>c.<Configure>b__8_0(IEndpointRouteBuilder endpoints) in D:\Dev\AlloyTours\AlloyTours\Startup.cs:line 339
at Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints(IApplicationBuilder builder, Action`1 configure)
at AlloyTours.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in D:\Dev\AlloyTours\AlloyTours\Startup.cs:line 337
I do have services.AddStottSecurity();
in my startup, but I do not have a \modules\_protected\Stott.Security.Optimizely\
directory.
Not sure this will do the trick:
<contentFiles>
<files include="module.config" buildAction="None" />
</contentFiles>
@evest the file is only added to the protected modules folder on build and should be included already within the NuGet package within the specified folder.
What happens if you do a full clean and rebuild of your solution?
Can you tell me more about your solution? Are you using Visual Studio 2022 or another IDE? Is this happening in a CI/CD pipeline and could you tell me more?
Sorry for the late reply; I'm using Rider, and I tried cleaning and rebuilding.
Didn't work. I copied the file manually, and that helped. I see the targets file in the package, but maybe Rider is more strict?
Since the files under modules are committed, it works in the DevOps pipeline.
I see other packages are constructed a bit differently, in the build directory, they have one or more framework folders with the targets file in, and under ContentFiles, there are any/any/
folders. Not sure how that makes a difference though, since the script points to the folders anyway.
Hello @evest
I've been using Visual Studio and Visual Studio Code for developing this AddOn as I can use those for free. I'll have to install JetBrains Rider and see if I can reproduce and hopefully solve the issue.
I can tell you that the NuGet package is working in GitHub Actions, Visual Studio and ADO as expected with the modules folder added to the .gitignore
, so this is potentially a rider specific issue as you say.
Hello @evest
I've downloaded a trial version of Rider and I can reproduce the issue with the module.config not being installed properly using 2.7.0.
Now I built a 2.7.2-beta release for @kennethskantz and when I use that version and build the project, the module.config file is copied correctly. Now the only difference here was the version range change I made to the package:
Previous
<ItemGroup>
<PackageReference Include="EPiServer.CMS.UI.Core" Version="12.23.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
</ItemGroup>
New
<ItemGroup>
<PackageReference Include="EPiServer.CMS.UI.Core" Version="[12.27.0,13.0.0)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="[7.0.0,8.0.0)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="[8.0.1,9.0.0)" />
</ItemGroup>
I'm not sure why that would make a difference to rider handling the package differently and correctly installing the file on build.
Hello @evest & @kennethskantz
I have now released a version 2.8 which contains the fixes listed here. You can read more here : #244
Hi, I'm using .NET Core 7.0.15 and Microsoft.EntityframeworkCore.SqlServer 7.0.15 and I'm getting this error when starting my ASP.NET Core application. Do I need to upgrade to .NET 8.0?