Hello.
I tried to avoid Oracle limitation of 1000 items for “IN” operator at maximum in out .NET project using following UDT:
CREATE OR REPLACE TYPE array_long AS TABLE OF NUMBER(10,0);
I have prepared a simple demo project and everything was working. Then I tried to implement this solution to our project and an unexpected problem appeared:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Oracle.ManagedDataAccess
StackTrace:
at Oracle.ManagedDataAccess.Types.OracleUdt.GetAllReferencedAssemblies() in Oracle.ManagedDataAccess.Types\OracleUdt.cs:line 752
When OracleUdt tries to search for OracleCustomTypeMappingAttribute in all loaded assemblies the function GetAllReferencedAssemblies() finds in my case 15 assemblies. The first one (by a chance or because stack is used?) is something called “Anonymously Hosted DynamicMethods Assembly”.
The FullName of this assembly is added to the collection of possible ones and later Assembly.Load(…) is called for this FullName. But this assembly cannot be loaded by its nature, so exception is raised and catched and variable assembly2 contains null value.
This variable is used to call hashtable.Contains(assembly2.FullName) and the exception “Object reference not set” is raised…
It seems this “Anonymously Hosted DynamicMethods Assembly” was created in runtime by some other library referenced from our project (could be OllamaSharp.dll which is not used in my simple demo project). This assembly is system and quite special and cannot be loaded - according to StackOverflow here:
https://stackoverflow.com/questions/2636141/what-exactly-is-the-anonymously-hosted-dynamicmethods-assembly-and-how-can-i-m
Possible easy solutions:
- check if assembly2 after Assembly.LoadFrom() is null or not
- add problematic assembly to the list of excluded assemblies (s_ODPExcludedAssembliesList) in OracleUdt2 constructor
The version of ODP used in our project is Oracle.ManagedDataAccess.Core 23.26.200.
Would be nice to have this fixed. :-)
Mirek
PS: The declaration of variable assembly2 should be moved into while loop to avoid re-using its value in case the assembly cannot be loaded.
PS2: The decompiled code of OracleUdt2 with my comments what is happening:
internal static ArrayList GetAllReferencedAssemblies()
{
Hashtable hashtable = new Hashtable();
Hashtable hashtable2 = new Hashtable();
Stack stack = new Stack();
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); // finds problematic assembly
foreach (Assembly assembly in assemblies)
{
if (!IsExcludedAssembly(assembly)) // problematic assembly is not excluded
{
if (!assembly.IsDynamic && !hashtable2.Contains(assembly.FullName))
{
hashtable2.Add(assembly.FullName, assembly.Location);
}
stack.Push(assembly.FullName); // adds problematic assembly to possible ones
}
}
Assembly assembly2 = null;
while (stack.Count > 0)
{
try
{
string text = (string)stack.Pop(); // gets "Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
try
{
assembly2 = Assembly.Load(text); // fails to load problematic assembly => exception
}
catch
{
if (hashtable2.Contains(text)) // not contained in hashtable2
{
assembly2 = Assembly.LoadFrom((string)hashtable2[text]);
}
}
...
if (!hashtable.Contains(assembly2.FullName)) // exception because assembly2 is null
{
hashtable.Add(assembly2.FullName, assembly2);
}
The properties of “Anonymously Hosted DynamicMethods Assembly” (IsDynamic = True, Location = “”):
- assembly {Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null} System.Reflection.Assembly {System.Reflection.RuntimeAssembly}
CodeBase "file:///C:/.../bin/Debug/net8.0/OllamaSharp.dll" string
CustomAttributes {System.Reflection.CustomAttributeData[0]} System.Collections.Generic.IEnumerable<System.Reflection.CustomAttributeData> {System.Reflection.CustomAttributeData[]}
DefinedTypes {System.RuntimeType[0]} System.Collections.Generic.IEnumerable<System.Reflection.TypeInfo> {System.RuntimeType[]}
EntryPoint null System.Reflection.MethodInfo
EscapedCodeBase "file:///C:/.../bin/Debug/net8.0/OllamaSharp.dll" string
ExportedTypes {System.Type[0]} System.Collections.Generic.IEnumerable<System.Type> {System.Type[]}
FullName "Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" string
GlobalAssemblyCache false bool
HostContext 0 long
ImageRuntimeVersion "" string
IsCollectible false bool
IsDynamic true bool
IsFullyTrusted true bool
Location "" string
+ ManifestModule {RefEmit_InMemoryManifestModule} System.Reflection.Module {System.Reflection.RuntimeModule}
+ Modules {System.Reflection.RuntimeModule[1]} System.Collections.Generic.IEnumerable<System.Reflection.Module> {System.Reflection.RuntimeModule[]}
ReflectionOnly false bool
SecurityRuleSet None System.Security.SecurityRuleSet
SyncRoot {object} object
_ModuleResolve null System.Reflection.ModuleResolveEventHandler
m_assembly 0x0000017ab8aa6450 System.IntPtr
m_fullname "Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" string
m_syncRoot {object} object
+ Static members