0

Developed an exe using .Net framework 4.0, EF 6.0. It works fine in machines where .Net framework 4.0, 4.5 full version installed.

But when I invoke the same exe from different machine's shared folder, it throws error. it is because of entityframework tag in the config.

Server Machine has shared folder with .Net 4.5 installed. SharedFolder contains the exe developed using .Net 4.0.

  • If user opens the exe of sharedFolder in servermachine, from clientmachine (4.0 installed) getting below error.

  • It works fine, when client and server machines have 4.5 framework.

  • Works, when opening directly in client (4.0) and server (4.5) machines.

Error

'System.Data.Entity.Internal.AppConfig' Type initializer for threw an exception 

Stack Trace:
   at System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
   at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
   at ShipNet.Accounting.Data.SNACSEntities..ctor(String ConnectionString)
   at ShipNet.Accounting.Data.Repository.BaseRepository..ctor()
   at ShipNet.QnR.Presenter.frmMainPresenter.IView_GetSNAPSSystem()
   at ShipNet.QnR2.UI.frmMain..ctor(String UserName)
   at ShipNet.QnR2.UI.Program.Main(String[] args)

Inner Exception Source:
System.Configuration

.Net Framework : 4.0 Entity Framework : 6.0 database: sql server

my configuration file:

 <?xml version="1.0" encoding="utf-8"?>
<configuration>

  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>

  <connectionStrings>
    <add name="ERP-DB" connectionString="Data Source=testserver;Initial Catalog=db;user Id=**;Password=**" providerName="System.Data.SqlClient" />
  </connectionStrings>

  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>

  <system.data>
    <DbProviderFactories>
      <add name="EF Caching Data Provider" invariant="EFCachingProvider" description="Caching Provider Wrapper" type="EFCachingProvider.EFCachingProviderFactory, EFCachingProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b" />
      <add name="EF Tracing Data Provider" invariant="EFTracingProvider" description="Tracing Provider Wrapper" type="EFTracingProvider.EFTracingProviderFactory, EFTracingProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b" />
      <add name="EF Generic Provider Wrapper" invariant="EFProviderWrapper" description="Generic Provider Wrapper" type="EFProviderWrapperToolkit.EFProviderWrapperFactory, EFProviderWrapperToolkit, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b" />
    </DbProviderFactories>
  </system.data>



</configuration>
anand
  • 307
  • 3
  • 14
  • Is the EF copied to the project folder or loaded from the GAC? Is it possible that a different version is being loaded on the "problem system" than the others? Oh, and what type of app is this? WPF / winforms / web? – David Kirkland Sep 09 '14 at 08:57
  • @DavidKirkland, it is winform application. Yes, EF files available in the project folder. If user executes the exe in the server machine, it is running. If user invokes same exe from another machine (where server folder is shared), getting this error (client machine has .net framework 4.0 installed). – anand Sep 09 '14 at 09:02
  • So are you running the app from a Windows share on the client machine? – David Kirkland Sep 09 '14 at 09:15
  • @DavidKirkland. yes invoking the exe from windows share. It works most the customers and our test environments. only one specific customer's client machine getting this error. But if we execute the same exe in the server machine ( where windows share available), it works. whether machine.config could cause issue? – anand Sep 09 '14 at 09:30
  • As an experiment, I'd try copying the folder onto the client system and executing it locally. If it still doesn't work the at least you've eliminated this as a cause... Also, you could try enabling Fusion logging on the problem system, in case there is some sort of DLL conflict and something is not loading correctly. http://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net – David Kirkland Sep 09 '14 at 09:37
  • Does this client system have the full .NET 4 framework installed? It could be a problem if they only had the client version installed. (Network functionality required by EF.) – David Kirkland Sep 09 '14 at 09:38
  • created simple exe connecting db server using EF. Invoked directly in the client machine. it worked. but exe from windows share didn't. But after installing .net 4.5.1 it worked. – anand Sep 09 '14 at 14:13
  • @DavidKirkland, it works even without installing 4.5.1 after removing entityframework tag. any suggestion??? – anand Sep 11 '14 at 13:22
  • I think it's down to DLL dependencies further down the stack. Fusion logs might give you more insight into this. If removing the tag is an acceptable solution for you then I'd be inclined to make a note of the issue and move on. – David Kirkland Sep 11 '14 at 13:52

2 Answers2

1

It sounds like the Microsoft .NET Framework 4 Client Profile is installed on the problem system. Installing the full framework on the client PC should resolve the issue.

The Microsoft .NET Framework 4 (full) version can be found here:

http://www.microsoft.com/en-us/download/details.aspx?id=17718

David Kirkland
  • 2,431
  • 28
  • 28
1

one more solution,

after removing below tag, it worked.

  <entityFramework>
    <!--<defaultConnectionFactory type="System.Data.Entity.CrossCutting.SqlConnectionFactory, EntityFramework"/>--> 

    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>

guys, is this tag mandatory???

From my machine (.Net 4.0 installed), if I execute exe from different machine's (.Net 4.5.1 installed) shared folder, it throws error when exe's config has above tag. works if I remove the above tag.

If we execute the same exe in local machine (.Net 4.0), it works with or without above tag.

anand
  • 307
  • 3
  • 14