Hmm I am confused. I had a look at the injected IL code in reflector and it 
looks ok for me:
 
.method privatescope hidebysig specialname rtspecialname static void 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Void>
 *.cctor 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.Common.Utilities:3.0.0.0/MeVis.Common.Utilities.StatefulValue<,>/.cctor()>*()
 cil managed
{
    .maxstack 8
    L_0000: ldstr "Static Constructor of class StatefulValue`2"
    L_0005: call void 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Void>
 [mscorlib 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Console
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Console>::WriteLine
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Console/WriteLine(String)>(string
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String>)
    L_000a: ldtoken MeVis.Common.Utilities.StatefulValue`2 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.Common.Utilities:3.0.0.0/MeVis.Common.Utilities.StatefulValue<,>><!TState,
 !TValue>
    L_000f: call class [mscorlib 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Type
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type>
 [mscorlib 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Type
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type>::GetTypeFromHandle
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type/GetTypeFromHandle(System.RuntimeTypeHandle):System.Type>(valuetype
 [mscorlib 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.RuntimeTypeHandle
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.RuntimeTypeHandle>)
    L_0014: newobj instance void 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Void>
 [syngo.Common 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14>]syngo.Common.Diagnostics.Tracing.FTraceDomain
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14/syngo.Common.Diagnostics.Tracing.FTraceDomain>::.ctor
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14/syngo.Common.Diagnostics.Tracing.FTraceDomain/.ctor(System.Type)>(class
 [mscorlib 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Type
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type>)
    L_0019: stsfld class [syngo.Common 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14>]syngo.Common.Diagnostics.Tracing.FTraceDomain
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14/syngo.Common.Diagnostics.Tracing.FTraceDomain>
 MeVis.Common.Utilities.StatefulValue`2 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.Common.Utilities:3.0.0.0/MeVis.Common.Utilities.StatefulValue<,>>::FTRACEDOMAIN_AEE2EE2A_E374_4555_A5EC_7B147AD45DD4
 
<http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.Common.Utilities:3.0.0.0/MeVis.Common.Utilities.StatefulValue<,>/FTRACEDOMAIN_AEE2EE2A_E374_4555_A5EC_7B147AD45DD4:syngo.Common.Diagnostics.Tracing.FTraceDomain>
    L_001e: ret 
}


Why to I still get the OutOfMemoryException on Access of the generic object. 



Am Donnerstag, 5. Februar 2015 15:42:03 UTC+1 schrieb Reh Gina:
>
> Thank you, I found the code and downloaded it.
> https://github.com/continuoustests
> I am not sure if If I can find the correct hint and would appreciate a bit 
> more help. In other words I feel a little bit over strained with that many 
> code.
> I found another method 
>
>  private static TypeReference GetDeclaringType(TypeReference declaringType)
>     {
>       // Instantiate the generic type before determining
>       // the current method
>       if (declaringType.GenericParameters.Count > 0)
>       {
>         var genericType = new GenericInstanceType(declaringType);
>         foreach (GenericParameter parameter in 
> declaringType.GenericParameters)
>         {
>           genericType.GenericArguments.Add(parameter.);
>         }
>
>         declaringType = genericType;
>       }
>       return declaringType;
>     }
>
> and added this to my code. The result is 
> static StatefulValue()
> {
>     Console.WriteLine("Static Constructor of class StatefulValue`2");
>     FTRACEDOMAIN_AEE2EE2A_E374_4555_A5EC_7B147AD45DD4 = new 
> FTraceDomain(typeof(StatefulValue<TState, TValue>));
> }
>
> But still I get the outOfMemoryException in Initializer.
>
> Now I added a dummy class which does exactly the stuff I want to inject 
>
>   class Dummy<A, B>
>   {
>     static private FTraceDomain domain = new FTraceDomain(typeof(Dummy<A, 
> B>));
>
>     public Dummy()
>     {
>       using (FTrace t = new FTrace(domain, "Dummy"))
>       {
>         
>       }
>     } 
>   }
>
> and the IL code of the static constructor shows (reflector):
>
>  .method private hidebysig specialname rtspecialname static void 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Void>
>  *.cctor 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.Tools.TracingInjector:3.0.0.0/MeVis.Tools.TracingInjector.Dummy%3C,%3E/.cctor()>*()
>  cil managed
> {
>     .maxstack 8
>     L_0000: ldtoken MeVis.Tools.TracingInjector.Dummy`2 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.Tools.TracingInjector:3.0.0.0/MeVis.Tools.TracingInjector.Dummy%3C,%3E><!A,
>  !B>
>     L_0005: call class [mscorlib 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Type
>  
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type>
>  [mscorlib 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Type
>  
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type>::GetTypeFromHandle
>  
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type/GetTypeFromHandle(System.RuntimeTypeHandle):System.Type>(valuetype
>  [mscorlib 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.RuntimeTypeHandle
>  
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.RuntimeTypeHandle>)
>     L_000a: newobj instance void 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Void>
>  [syngo.Common 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14>]syngo.Common.Diagnostics.Tracing.FTraceDomain
>  
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14/syngo.Common.Diagnostics.Tracing.FTraceDomain>::.ctor
>  
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14/syngo.Common.Diagnostics.Tracing.FTraceDomain/.ctor(System.Type)>(class
>  [mscorlib 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Type
>  
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type>)
>     L_000f: stsfld class [syngo.Common 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14>]syngo.Common.Diagnostics.Tracing.FTraceDomain
>  
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14/syngo.Common.Diagnostics.Tracing.FTraceDomain>
>  MeVis.Tools.TracingInjector.Dummy`2 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.Tools.TracingInjector:3.0.0.0/MeVis.Tools.TracingInjector.Dummy%3C,%3E><!A,
>  !B>::domain 
> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.Tools.TracingInjector:3.0.0.0/MeVis.Tools.TracingInjector.Dummy%3C%3C!0%3E,%3C!1%3E%3E/domain:syngo.Common.Diagnostics.Tracing.FTraceDomain>
>     L_0014: ret 
> }
>
>
> What does <!A, !B> mean and how to I receive it via monocecil?
>
>
> Am Donnerstag, 5. Februar 2015 13:55:46 UTC+1 schrieb Greg Young:
>>
>> We do it in continuoustests on github look in minimizer (sry at airport 
>> boarding so vant link etc)
>> On 5 Feb 2015 14:53, "Reh Gina" <[email protected]> wrote:
>>
>>> Now I am sure the generics are the bad ones. Does anybody know how to 
>>> get the Type of a class with generic parameters?
>>>
>>> Am Donnerstag, 5. Februar 2015 11:41:00 UTC+1 schrieb Reh Gina:
>>>>
>>>> May this be a problem with generic types? I suppose this only occurs 
>>>> for generic types because for generic types the reflector shows something 
>>>> like this
>>>>
>>>> FTRACEDOMAIN_AEE2EE2A_67c3e758-a6a1-45eb-9e59-9ff194abcc53 
>>>> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.Common.Utilities:3.0.0.0/MeVis.Common.Utilities.StatefulValue%3C,%3E/FTRACEDOMAIN_AEE2EE2A_67c3e758-a6a1-45eb-9e59-9ff194abcc53:syngo.Common.Diagnostics.Tracing.FTraceDomain>
>>>>  = new FTraceDomain 
>>>> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14/syngo.Common.Diagnostics.Tracing.FTraceDomain/.ctor(System.Type)>(typeof(StatefulValue
>>>>  
>>>> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.Common.Utilities:3.0.0.0/MeVis.Common.Utilities.StatefulValue%3C,%3E><,>));
>>>>
>>>>
>>>> What returns typeof(somegenerictype<>) ???
>>>>
>>>>
>>>> Am Donnerstag, 5. Februar 2015 09:07:46 UTC+1 schrieb Reh Gina:
>>>>>
>>>>> That makes no sense. I simply inject the initialization of a static 
>>>>> member into the static constructor. Looks like this afterwards (from 
>>>>> reflector):
>>>>>  
>>>>> static *VersionMessage 
>>>>> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.MeVisLab.RemoteClient:3.0.0.0/MeVis.MeVisLab.RemoteClient.Messages.VersionMessage/.cctor()>*()
>>>>> {
>>>>>     FTRACEDOMAIN_AEE2EE2A_319e3e9d-6fab-4076-9a42-108dc52c976b 
>>>>> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.MeVisLab.RemoteClient:3.0.0.0/MeVis.MeVisLab.RemoteClient.Messages.VersionMessage/FTRACEDOMAIN_AEE2EE2A_319e3e9d-6fab-4076-9a42-108dc52c976b:syngo.Common.Diagnostics.Tracing.FTraceDomain>
>>>>>  = new FTraceDomain 
>>>>> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://syngo.Common:1.0.0.0:008145f79b9aec14/syngo.Common.Diagnostics.Tracing.FTraceDomain/.ctor(System.Type)>(typeof(VersionMessage
>>>>>  
>>>>> <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://MeVis.MeVisLab.RemoteClient:3.0.0.0/MeVis.MeVisLab.RemoteClient.Messages.VersionMessage>));
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> The code which injects above line: 
>>>>>
>>>>>
>>>>>     /// <nn />
>>>>>     private static void 
>>>>> AddInitialisationOfFTraceDomainFieldToStaticConstructor(
>>>>>       ModuleDefinition module,
>>>>>       TypeDefinition type,
>>>>>       MethodDefinition staticConstructor)
>>>>>     {
>>>>>       staticConstructor.Body.SimplifyMacros();
>>>>>       Instruction firstInstruction = 
>>>>> staticConstructor.Body.Instructions.First();
>>>>>       ILProcessor ilProcessor = staticConstructor.Body.GetILProcessor();
>>>>>
>>>>>       Instruction loadClassTypeInstruction = 
>>>>> Instruction.Create(OpCodes.Ldtoken, type);
>>>>>       ilProcessor.InsertBefore(firstInstruction, 
>>>>> loadClassTypeInstruction);
>>>>>
>>>>>       Instruction callGetTypeInstruction = 
>>>>> Instruction.Create(OpCodes.Call,
>>>>>       module.Import(typeof(System.Type).GetMethod("GetTypeFromHandle")));
>>>>>       ilProcessor.InsertAfter(loadClassTypeInstruction, 
>>>>> callGetTypeInstruction);
>>>>>
>>>>>       var domainConstructor =
>>>>>         
>>>>> typeof(syngo.Common.Diagnostics.Tracing.FTraceDomain).GetConstructor(new[]
>>>>>  { typeof(Type) });
>>>>>       var domainConstructorReference = module.Import(domainConstructor);
>>>>>       Instruction domainConstructorInstruction = 
>>>>> Instruction.Create(OpCodes.Newobj, domainConstructorReference);
>>>>>       ilProcessor.InsertAfter(callGetTypeInstruction, 
>>>>> domainConstructorInstruction); // create new instance of person
>>>>>       Instruction popFTraceDomainVariableInstruction = 
>>>>> Instruction.Create(OpCodes.Stsfld, _fTraceDomainField);
>>>>>       
>>>>>       ilProcessor.InsertAfter(domainConstructorInstruction, 
>>>>> popFTraceDomainVariableInstruction);
>>>>>
>>>>>       staticConstructor.Body.OptimizeMacros();
>>>>>     }
>>>>>
>>>>>
>>>>> Am Mittwoch, 4. Februar 2015 17:18:44 UTC+1 schrieb Jb Evain:
>>>>>>
>>>>>> I'll go out on a limb an suggest your field initializer is taking a 
>>>>>> lot of memory? :) 
>>>>>>
>>>>>> Can you show what you're injecting? 
>>>>>>
>>>>>> On Wed, Feb 4, 2015 at 5:12 PM, Reh Gina <[email protected]> wrote: 
>>>>>> > Via injection I am adding a static field into a static class which 
>>>>>> already 
>>>>>> > contains two static fields. Injection code checks if static 
>>>>>> constructor is 
>>>>>> > already available, otherwise it will create one. In this case the 
>>>>>> static 
>>>>>> > constructor is available and the initialization of the static field 
>>>>>> is just 
>>>>>> > added before the existing instructions. At run time an 
>>>>>> OutOfMemoryException 
>>>>>> > occurs if accessing the injected object. 
>>>>>> > Does anybody has an Idea what can cause this exception? 
>>>>>> > 
>>>>>> > -- 
>>>>>> > -- 
>>>>>> > -- 
>>>>>> > mono-cecil 
>>>>>> > --- 
>>>>>> > You received this message because you are subscribed to the Google 
>>>>>> Groups 
>>>>>> > "mono-cecil" group. 
>>>>>> > To unsubscribe from this group and stop receiving emails from it, 
>>>>>> send an 
>>>>>> > email to [email protected]. 
>>>>>> > For more options, visit https://groups.google.com/d/optout. 
>>>>>>
>>>>>  -- 
>>> -- 
>>> --
>>> mono-cecil
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "mono-cecil" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
-- 
--
mono-cecil
--- 
You received this message because you are subscribed to the Google Groups 
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to