Steeltoe
Steeltoe copied to clipboard
EFCore Service Connector not usable when published single file
Summary
I am producing a dotnet core web application using the EFCore service connector to manage db connection string however when i publish it with PublishSingleFile=true, the application fails to launch.
It is a part of our organisation architecture directives that all dotnet core apps must be published as a single file and as such i don't want to move away from that. At the same time i don't want to stop using steeltoe as i am wanting to rollout more steeltoe functionality as time allows.
Stack Trace
File path path information for the assembly containing ServiceInfoCreatorAssemblyAttribute is missing. Some Steeltoe functionality may not work with PublishSingleFile=true Unhandled exception. System.IO.FileNotFoundException: Could not find core assembly. Either specify a valid core assembly name in the MetadataLoadContext constructor or provide a MetadataAssemblyResolver that can load the core assembly. at System.Reflection.TypeLoading.CoreTypes..ctor(MetadataLoadContext loader, String coreAssemblyName) at System.Reflection.MetadataLoadContext..ctor(MetadataAssemblyResolver resolver, String coreAssemblyName) at Steeltoe.Common.Reflection.ReflectionHelpers.TryLoadAssembliesWithAttributeT at Steeltoe.Common.Reflection.ReflectionHelpers.FindAssembliesWithAttributeT at Steeltoe.Common.Reflection.ReflectionHelpers.FindTypeFromAssemblyAttributeT at Steeltoe.Connector.ServiceInfoCreatorFactory.GetServiceInfoCreator(IConfiguration configuration) at Steeltoe.Connector.IConfigurationExtensions.GetServiceInfos[TServiceInfo](IConfiguration configuration) at Steeltoe.Connector.IConfigurationExtensions.GetSingletonServiceInfo[TServiceInfo](IConfiguration config) at Steeltoe.Connector.SqlServer.EFCore.SqlServerDbContextOptionsExtensions.GetConnection(IConfiguration config, String serviceName) at Steeltoe.Connector.SqlServer.EFCore.SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder optionsBuilder, IConfiguration config, Object sqlServerOptionsAction) at Skidata.Dashboard.Manager.Program.<>c__DisplayClass1_1.<CreateHostBuilder>b__4(DbContextOptionsBuilder options) in C:\Users\thja\Documents\Repos\Dashboard.Server\Dashboard.Logic-Web\Dashboard-Web\Program.cs:line 42 at Skidata.Dashboard.Service.DashConfigurationProvider.Load() in C:\Users\thja\Documents\Repos\Dashboard.Server\Dashboard.Logic-Web\Dashboard-Web_Lib\Service\DashConfigurationProvider.cs:line 92 at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList
1 providers) at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build() at Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration() at Microsoft.Extensions.Hosting.HostBuilder.Build() at Skidata.Dashboard.Manager.Program.Main(String[] args) in C:\Users\thja\Documents\Repos\Dashboard.Server\Dashboard.Logic-Web\Dashboard-Web\Program.cs:line 31
Note I will be more than happy to contribute a fix for this which would be to stop TryLoadAssembliesWithAttribute from running in a merged application and am testing it in a local fork so my product can proceed to QA.
Please let us know how that goes, we'd love a PR if you're able to get it working. I'm not sure it will work without reflection... Something like what we did for the CloudFoundry connector might be needed, but we definitely want to see this scenario work. If you can't get it working but can provide a basic repro it would be helpful, thanks!
So my testing looks good. I effectively exit out of TryLoadAssembliesWithAttributes if I see it is a merged dll. This avoids the exception & the client can resolve connection string.
@TimHess & @bart-vmware I have just gone and upgraded to the latest version on nuget and issue is still occuring. Do you want a new issue or can you re-open this one? How can I go about providing a PR as i really don't want to have to maintain my own fork
Hi @thompson-tomo, I closed this issue as part of the Connectors work I did on Steeltoe v4, which hasn't yet been released. A PR to fix this in v3 would still be welcome.
Thanks @bart-vmware do you have a timeline for when atleast a preview of v4 would be released so I can check it etc?
Hi @thompson-tomo,
We'll be solidifying v4 release contents and timelines over the next couple of weeks. We've not pushed to nuget.org yet because we have been anticipating major API surface area changes across several more components and didn't want to give any false impression that we were close to done with significant changes there. We've also had some personnel changes (and a whole lot of abnormal distractions lately) due to the Broadcom acquisition of VMware, so we are likely to need to figure out how to further cut the scope of 4.0.0 so that we can ship sooner rather than later.
If you would like to try the latest builds of v4, they are available in the Steeltoe Dev feed, which can be used with a nuget.config something like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="SteeltoeDev" value="https://pkgs.dev.azure.com/dotnet/Steeltoe/_packaging/dev/nuget/v3/index.json" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
Steeltoe samples that have been updated to use the latest packages can be found in the "latest" branch of the samples repo. We would love any feedback if you are able to try it out
Thanks @TimHess will give it a go in the coming days & provide feedback.
Hi @TimHess over the Christmas break, I looked into this and the preview package didn't help & I was still having issues. So I have submitted a PR for v3 which addresses the issue and habe included an example app which can be used to test it. Let me know if you would like any additional information from me.