I have a core 3.1 console multi-targeting project where i want to access some EF6 data on .net 4.7.2 from core console through netstandard2.0

iqworks Information Quality Works 296 Reputation points
2022-11-30T18:00:12.56+00:00

Hi,

I dont think I am using the multi-targeting correctly, and, Going from the console through netstandard2.0 is NOT multi-targeting. All I see from videos or forum post just show you how to set up multi-targeting, but then what. If you know of any links or videos that go beyond setting up a multi-targeting project, it would be VERY helpful.

This is my multi-targeting project:
265818-core-console-multi-targeting-0.png

My Mbsa .net 4.7.2 project:
265750-core-console-multi-targeting-1.png

My Mbsa Entity framework in .net 4.7.2 in web.config :
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>

Here, I am calling the .netstandard method to return the EF member table data from .net 4.7.2 for member number 1.
265854-core-console-multi-targeting-3.png

when I run the core console app I get this error in my Mbsa .net 4.7.2.
265803-core-console-multi-targeting-4.png

This is the description
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
at System.Data.Entity.Internal.LazyInternalConnection..ctor(DbContext context, String nameOrConnectionString)
at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
at Mbsa.Models.MbsaDataEntities..ctor() in D:\MBSSys\Mbsa\Mbsa 2021\Models\MbsaDB.Context.cs:line 19
at Mbsa.Common.CommonRepo`1..ctor() in D:\MBSSys\Mbsa\Mbsa 2021\Common\CommonRepo.cs:line 24
at Mbsa.BL.MembersService..ctor() in D:\MBSSys\Mbsa\Mbsa 2021\BL\MembersService.cs:line 38
at MbsaDotNetStandard.MbsaUseFrameworkMethods.grabMbsaMember(Int32 mno) in D:\MBSSys\MbsaDotNetStandard\MbsaUseFrameworkMethods.cs:line 16
at MbsaMultiTargeting.Program.Main(String[] args) in D:\MBSSys\MbsaMultiTargeting\MbsaMultiTargeting\Program.cs:line 31

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
ConfigurationErrorsException: Configuration system failed to initialize

Inner Exception 2:
ConfigurationErrorsException: Unrecognized configuration section add. (D:\MBSSys\MbsaMultiTargeting\MbsaMultiTargeting\bin\Debug\netcoreapp3.1\MbsaMultiTargeting.dll.config line 3)

this is the problem. I have seen several posts about this from various forums but I dont know where to put what. It looks like I need a <section name> in my app.config.
265794-core-console-multi-targeting-6.png
this is my appsettings.json
265857-core-console-multi-targeting-7.png

This is what I SHOULD be focusing on "line 6 ":
266853-core-console-config.png

Perhaps I need a new thread to clear what the focus should be on:
https://learn.microsoft.com/en-us/answers/questions/1114938/console-core-31-gives-this-error.html

thanks for any suggestions and advice

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,664 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 67,916 Reputation points
    2022-11-30T21:36:57.227+00:00

    multi-target builds multiple versions of the application, one for each target. the core 3.1 target can not reference a 4.* library.

    as there is no .netstandard 2.0 version of EF 6, all the library projects that use it must also be multi-target if you want to share between 4.* & core 3.1

    note: EF 6 has a net45 and netstandard 2.1 version, which can be used for multi-targets


  2. iqworks Information Quality Works 296 Reputation points
    2022-12-09T20:05:05.627+00:00

    Hi Bruce & ZhiLv-MSFT
    Bruce was correct, you cannot access .net4.7.2 from core 3.1. But I found the actual reason pertaining to my particular issue.
    Core 3.1 puts its connection string in appsettings.json. net4.7.2 cannot read this appsettings.json, it only reads its web.consig file. One solution is to pass the connection string as a parm or something like a session variable and send it from core 3.1 through .netstandard to .net7.7.2. This was ONE suggestion.

    But, for others that are looking into this issue. Do a google search with "core 3.1 console .nt472 Message=No connection string named could be found in the application config file. Source=EntityFramework". Here you will find MANY links of people explaining this issue and, the many different ways each link showing how to get around this.

    Thank you guys for your help and enlighting information.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.