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] <javascript:>>
> 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] <javascript:>.
> > 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.