c# - How to locally disable optimization -
i faced strange problem. app has next code, execute on startup:
protected override void registertypes() { // app.container - unitycontainer var dvcc = new myclientcore(new mysorter()); app.container.registerinstance(typeof(clientcore), dvcc); app.container.registerinstance(typeof(myclientcore), dvcc); this.dataprovider = new myprovider(); this.dataprovider.configure(app.container); app.container.registerinstance(typeof(provider), this.dataprovider); app.container.registerinstance(typeof(myprovider), this.dataprovider); // create view models , register them in container this.registerviewmodels(); // command - singleton, resolved in ctor view models, // registered in registerviewmodels(); command.instance.initcommands(); // create , configure shell } when app execute in debug configuration there no problem. when app execute in release configuration in visual studio. when try start app directly typeinitializationexception in command ctor because of resolution of dependency registered in dataprovider.configure method.
i thought cause in jit optimization, , code may execute like
protected override void registertypes() { command.instance.initcommands(); // other method body } i found solution - mark registertypes method atribute [methodimpl(methodimploptions.nooptimization)].
but maybe exist better method fix it? gratiful link, when situation explained simple words.
p.s. sorry english.
Comments
Post a Comment