dotNET COM Initialization Issues - fixing "The specified framework 'Microsoft.AspNetCore.App' is not present in the previously loaded runtime"
See the question and my original answer on StackOverflowIf you run your exe with a tool such as DebugView, you will see this output:
The specified framework 'Microsoft.AspNetCore.App' is not present in the previously loaded runtime.
It's because project ComProject2 implicitely requires the Microsoft.AspNetCore.App
framework because of the dependency on the CoreWCF.WebHttp
package.
For some reason, the .NET core loader cannot load an additional framework automatically in this COM scenario (the exe is not a .NET Core app). But you can configure it, this is described with more details here: Framework-dependent Deployment Model
There are multiple ways of fixing it. One solution is, at deployment time, to copy the content of the generated ComProject2.runtimeconfig.json
file into ComProject1.runtimeconfig.json
, to force the first component to load the Microsoft.AspNetCore.App framework, so it content should be this:
{
"runtimeOptions": {
"tfm": "net6.0",
"rollForward": "LatestMinor",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "6.0.0"
}
]
}
}
Another solution is, as explained here, to create a file named runtimeconfig.template.json
at ComProject1's root with a content like this:
{
"frameworks": [
{
"name": "Microsoft.AspNetCore.App",
"version": "6.0.0"
}
]
}
and it will be merged, at build time (requires a rebuild the first time), into ComProject1.runtimeconfig.json
.