Bookmark and Share
Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Wednesday, July 10, 2013

TIP : Visual studio Remote debugging on different domains

Hello, you need to debug a remote server, from your workstation, you configure all the things following Microsoft’s specs.. but , you realize that is a hell to configure remote debugging on two machine with different domains.
Here is a trick :
  1. Create a new LOCAL user on the target server, with administrative privileges.
  2. Enable this user to remote connection
  3. Create a new LOCAL user on your workstation, with the same username and same password and with administrative privileges..
  4. Connect to the target server using remote desktop with the new user (this will create the user profile on the server)
  5. Launch the remote debugger on the target server
    image
  6. Go to options and copy the url of the remote debugger:
    image
  7. On your workstation open in visual studio the debug window
  8. Type in the address edit box the value  NEWUSERNAME@TARGETSERVERNAME (you just copied it)
  9. VoilĂ ! The remote debugger should connect successfully to the target server.
  10. If you have any problem try disabling the firewall on the two machines.
You can skip point 4 , you can execute the remote debugger using the “runas” command. If you connect using remote desktop you will have the profile of the user created on the target server, and I think that this helps.
Let me know if this helps you.
Happy remote debugging!

Friday, February 15, 2013

Convert from VB.NET to C# and C# to VB

Code Converter is a free and simple VB to C# and C# to VB code converter. While there are several other good code converters available, none are perfect. Some are buried in busy websites. Some are awkward to use. Some just don't convert accurately! Code Converter, while not yet perfect, aims to address these issues and provide the best free .NET converter available on the web.

image

Monday, May 09, 2011

Sharp Snippet Compiler: there’s a new interactive .net compiler in town

If you need to test one C# instruction and you don’t want to wait 3 minutes for the Visual Studio 2010 startup, here is the solution, use Sharp Snippet Compiler, write the code, add breakpoints , hit F5 and see the results:

image

Here are the functions available:

  • variables watch window
  • stepping through the code
  • assembly references
  • light and fast
  • syntax highlighting
  • IntelliSense code-completion
  • supports .NET 3.5 features

This tool replaces the old “Snipper Compiler”, last updated in 2007 :

image

Friday, July 23, 2010

Simply write logs from your .net app using System.Diagnostics.Trace

Here is one of the simplest method for logging from your application, simply use the System.Diagnostics.Trace class and call:

System.Diagnostics.Trace.WriteLine(message);

and add to the App.Config file this section:

<?xml version="1.0"?>
<
configuration>
<
system.diagnostics>
<
trace autoflush="false" indentsize="4">
<
listeners>
<
add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="MyService.log" />
<
remove name="Default" />
</
listeners>
</
trace>
</
system.diagnostics>
</configuration>

And the logging will be executed succesfully.


If you need the logs on the Event Log add:

<add name="myEventListener" type="System.Diagnostics.EventLogTraceListener"  initializeData="TraceListenerLog" />

And you’ll find the event log populated with your application log.

Tuesday, October 13, 2009

Convert c++ bool to .NET bool

Be careful when you work with Interop and you call functions written in C++ returning bool.
In c++ the bool type is managed with one byte, in .Net Framework the bool type is managed with 4bytes(32bit).

So if you have a c++ api like this:

extern "C" bool GetBoolStatusFromC();


and a definition in the c# code like this:

[DllImport("myOldCpp.dll", CharSet = CharSet.Unicode)]
extern public static bool GetBoolStatusFromC();


You could have strange results, sometimes you receive true sometimes you receive false without a clear logic.

When the C++ bool is returned it is stored with one byte in AL and it is mapped to the EAX registy that is 4 bytes replacing only the last byte.
The other 24 bits remains dirty and they should contains values from other system calls that works with the EAX register.
So, the dirty 24 bytes causes random C# bool values, without control.

The solution is:

- decorate the PInvoke declaration with [return:MarshalAs(UnmanagedType.I1)]
- change the c++ declaration and use INT as return value.

Hope it helps,

Tuesday, November 13, 2007

DropDownList binding to List

Here is the simplest way to bind an asp.net DropDownList to List<string>:

List
<string> list = new List<string>();
list.Add(
"AAA");
list.Add(
"BBB");
mydrop.DataSource = list;
myAnno.DataBind();
 
 
 

Friday, November 02, 2007

DataBind di un dictionary object

Ecco come eseguire il databind di una dropdown ad un oggetto dictionary:
 
//definisco il dizionario
diz = new Dictionary<string, string>();
... //lo popolo
diz.Add("aakey","aaaaaa");
diz.Add("bbkey","bbbbbb");
dropLista.DataSource = diz;
dropLista.DataTextField = "Key";
dropLista.DataValueField = "Value";
dropLista.DataBind();
//semplice no?