Andrus Andrus - 4 days ago 4x
ASP.NET (C#) Question

How to not load unused assembly

In ASP.NET MVC4 application System.Data.OracleClient assembly is loaded.

Code in controller

var sb = new StringBuilder();
foreach (Assembly b in AppDomain.CurrentDomain.GetAssemblies())

Outputs it:

System.Data.OracleClient, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089

According to How to avoid loading unnessecary assemblies answer this is caused by presence of Oracle section in machine.config:

<section name="" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

Trying to remove in using remove element in application web.config show error

enter image description here

and after running application
still appears in list of loaded assemblies.
Solution does not contain any direct reference to any Oracle namespace.
How to remove this amnd other unused assemblies from loaded assemblies.

Application is running in VPS with limited memory and hopefully this frees some memory.


After further investigation I found that that this is called and used by System.Data that is critical if you use any kind of data base.

After even more investigation using the ILSpy I also found that the mscorlib (the core library) is also have reference to that Oracle Client... so probably you can not avoid it at all...

So you need to remove this System.Data to avoid the oracle client - but it will not play if you have any kind of data.

Remove it from assemblies as I also have post here

        <add assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add assembly="mscorlib" />
        <add assembly="Microsoft.CSharp, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add assembly="System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.Configuration, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add assembly="System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add assembly="System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.Web.Services, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add assembly="System.Xml, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.Drawing, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add assembly="System.EnterpriseServices, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add assembly="System.IdentityModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.Runtime.Serialization, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.ServiceModel.Activation, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.ServiceModel.Web, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Activities, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.ServiceModel.Activities, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.WorkflowServices, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Data.DataSetExtensions, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.Xml.Linq, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.ComponentModel.DataAnnotations, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.DynamicData, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.ApplicationServices, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="*" />
        <add assembly="System.Web.WebPages.Deployment, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

Now the message that you see on the visual studio if false alert because visual studio can not compile the web.config as IIS... actually the remove works and the site is run.

At the end I like to say you that I am not sure that you can gain much from that oracle client remove because this is only check if there is any database connection in web.config, if not exist actually is not do anything.

Most important is to minimize the pipe line of the request as I have type on my previous answer...