I have 2 projects A and B
each project has its own database and connect to it using entity framework and each project is working well alone
My problem is that when I use the project B as a library inside the project A It gives me "The type initializer for (MYCLASS) threw an exception"
you should know that (MYCLASS): is an Entity inside the project B
-
Is the connection string of B's context in the app.config of A?– Gert ArnoldJul 2, 2012 at 6:27
3 Answers
Check if both projects are referring to the same version of entityframework in app.config
.
You might have upgraded your ef dlls in your project B but not in your project A. Since you have made reference of B in A, entityframework is using the config in A for both projects.
Install same version of EF to all project first and then check the following in the App.config file,
- connectionStrings element is after the configSections element.
- startup element is after the connectionStrings element.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<connectionStrings>
<add name="SchedulingContext" connectionString="Data Source=XXX\SQL2008R2DEV;Initial Catalog=YYY;Persist Security Info=True;User ID=sa;Password=XXX" providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
just remove all lines from ConfigSection
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />