Method invocation is skipped in C#?
Asked Answered
W

2

11

I have this simple code :

 void Application_BeginRequest(object sender, EventArgs e) 
    {
        Trace.Write("Exception Handling", "......");
    }

However re-sharper scream (no-error only suggest) about :

enter image description here

Method invocation is skipped. Compiler will not generate method invocation because the method is conditional, or it is a partial method without implementation

I'm not able to see this line in the Trace output.

however - other traces - I do see.

Why is that ?

(p.s. The page (which is under web Site project) has trace="true").

Whitten answered 3/1, 2013 at 11:44 Comment(9)
trace==true is not related to TRACEIrriguous
@HenkHolterman What do you mean ? <%@ Page Trace="true" %> allows me to trace. ( can you please explain ?)Whitten
Remove using System.Diagnostics;Irriguous
@HenkHolterman I removed it and now I wrote only Context.Trace.Write("34343"); but i.sstatic.net/qlAST.jpgWhitten
I don't click on picture-links.Irriguous
@HenkHolterman Ok. (it's just the trace output.). Thanks for your help.Whitten
@RoyiNamir Why did you delete your UTF-8 question a few minutes ago? I think I found some usefull information for it.Webfoot
@SonerGönül because I was fool enough not to look for it in wikipedia which shows how its done....Whitten
@RoyiNamir Ok. Just want to say there is some usefull information also msdn.microsoft.com/en-us/library/ms404377.aspxWebfoot
E
22

Be sure that the TRACE constant is defined in your project settings for your current build configuration.

enter image description here

UPDATE

Since it's a website project, you could put

#define TRACE

at the top of Global.asax.cs so that the trace symbol is defined.

Emmaemmalee answered 3/1, 2013 at 11:52 Comment(11)
I'm in web site...it doesnt have this menu.Whitten
@RoyiNamir updated, sorry, didn't know it was a web site project at firstEmmaemmalee
@RoyiNamir if you were to use the #define, it'd have to go in Global.asax.cs not in a script block in Global.asaxEmmaemmalee
global.asax in website doesnt have cs.Whitten
You can add a code-behind. But since Trace is not recommended for ASP.NET it's all a bit academic.Irriguous
@HenkHolterman Hi. I did added a cs file and in global.asax I added <%@ Application Language="C#" Inherits="myClass" %> and not it doesnt yell. However - I dont see the line in the trace report. Does trace can't handle info from the http moudle pipeline ( global asax events) ?Whitten
Which trace report? I think you're confusing 2 systems. Diagnostics.Trace != TraceContext.Irriguous
Could Context.Trace.Write(...); be what you're looking for instead? (in your Global.asax) msdn.microsoft.com/en-us/library/system.web.tracecontext.aspxEmmaemmalee
I added this line ( and remove diagnostics) but i.sstatic.net/qlAST.jpgWhitten
I had to check Define DEBUG constant too mot only Define TRACE constantArchetype
For those who got here and are still scratching their heads: make sure the TRACE constant is turned on in the project that needs it, not necessarily the one that's calling it. For instance, in our solution, one project implemented a TraceListener, and another project created a TraceSource and added the listener. The TRACE constant was on in the project with the TraceSource, but not the one with the custom listener, so it failed to write to the affected listener while writing to the others. Tricky, tricky!Martinsen
W
2

To quote the JetBrains wiki (which may* be linked to from the ReSharper menu under 'Why is ReSharper suggesting this'):

While coding, you may encounter warnings regarding methods whose invocations will not be generated by the compiler. Why would that be? Typical cases are conditional methods that will not be compiled (e.g., it’s marked with [ReSharperInt:Conditional("DEBUG")] and you’re in RELEASE mode). Another reason why a method may be skipped is that, at some point, its body has been declared as partial and the implementation wasn’t provided.

Given that this is on a method of Trace, I'd suggest the first of these typical cases is the one that applies.

* I haven't got v7 yet

Wanderlust answered 3/1, 2013 at 11:44 Comment(1)
1) my global asax file is not partial . 2)I;m in debug mode.Whitten

© 2022 - 2024 — McMap. All rights reserved.