Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add assembly in web.config file of mvc 4

I have a "MVC 4" project and i want to add an assembly to web.config file but i don't know where should i put it. I try any ways but i cant find the solution.

every time i got this error:

You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

this is my web.config file:

    <?xml version="1.0" encoding="utf-8"?> <!--   For more information on how to configure your ASP.NET application, please visit   http://go.microsoft.com/fwlink/?LinkId=152368   --> <configuration>   <connectionStrings>     <add name="ParsGraphicEntities" connectionString="metadata=res://*/Entities.ParsGraphic.csdl|res://*/Entities.ParsGraphic.ssdl|res://*/Entities.ParsGraphic.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=ParsGraphic;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />     <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-UI.MVC.InternetApplication-2012317193118;Integrated Security=True" providerName="System.Data.SqlClient" />   </connectionStrings>   <appSettings>     <add key="webpages:Version" value="2.0.0.0" />     <add key="webpages:Enabled" value="true" />     <add key="PreserveLoginUrl" value="true" />     <add key="ClientValidationEnabled" value="true" />     <add key="UnobtrusiveJavaScriptEnabled" value="true" />   </appSettings>   <system.web>     <compilation debug="true" targetFramework="4.0" />     <authentication mode="Forms">       <forms loginUrl="~/Account/Login" timeout="2880" />     </authentication>     <pages>       <namespaces>         <add namespace="System.Web.Helpers" />         <add namespace="System.Web.Mvc" />         <add namespace="System.Web.Mvc.Ajax" />         <add namespace="System.Web.Mvc.Html" />         <add namespace="System.Web.Routing" />         <add namespace="System.Web.WebPages" />       </namespaces>     </pages>     <profile defaultProvider="DefaultProfileProvider">       <providers>         <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />       </providers>     </profile>     <membership defaultProvider="DefaultMembershipProvider">       <providers>         <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />       </providers>     </membership>     <roleManager defaultProvider="DefaultRoleProvider">       <providers>         <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />       </providers>     </roleManager>     <sessionState mode="InProc" customProvider="DefaultSessionProvider">       <providers>         <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />       </providers>     </sessionState>   </system.web>   <system.webServer>     <validation validateIntegratedModeConfiguration="false" />     <modules runAllManagedModulesForAllRequests="true" />   </system.webServer>   <runtime>     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">       <dependentAssembly>         <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />         <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />       </dependentAssembly>       <dependentAssembly>         <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />         <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />       </dependentAssembly>       <dependentAssembly>         <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />         <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />       </dependentAssembly>     </assemblyBinding>   </runtime> </configuration> 

please help me.

thanks.

like image 859
Mohammad Zare Avatar asked Feb 26 '12 19:02

Mohammad Zare


People also ask

Why we use Web config file in asp net?

A configuration file (web. config) is used to manage various settings that define a website. The settings are stored in XML files that are separate from your application code. In this way you can configure settings independently from your code.

Where is Web config file in asp net?

You must create a text file that is named Web. config in the root directory of your ASP.NET application. The Web. config file must be a well-formed XML document and must have a format similar to the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\Machine.

Where is Web config file in Visual Studio?

Your application inherits all configuration settings from the Machine. config and Web. config files in the %SystemRoot%\Microsoft.NET\Framework\<version>\CONFIG directory, but you will not see those default settings here. Application-level or directory-level Web.

Where is Web config file in IIS?

config files. The configuration files for IIS 7 and later are located in your %WinDir%\System32\Inetsrv\Config folder, and the primary configuration files are: ApplicationHost. config - This configuration file stores the settings for all your Web sites and applications.


1 Answers

It is quite simple. Look at your compilation section in your web.config:

<compilation debug="true" targetFramework="4.0"/> 

Now open the section and put your assembly inside like this:

<compilation debug="true" targetFramework="4.0">   <assemblies>     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />   </assemblies> </compilation> 

Libraries in this section are checked in compilation time, it has nothing to do with runtime binding.

like image 116
Alfonso Muñoz Avatar answered Sep 21 '22 14:09

Alfonso Muñoz