1

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())
        sb.AppendLine(b.FullName);

Outputs it:

 System.Data.OracleClient, Version=4.0.0.0, 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="system.data.oracleclient" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=4.0.0.0, 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 System.Data.OracleClient 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.

Community
  • 1
  • 1
Andrus
  • 26,339
  • 60
  • 204
  • 378
  • Have you used ctrl-F to search the solution for "using System.Data.OracleClient;" OracleClient is part of System.Data, so if you are referencing that, the OracleClient namespace would be available. – Dave Smash Oct 17 '16 at 19:54
  • Searcing solution for word `oracle` didnt found references. `using System.Data` command is present but it should not cause Oracle assembly loading – Andrus Oct 17 '16 at 19:56
  • @Andrus One question, beside that message there, the site is run or not ? – Aristos Oct 17 '16 at 19:59
  • Application is running OK by pressing F5 in Visual Studio and also under Mono in VPS production server. web.config error is ignored on run – Andrus Oct 17 '16 at 20:02
  • @Andrus In my case the site is run, this message there is because of I don't know - but the site is run, this remove is working (try to remove something else and you that works)... so probably some other dll loads that part of oracle. – Aristos Oct 17 '16 at 20:02
  • @Aristos It one test Oracle dll vas not loaded, I changed element to `` . However now this and `` both still cause Oracle dll loading. How to find which dlls load it ? – Andrus Oct 17 '16 at 20:05
  • @Andrus I use your code for assemblies and in my case I see that this OracleClient is loaded by `SystemDesign` - so even if you remove it from there the SystemDesign load it. So you also need to remove SystemDesign from assemblies section. – Aristos Oct 17 '16 at 20:05
  • Used projects in solution, machine.config and web.configs does not have references to `System.Design`. How to remove it ? – Andrus Oct 17 '16 at 20:10
  • I see where you pulled your from, but it's obviously not in the right place (not a valid child element of configuration - configsections.) It seems like that should be in the tag belongs here instead... – Dave Smash Oct 17 '16 at 20:11
  • I changed it to ` ` but oracle assembly is still loaded – Andrus Oct 17 '16 at 20:16
  • Are you running low on address space or physical memory? If physical memory, by what mechanism do you believe an unused assembly is consuming physical memory? And are there other processes that make use of that assembly? If so, then what possible cost is there associated with sharing those pages? It sounds like you are running down a "solution" that has nothing to do with your problem. – Eric Lippert Oct 17 '16 at 20:21
  • VPS server has swap memory disabled by ISP for perfomance reasons. Everything must be in physical memory. There are lot of same application instances in this server, every virtual path has separate application. – Andrus Oct 17 '16 at 20:26

1 Answers1

2

After further investigation I found that that this system.data.oracleclient 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 https://stackoverflow.com/a/40085122/159270

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

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...

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • Application uses Npgsql data provider, dBLinq, WebMatrix, custom datareader, RDLEngine. So `System.Data` cannot removed. So it looks like loading Oracle cannot avoided? – Andrus Oct 17 '16 at 20:21
  • @Andrus yes probably you can not avoid it... now I scan again and found that the `mscorlib` also call its - that is very basic module ! – Aristos Oct 17 '16 at 20:28
  • @Andrus Limit the pipe line - this is called on every request. This oracle is called - if called - only on start. The pipe line at `` on my previews answer. This is what I do. – Aristos Oct 17 '16 at 20:31
  • `GetReferencedAssemblies()` does not return any referenced assemby for `mscorlib` . How to determine that `mscorlib` calls it ? Maybe switching to ASP.NET Core can help. – Andrus Oct 17 '16 at 20:31
  • @Andrus I use the ILSpy and find it - and if you see this mscorlib is loaded first on the assemblies. – Aristos Oct 17 '16 at 20:32