type initializer for 'XXX.CustomerDataContext' threw an exce

type initializer for 'XXX.CustomerDataContext' threw an exce

Postby sandeepchinni » Fri 04 Feb 2011 20:23

I am very intermittently getting the error "The type initializer for 'XXX.CustomerDataContext' threw an exception."

When I look at the logs in the event viewer I find the below two logs:

2011-02-04 10:53:53.510 /LM/W3SVC/1/ROOT/XXX/2.13-1-129413156227617160 9160:2 XXX.Adapter
AddCustomer
EXCEPTION (LEVEL 1): System.TypeInitializationException
EXCEPTION OUTPUT: The type initializer for 'XXX.CustomerDataContext' threw an exception.

STACK TRACE:
at XXX.CustomerRepository.get_Context() in d:\DS\Builds\XXX\CustomerRepository.cs:line 41
at XXX.CustomerRepository.get_CurrentDate() in d:\DS\Builds\XXX\CustomerRepository.cs:line 55
at XXX.AddCustomer(Customer customer) in d:\DS\Builds\XXX\CustomerRepository.cs:line 88
at XXX.AddCustomer(AddCustomerRequest request) in d:\DS\Builds\XXX\CustomerManagementAdapter.cs:line 105
at ICustomerManagementAdapterProxy86dbb599e20340d4879bc6a16ef74bde.InvocationAddCustomer_1.InvokeMethodOnTarget()
at XXX.AdapterActivityDetailLoggingInterceptor.Intercept(IInvocation invocation) in d:\DS\Builds\XXX\AdapterActivityDetailLoggingInterceptor.cs:line 32
-----------------------------------

EXCEPTION (LEVEL 2): System.NullReferenceException
EXCEPTION OUTPUT: Object reference not set to an instance of an object.

STACK TRACE:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Devart.Data.Linq.CompiledQueryCache.RegisterDataContext(Type dataContextType)
at XXX.CustomerDataContext..cctor() in d:\DS\Builds\XXX\CustomerModel.Designer.cs:line 30
-----------------------------------


Location: 352BF105-6FE7-4CFC-9153-0DB890328FAD
Assembly Name: XXX
Assembly Version: 2.13.1.0
Assembly File Version: 2.1301.0000.166
Source File: d:\DS\Builds\XXX\AdapterActivityDetailLoggingInterceptor.cs:32

Current Activity: c6445667-8435-4b8c-9581-37a9c15c01bb
Parent Activity: 430e24a3-d8d9-4b81-bab4-9576ddaacc35
Root Activity: 70b9cc51-4b1e-41a6-91cf-2db608ed8652

--- Tenant Data ---
Client: XXX
Environment: XXX
Database: XXX

-------------------------------------------------------------------------------------
Error Log 2:


2011-02-04 10:53:53.510 /LM/W3SVC/1/ROOT/XXX/2.13-1-129413156227617160 9160:2 XXX
AddCustomer
EXCEPTION (LEVEL 1): System.TypeInitializationException
EXCEPTION OUTPUT: The type initializer for 'XXX.CustomerDataContext' threw an exception.

STACK TRACE:

-----------------------------------

EXCEPTION (LEVEL 2): System.NullReferenceException
EXCEPTION OUTPUT: Object reference not set to an instance of an object.

STACK TRACE:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Devart.Data.Linq.CompiledQueryCache.RegisterDataContext(Type dataContextType)
at XXX.CustomerDataContext..cctor() in d:\DS\Builds\XXX\CustomerModel.Designer.cs:line 30
-----------------------------------


Location: 352BF105-6FE7-4CFC-9153-0DB890328FAD
Assembly Name: XXX
Assembly Version: 2.13.1.0
Assembly File Version: 2.1301.0000.166
Source File: d:\DS\Builds\XXX\AdapterActivityDetailLoggingInterceptor.cs:32

Current Activity: f6f308f9-ba39-435e-8a40-fdd00fb09977
Parent Activity: c489a4ff-e610-4671-b600-e3e4c0c6943b
Root Activity: 1a053057-f6c9-473b-8e2a-4903063e46c5

--- Tenant Data ---
Client: XXX
Environment: XXX
Database: XXX

----------------------------------------------------------------------------------

Is this an issue with the dot connect or might be any issue with my code?

Thanks,
Sandeep
sandeepchinni
 
Posts: 2
Joined: Fri 04 Feb 2011 19:47

Postby StanislavK » Tue 08 Feb 2011 17:38

Please describe the way you are working with your DataContext, and, if possible, send us the model and the generated DataContext class. We couldn't reproduce the issue when creating instances of DataContexts generated by Entity Developer.

Also, please specify the version of dotConnect for Oracle you are using.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Postby sandeepchinni » Mon 14 Feb 2011 16:17

I cannot send you the complete model and class, but here is a snippet...

The datacontext is being initialized as

Code: Select all
private CustomerDataContext Context
      {
         get
         {
            if (_context == null)
            {
               _context = new CustomerDataContext(_connection);//error here
               _context.Connection.Open();
            }
            return _context;
         }
      }


and the model designer has this code for the constructor

Code: Select all
private static System.Data.Linq.Mapping.MappingSource mappingSource = new Devart.Data.Linq.Mapping.AttributeMappingSource();
       
public CustomerDataContext(string connection) :
            base(connection, mappingSource)
        {
          OnCreated();
        }


The version that I am using is 5.70.180.0.
sandeepchinni
 
Posts: 2
Joined: Fri 04 Feb 2011 19:47

Postby StanislavK » Tue 15 Feb 2011 16:00

Please try the latest 6.10.103 build of dotConnect for Oracle and tell us if this helps. We couldn't reproduce the issue with the latest version in our environment.

You can download the new build from
http://www.devart.com/dotconnect/oracle/download.html
(the trial only) or from Registered Users' Area (provided that you have an active subscription):
http://secure.devart.com/
You may need new credentials to download the 6th version, please contact our Sales department to receive them: sales * devart * com .
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Re: type initializer for 'XXX.CustomerDataContext' threw an exce

Postby chrisxue815 » Wed 04 Oct 2017 16:11

CompiledQueryCache.RegisterDataContext internally uses Dictionary, which is not thread safe.
See a similar error in stackoverflow:
https://stackoverflow.com/questions/1320264/how-did-i-get-this-nullreferenceexception-error-here-right-after-the-constructor
chrisxue815
 
Posts: 1
Joined: Wed 04 Oct 2017 16:06

Re: type initializer for 'XXX.CustomerDataContext' threw an exce

Postby Shalex » Thu 05 Oct 2017 14:10

Could you please upload a test project for reproducing System.NullReferenceException (caused by CompiledQueryCache.RegisterDataContext) to ftp://ftp.devart.com (credentials: anonymous / yourEmail)?
Shalex
Devart Team
 
Posts: 7703
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle