How can I get PostSharp to emit a message to the build window in VisualStudio for my Aspect - postsharp

I have an aspect (attribute) that I want to be sure is being added to the correct classes/events during compile time (technically, after compile time when PostSharp is instrumenting the code), so I have tried to add a WriteLine statement in the CompileTimeInitialize() method, but nothing is ever emitted to the "build" window:
[PSerializable]
public class LogEventAttribute : EventInterceptionAspect
{
public override void CompileTimeInitialize(EventInfo targetEvent, AspectInfo aspectInfo)
{
Console.Out.WriteLine($">>>> EVENT: {targetEvent.Name} CLASS: {targetEvent.DeclaringType?.FullName}");
base.CompileTimeInitialize(targetEvent, aspectInfo);
}
}
I have also tried Console.Error.WriteLine(), Debug.WriteLine(), and Trace.WriteLine() all to no avail. Any suggestions as there appears to be no documentation (that I can find anyway) regarding this on the PostSharp site.

Using Message.Write.
Console.WriteLine does not work because compilation happens in a background process.

Related

Set OnAutomaticHitTest and OnInteractiveHitTest during runtime

I'm placing my Plane Stage and Plane Finder and setting the attributes at runtime, but there are two attributes I can't figure out how to set: OnAutomaticHitTest and OnInteractiveHitTest.
I saw that it expects something of the type HitTestEvent, but i can't figure out how to set my custom function here.
Can someone Help me?
You can find the documentation for the PlaneFinderBehaviour here
Essentially, you don't actually define these attribute but you use them to fire events.
For example:
public class CustomPlaneFinderBehaviour : PlaneFinderBehaviour
{
public void CustomIntPerformHitTest(Vector2 screenPosition)
{
//Triggered on interactive hit test
}
public void CustomAutoPerformHitTest(Vector2 screenPosition)
{
//Triggered on automatic hit test
}
}
Then in the inspector you are able to define the events, by pressing the plus button and choosing the current script in the box. It then gives you the option to change the function that is called.
Here on interactive hit test has been defined and automatic hit test has not:
You need to use Unity's AddListener call
void HandleHitTest(HitTestResult htr)
{
//Handle Test Here
}
planeFinderBehavior.OnAutomaticHitTest.AddListener(HandleHitTest);

Unity WebGL - Locating code that triggers Reflection.emit

I've run into the dreaded Reflection.emit issue in my webplayer build and am unable to locate what is triggering it. I'm currently commenting out code method by method and rebuilding to locate the cause and have narrowed it down to the below.
I'm not using JSON so the various JSON libraries aren't the cause, nor any of the other result suggestions returned by google.
How can i more easily go about locating the cause of this error. I have full stack trace on and well as full debugging, but all i get is the following console output.
NotSupportedException: C:\Program Files\Unity 2018.2.0b2\Editor\Data\il2cpp\libil2cpp\icalls\mscorlib\System.Reflection.Emit\AssemblyBuilder.cpp(20) : Unsupported internal call for IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported.
Rethrow as TypeInitializationException: The type initializer for 'System.Reflection.Emit.DynamicMethod.AnonHostModuleHolder' threw an exception.
//NOTE: appM.procM is a C# .Net 4.x dynamic variable EG:
//public dynamic procM = GetProcClass(strProcName)
public void ShowProcList() {
/* Rest of method commented out*/
if(appM.procM == null){
procList.Initialize(appM.procM.lstNames, this);
}
/* Rest of method commented out*/
}
public void Initialize(List<string> lstNames, UIM um, string currProc=null) {
uiM = um;
//cleanup of the list before populating
foreach(Transform fld in Panel.transform) {
Destroy(fld.gameObject);
}
/* Rest of method commented out*/
}
Update: I narrowed down the problem line of code, but haven't closed the question as there's got to be an easier way than commenting out line by line and rebuilding.
For future searchers, the issue is the if(appM.procM == null) check. As procM is a dynamic variable reflection is used which kills AOT in webGL builds. No compiler warnings were generated to save myself from myself.
Nevermind, i am an idiot, The option Enable Exceptions under Player Settings was set to Full Without Stacktrace and not Full with Stacktrace.
The value Full With Stacktrace contains the pertinent data. Easily locatable in the browsers console. Warning that full debugging does increase build times and slow down the application.

HTML version of LibGDX game doesn't show any logging

I am having trouble getting a html version of my programme to appear.
I am using LibGDX 1.3.1 and running in Java it works fine.
I uploaded the game here:
http://www.darkflame.co.uk/MeshExplorer/index.html
The libgdx loading bar appears and finishes - and in Chromes network tag I can see assets loading.
However, nothing appears other then the rectangle of the expected game size.
Most confusingly for me though, I dont see any crashes or logs from my code.
That is, there is nothing after "SoundManager 2 loaded (OK) "
Given that the first lines of my main core class are:
game=this;
font = new BitmapFont();
batch = new SpriteBatch();
Gdx.app.log(logstag, "loading..");
I expected at least to see "loading.."
I even added some gwt logs to html launcher
public class HtmlLauncher extends GwtApplication {
static Logger Log = Logger.getLogger("HtmlLauncher");
#Override
public GwtApplicationConfiguration getConfig () {
Log.info("GwtApplicationConfiguration");
System.out.print("GwtApplicationConfiguration");
return new GwtApplicationConfiguration(640, 480);
}
#Override
public ApplicationListener getApplicationListener () {
Log.info("test, returning class ME() ");
System.out.print("test, returning class ME() ");
return new ME();
}
}
again, nothing.
I am at a lose how to disorganize this problem further.
It just seems like libgdx isn't even attempting to run my code.
The default logging level in the html target is LOG_ERROR. You would not see any Gdx.app.log messages unless you set the logging level to LOG_INFO.
Calling Gdx.app.setLogLevel(LOG_INFO) in your getConfig or getApplicationListener methods should do the trick.

condition not working sometimes with gwt

I'm having a rare issue in my code, I have a method that makes a very simple validation based on a string variable:
private void showNextStep(String psCondition,String poStepName){
int liCurrentStep=Integer.valueOf(poStepName);
String lsNextTrueStep=moSteps[liCurrentStep][4];
String liNextFalseStep=moSteps[liCurrentStep][5];
if ("Yes".equals(psCondition)){
moFrmStepsContainer.getField(liNextFalseStep).hide();
moFrmStepsContainer.getField(lsNextTrueStep).show();
}else{
moFrmStepsContainer.getField(liNextFalseStep).show();
moFrmStepsContainer.getField(lsNextTrueStep).hide();
}
}
Now, here is the ticky part: if I execute the application without debugging mode, it does the validation right all the time, how ever if don't it always goes to the else block (or at least I think) I tried to use JS alerts (I have a class that calls JS methods) to debug manually and check the valors of the variables; the valors where all right and the validation was also good. This means that only debugging or putting alerts before at the beggining of the IF block it does the validation right, otherwise it always goes to the ELSE, what do you think it could be?
It might be worth mentioning this is a web application made in netbeans 6.9, using the framework GWT 2.1. This application runs in firefox 25.0.1
Thank you!
UPDATE
Here is the code of the event that calls my method
final ComboBoxItem loYesNo=new ComboBoxItem("cmbYesNo" + moSteps[liStepIndex][0],"");
loYesNo.setValueMap("Yes","No");
loYesNo.setVisible(false);
loYesNo.setAttribute("parent", liStepIndex);
loYesNo.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent poEvent){
String lsStepName=loYesNo.getName();
FormItem loItem=moFrmStepsContainer.getField(lsStepName);
String liStepNumber=String.valueOf(loItem.getAttributeAsInt("parent"));
showNextStep((String)poEvent.getItem().getValue(),liStepNumber);
}
});

Handle Window close event

I'm trying to handle the event when the close button of a Window is clicked:
// View Code
#Override
public void attachWindowListener(WindowListener listener) {
window.addWindowListener(listener);
}
// Presenter code
view.attachWindowListener(new WindowListener(){
public void windowHide(WindowEvent we) {
GWT.log("Window Event - Processing fields");
processFields();
}
});
However, the windowHide function seems to be not executed since I can't see the log I placed there.
How to properly handle that event?
How about
Window.addCloseHandler(
new CloseHandler<Window>()
{
public void onClose( CloseEvent<Window> windowCloseEvent )
{
// Do your worst here
}
} );
I usually put this in onModuleLoad() in my EntryPoint class.
Cheers,
Based on the information provided I would guess that either a.) the events you think are firing do not fire for the Window component (even if it seems like they should) or b.) the events are firing but in a different order than you expect.
For example, it's possible that a BrowserEvent or some other event is firing first as the window is being closed and the Window object's WindowEvent never fires. According to the API docs for GXT 2.x, the WindowEvent will fire on hide and deactivate but it does not specify that it fires on close. The GXT 3.0.x API doc is less clear on this point but I would assume the same behavior. Unfortunately Sencha does not provide good documentation on what events fire for a given component and in what order.
With that said, I have had some luck working through similar issues to this by using a debug class which outputs all the events on a component to which it is attached. This may shed some light on which events are firing and their order of execution, and you may find an optimal event to which you can attach your processFields() method.
For a good example of a debugger class, see this answer from a related post: https://stackoverflow.com/a/2891746/460638. It also includes an example of how to attach the debugger to your component.
API Doc for Window, GXT 2.x: http://dev.sencha.com/deploy/gxt-2.2.5/docs/api/com/extjs/gxt/ui/client/widget/Window.html
API Doc for Window, GXT 3.0.x: http://dev.sencha.com/deploy/gxt-3.0.0/javadoc/gxt/com/sencha/gxt/widget/core/client/Window.html
This worked:
window.addListener(Events.Hide, new Listener<ComponentEvent>() {
#Override
public void handleEvent(ComponentEvent be) {
// Do stuff
}
});