Entity Framework in Child Project Not Working in Parent Project - sql-server

I have a project that contains my Entity Framework generated models and DBContext. I am attempting to reference that project from another project which has the following config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
But anytime I instantiating the context: using (var db = new DataDB()) { ... } I get the error below:
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Additional information: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application.See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
I also installed EF for my project. Not sure what else needs to be configured to get this working?

If anyone is looking, you probably have created your model in a separate project. You need to add references for EntityFramework and EntityFramework.SqlServer

Related

DevExpress DLL's License Exception in visual studio windows application due to CAS Policy

Exception occurred creating type 'DevExpress.XtraEditors.CheckEdit, DevExpress.XtraEditors.v8.2, Version=8.2.8.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1' System.TypeInitializationException: The type initializer for 'DevExpress.Utils.AppearanceObject' threw an exception. ---> System.NotSupportedException: This method explicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility reasons, please use the NetFx40_LegacySecurityPolicy configuration switch. Please see http://go.microsoft.com/fwlink/?LinkID=155570 for more information. ..\Properties\licenses.licx
Tried below configuration in app.config to resolve the issue but did not work:
`
<configuration>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
<startup>
<supportedRuntime version="v3.5.0000"/>
<!--<supportedRuntime version="v1.0.3705"/>-->
</startup>
`
Is there any extra configuration or setup required to resolve this issue?
Tried the steps given in the link below to resolve the issue:
https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/dd409253(v=vs.100)
https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/w4atty68(v=vs.100)

Config transform error setting up Episerver 9 Commerce project

I am following instructions to set up a new Episerver 9 commerce site.
I've followed the instructions at: http://world.episerver.com/documentation/Items/Installation-Instructions/installing-episerver/#Commerce
When I install NuGet package EpiServer.CommerceManager I get the following error:
An error occurred while applying transformation to 'web.config' in
project 'WebCommerceApplication' No element in the source document
matches '/configuration/system.serviceModel/services'
What do I do wrong?
It seems you have a transform for an element that's missing in web.config.
Make sure you have an element like...
<configuration>
<system.serviceModel>
<services />
<system.serviceModel>
<configuration>
...in your web.config.

SSDT Unit Test:. An error occurred while SQL Server unit testing settings were being read from the configuration file

I created a database project in Visual Studio 2013 professional. Then added a unit test by right click on one of the stored procedure and select Create Unit Tests. Selected to create a new VB test project. Then right click on the newly created test project and select SQL Server Test Configuration, choose localdb database and configured the project that need to be deployed.
Rebuild the solution, Run All tests (two tests). Tests always fail with this error:
Message: An error occurred while SQL Server unit testing settings were being read from the configuration file. Click the test project, open the SQL Server Test Configuration dialog box from the SQL menu, add the settings to the dialog box, and rebuild the project.
StackTrace:
at Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestService.OpenProcessConfig()
at Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestService.DeployDatabaseProject()
at *************.Tests.SqlDatabaseSetup.InitializeAssembly(TestContext ctx) in C:\Projects*********************.Tests\SqlDatabaseSetup.vb:line 15
It seems to be that the app.config that is get generated by VS 2013 is empty. I did some research online and lots of try and error and came with the following app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="system.data.localdb" type="System.Data.LocalDBConfigurationSection,System.Data,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
<section name="SqlUnitTesting_VS2013" type="Microsoft.Data.Tools.Schema.Sql.UnitTesting.Configuration.SqlUnitTestingSection, Microsoft.Data.Tools.Schema.Sql.UnitTesting, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<system.data.localdb>
<localdbinstances>
<add name="(localdb)\ProjectsV12" version="12.0" />
</localdbinstances>
</system.data.localdb>
<SqlUnitTesting_VS2013>
<DatabaseDeployment DatabaseProjectFileName="..\..\..\Database_Project_Name\Database_Project_Name.sqlproj"
Configuration="Debug" />
<DataGeneration ClearDatabase="true" />
<ExecutionContext Provider="System.Data.SqlClient" ConnectionString="Data Source=(localdb)\ProjectsV12;Initial Catalog=Database_Name;Integrated Security=True;Pooling=False;Connect Timeout=30"
CommandTimeout="30" />
<PrivilegedContext Provider="System.Data.SqlClient" ConnectionString="Data Source=(localdb)\ProjectsV12;Initial Catalog=Database_Name;Integrated Security=True;Pooling=False;Connect Timeout=30"
CommandTimeout="30" />
</SqlUnitTesting_VS2013>
</configuration>
Now I get the following error:
Failed to deploy database project C:\Projects\Database_Project_Name\Database_Project_Name\Database_Project_Name.sqlproj. But this seems to be because my database depends on other databases and I need to deploy the other database with my database.

How to make the application read keys from app.config file of class library dynamically

My requirement is as follows.
1)I want to use the application settings to read a location path and use it in my project to read the files in that folder.
--- I achieved this by creating a setting with the path and I used to read the path from that settings in the project as follows
Properties.Settings.Default.XMLModelPath
2)Now the actual requirement is I want that app.config of the class library to be available in the bin so that I can update the path if there are any changes required later and every time I run the application, the settings of that project should read this file and update its value.
Is there a way to achieve this or suggest any other possible ways.?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MyClass.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<MyClass.Properties.Settings>
<setting name="XMLModelPath" serializeAs="String">
<value>C:\Resources\</value>
</setting>
</MyClass.Properties.Settings>
</applicationSettings>
</configuration>
This is my app.config file of the class. I want this to be available in bin and the settings of the project to be updated everytime I run my application.

Why does my app require the full .NET 4 Framework?

I have a WinForms app targeting the .NET 4 Client Profile. However, when I try to run it on a machine that has only the Client Profile (and not the full/extended profile), I get ".NET Framework Initialization Error" saying I need to install ".NETFramework,Version=v4.0":
I've double-checked the project file to make sure that it is indeed targeting the client profile, and it is:
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
As are all of the projects it references. I'm not even sure where else to look - what is going on here?
Check your app.configs and verify the supported runtime specified in the startup:
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
should be replaced with
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>

Resources