Jump to content


Photo

Simple ASP.Net learning exercise fails: weird reference to Oracle

ASP.Net Oracle

  • Please log in to reply
3 replies to this topic

#1 fmorriso

fmorriso

    Newbie

  • Members
  • Pip
  • 2 posts
  • Gender:Male
  • Location:USA

Posted 26 August 2013 - 06:07 AM

To help me evaluate NCache 4.1 SP1, I have created a simple ASP.Net example application (.Net 3.5 Framework) on my 64-bit Windows 7 Ultimate laptop, that is full patched through July 2013 "Patch Tuesday".

 

My simple application runs into the following error before it even "get's out of the box":

 
Could not load file or assembly 'Oracle.DataAccess, Version=2.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
 
 Exception Details: System.BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess, Version=2.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format.
 
Source Error: 
 
 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
 
My web.config:
 
  <appSettings >
    <add key="NCacheName" value="DefaultCache"/>
    <add key="NCacheId" value="DefaultCacheId"/>
  </appSettings>
 
Global.asax.cs:
using System;
using System.Configuration;
using System.Diagnostics;
//
using Alachisoft.NCache.Web.Caching;
using Alachisoft.NCache.Web.Management;
 
        protected void Application_Start(object sender, EventArgs e)
        {
            Debug.WriteLine("Application_Start");
            string cacheName = ConfigurationManager.AppSettings["NCacheName"];
            Cache _cache = NCache.InitializeCache(cacheName);
 
            string _computerName = Environment.GetEnvironmentVariable("COMPUTERNAME");
            string _cachedId = ConfigurationManager.AppSettings["NCacheId"];
            CacheManager.StartCache(_cachedId, _computerName);
        }
 
I've run the NCache Manager tool, but nothing I define seems to persist because every time I run that tool, it proclaims total ignorance of my previous efforts to define a "Local Cache", so I must be doing something fundamentally wrong.
 
Eventually, I want to try something simple such as this code-behind for a ASP:Button click event:
 
       protected void putInCache_OnClick(object sender, EventArgs e)
        {
            var customer = new Customer
            {
                Name = "Fred",
                Id = 1001
            };
            
            string CacheName = ConfigurationManager.AppSettings["NCacheName"];
            
            CacheItemVersion result = NCache.Caches[CacheName].Add("<Customer>" + customer,
                DateTime.UtcNow,
                null,
                Cache.NoAbsoluteExpiration,
                Cache.NoSlidingExpiration,
                CacheItemPriority.NotRemovable
                );
        }
 
Where Customer is defined as:
    [Serializable]
    public class Customer
    {
        public string Name { get; set; }
        public int Id { get; set; }
    }
 
My ultimate goal is to replace multiple ways of caching in an ASP.Net application that is using the .Net 3.5 Framework (and cannot and will not be upgraded to .Net Framework 4/4.5 so please don't suggest that as a solution because it won't happen - at least not in my lifetime).
 
I have uninstalled and reinstalled (while logged in as Administrator) twice and this error continues to happen.
 
What can I do to get passed this weird Oracle error?

 



#2 zack

zack

    Advanced Member

  • Admin
  • Pip
  • 3 posts
  • Gender:Male
  • Location:California

Posted 26 August 2013 - 07:38 AM

NCache web dll internally refers to this particular assembly (Oracle.DataAccess), that’s why your application is asking for it. This assembly comes installed with NCache. You can add reference for this assembly in your application from windows GAC folder and can also set the Copy local flag to false, this will avoid the assembly to be copied in your application bin and the issue will be resolved.

 

If you are using .Net 4.0 Dlls of NCache then you add a reference of Oracle.DataAccess from the location (C:\Windows\Microsoft.NET\assembly\GAC_64).

 

If you are using .Net 2.0 Dlls of NCache the please add the of Oracle.DataAccess from the location (C:\Windows\assembly)

 

If you are still unable to resolve the problem then please use the dll available on the following link:

 

http://www.alachisoft.com/downloads/support/Oracle.DataAccess_20_x86.zip 

 

I hope this helps. Please let me know if you have further questions in this regard.



#3 fmorriso

fmorriso

    Newbie

  • Members
  • Pip
  • 2 posts
  • Gender:Male
  • Location:USA

Posted 26 August 2013 - 11:21 AM

NCache web dll internally refers to this particular assembly (Oracle.DataAccess), that’s why your application is asking for it. This assembly comes installed with NCache. You can add reference for this assembly in your application from windows GAC folder and can also set the Copy local flag to false, this will avoid the assembly to be copied in your application bin and the issue will be resolved.

 

If you are using .Net 4.0 Dlls of NCache then you add a reference of Oracle.DataAccess from the location (C:\Windows\Microsoft.NET\assembly\GAC_64).

 

If you are using .Net 2.0 Dlls of NCache the please add the of Oracle.DataAccess from the location (C:\Windows\assembly)

 

If you are still unable to resolve the problem then please use the dll available on the following link:

 

http://www.alachisoft.com/downloads/support/Oracle.DataAccess_20_x86.zip 

 

I hope this helps. Please let me know if you have further questions in this regard.

I can see Orace.DataAccess in %windir%\assembly, but cannot add it as a reference.

I took the ZIP file you referenced earlier, unzipped it and copied the DLL to C:\Program Files\NCache\bin\assembly\2.0\Oracle.DataAccess.dll (after renaming the one that was there) and now my small application works.  I did reduce the amount of work being done to start the cache to a small CacheUtility.cs module:    public static class CacheUtility

    {
        #region Fields
        
        private static readonly string _cacheName = ConfigurationManager.AppSettings["NCacheName"];
        private static readonly Cache _cache = NCache.InitializeCache(_cacheName);
 
        #endregion
with a couple of generic methods:
        public static bool CacheObject<T>(string key, T objectToCache, int cacheDurationInMinutes)
        {
            bool retVal = false;
 
            if (_cache != null)
            {
                DateTime dtExpiration = DateTime.Now.AddMinutes(cacheDurationInMinutes);
                CacheItemVersion ver = _cache.Insert(key, objectToCache, null, dtExpiration, TimeSpan.Zero,
                    CacheItemPriority.Default);
                
                
                retVal = true;
            }
 
            return retVal;
        }
        public static T TryGetObjectFromCache<T>(string key)
        {
            T retVal = default(T);
 
            if ((_cache != null) && (_cache.Contains(key)))
            {
                try
                {
                    //retVal = (T)HttpContext.Current.Cache[key];
                    retVal = (T) _cache.Get(key);
                }
                catch (Exception ex)
                {
                    // logger call or similar goes here
                }
            }
 
            return retVal;
        }
 
I do think the whole "needs Oracle DLL to work" issue is a potential roadblock to us adopting NCache for use in the project I'm working on, but I'll do my best to explain it away should the need to do so come to pass.


#4 Ron

Ron

    Professional

  • Admin
  • PipPip
  • 21 posts
  • Gender:Male
  • Location:San Ramon

Posted 27 August 2013 - 05:52 AM

Thanks for sharing your feedback with us, I really appreciate it.

 

Actually Alachisoft.NCache.Web.dll internally refers this Oracle Dll and it is required for Oracle dependency feature within NCache. I would share your feedback with engineering on this regard.

 

Please feel free to contact us over support@alachisoft.com if there are more questions.

 

Regards,

 

Ron Hussain






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users