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").

Royi Namir
  • 144,742
  • 138
  • 468
  • 792

2 Answers2

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.

mlorbetske
  • 5,529
  • 2
  • 28
  • 40
  • I'm in web site...it doesnt have this menu. – Royi Namir Jan 03 '13 at 11:54
  • @RoyiNamir updated, sorry, didn't know it was a web site project at first – mlorbetske Jan 03 '13 at 11:59
  • @RoyiNamir if you were to use the #define, it'd have to go in `Global.asax.cs` not in a script block in `Global.asax` – mlorbetske Jan 03 '13 at 12:01
  • global.asax in website doesnt have cs. – Royi Namir Jan 03 '13 at 12:02
  • 1
    You can add a code-behind. But since Trace is not recommended for ASP.NET it's all a bit academic. – H H Jan 03 '13 at 12:04
  • @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) ? – Royi Namir Jan 03 '13 at 12:08
  • 1
    Which trace report? I think you're confusing 2 systems. Diagnostics.Trace != TraceContext. – H H Jan 03 '13 at 12:10
  • Could `Context.Trace.Write(...);` be what you're looking for instead? (in your Global.asax) http://msdn.microsoft.com/en-us/library/system.web.tracecontext.aspx – mlorbetske Jan 03 '13 at 12:11
  • I added this line ( and remove diagnostics) but http://i.stack.imgur.com/qlAST.jpg – Royi Namir Jan 03 '13 at 12:15
  • I had to check Define DEBUG constant too mot only Define TRACE constant – Ghini Antonio Nov 05 '14 at 08:34
  • 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! – J.D. Mallen Mar 19 '19 at 17:38
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

AakashM
  • 62,551
  • 17
  • 151
  • 186