Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

2009/10/21

Error "The remote debugger is not an acceptable version"

If you try to debug an ASP.NET application remotely using Remote Debugging Monitor (msvsmon.exe) and you get the following error:
The remote debugger is not an acceptable version
it means that the versions of Visual Studio and Msvsmon are different (e.g. Visual Studio 2005 + Msvsmon 2008).

2009/05/15

Missing auto-generated Resources.Designer.cs file

If the Resources.Designer.cs file is missing and there is no Run Custom Tool option in the context menu for the Resources.cs file (or, of course, any other resources file), it probably means that the Custom Tool property of the Resources.cs file is empty:


This is what MSDN says about the Custom Tool property:
Custom tools are components that can be used to transform files from one type to another at design time. For example, a custom tool might be a dataset code generator that reads in an XML Schema (.xsd) file and generates classes in a code file that programmatically exposes its tables and columns. There is a predefined list of custom tools available in the product; this property enables you to see which custom tool is applied to a file. In rare circumstances, you might have to change the value of this property. The value of this property must be either blank or one of the built-in custom tools.
In case of Visual Studio 2008 the default tool generating the *.Designer.cs files is ResXFileCodeGenerator - type it in the property and the problem should be solved:


UPDATE:

I found an easier way to do it:

2007/07/27

Preventing code from being generated in InitializeComponent() method for a property

When you place controls on a form, Visual Studio generates code in the InitializeComponent() method that sets values of their properties.

If you are developing a custom control and you don't want Visual Studio to generate such code for some of its properties, you should apply the DesignerSerializationVisiblityAttribute to such properties and place DesignerSerializationVisiblity.Hidden value on them.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DateTime Value
{
    get { /* ... */ }
    set { /* ... */ }
}
More information about customizing the code generated by Visual Studio can be found here.

2007/05/16

A SQL CLR user-defined aggregate - notes on creating and debugging

At the end of this post you will find my very first attempt to use one of the new features of SQL Server 2005 - CLR integration. It is a CLR user-defined aggregate that produces a comma-separated (comma plus space to be precise) list of values.
Column1
--------
aaa
bbb       -->   aaa, bbb, ccc
ccc
My code is a modified version of an example that I found here.

Global variables

You may expect (at least I did) that if you have a global variable (e.g. intermediateResult in my example) and you assign it a value in the Init method then you will be able to use this value in the Terminate method. Well, that's not true.

If you need to use a value of some variable in the Terminate method, you have to serialize it in the Write method (to save the needed value) and then deserialize it in the Read method and assign to some variable (to restore the needed value).

You can of course save and restore more than one variable - use some kind of serializable object to store the values.

Debugging

There is an MSDN article that explains exactly how to debug a CLR user-defined aggregate - Walkthrough: Debugging a SQL CLR User-Defined Aggregate - nonetheless, I encountered one problem.

I started with a solution that contained two projects - one project contained the aggregate code and the other was for a SQL test script. It is possible to perform debugging in such configuration (I managed to do it, although I am not sure how), but it is a better idea to have a single SQL Server project with both the aggregate code and SQL test scripts. This is what the IDE expects, so following this advice can spare you lots of hassle.

For example, MSDN says that to debug a CLR user-defined aggregate you need to enable CLR Debugging, but it doesn't say that Application Debugging must also be enabled.

Application Debugging option

When I worked with a single project, Visual Studio enabled this option automatically when needed, while with the two-project solution I had to do it myself.
using System;
using System.Data;
using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
using System.IO;
using System.Text;

[Serializable()]
[SqlUserDefinedAggregate(
    Format.UserDefined,
    IsInvariantToNulls=true,
    IsInvariantToDuplicates=false,
    IsInvariantToOrder=false,
    MaxByteSize=8000)]
public class Concat : IBinarySerialize
{
    #region Private fields
    private string separator;
    private StringBuilder intermediateResult;
    #endregion

    #region IBinarySerialize members
    public void Read(BinaryReader r)
    {
        this.intermediateResult = new StringBuilder(r.ReadString());
    }

    public void Write(BinaryWriter w)
    {
        w.Write(this.intermediateResult.ToString());
    }
    #endregion

    #region Aggregation contract methods
    public void Init()
    {
        this.separator = ", ";
        this.intermediateResult = new StringBuilder();
    }

    public void Accumulate(SqlString pValue)
    {
        if (pValue.IsNull)
        {
            return;
        }

        if (this.intermediateResult.Length > 0)
        {
            this.intermediateResult.Append(this.separator);
        }
        this.intermediateResult.Append(pValue.Value);
    }

    public void Merge(Concat pOtherAggregate)
    {
        this.intermediateResult.Append(pOtherAggregate.intermediateResult);
    }

    public SqlString Terminate()
    {
        return this.intermediateResult.ToString();
    }
    #endregion
}

2007/01/25

HOWTO: Edit properties of DataGrid columns (.NET 1.1)

Editing DataGrid properties
It's probably obvious for everyone working with Visual Studio 2003, but it doesn't work this way in VS 2005 (which I usually use) and as a result it recently took me a while to find this option.

2007/01/12

Reading data from a sorted view (Microsoft SQL Server)

If you read data from a sorted view (a view that contains an ORDER BY clause in its SELECT statement) into a DataTable (ADO.NET) or a ADODB.Recordset ('old' Visual Basic 6 ADO), it will not sorted in the DataTable/Recordset.

2006/12/21

A property of a custom control is not shown in the Properties pane

If you are creating a custom control and it has a property that is not shown in the Properties pane in Visual Studio IDE, ensure the property is not write-only.

Write-only properties are not shown in the Properties pane.
Read-and-write as well as read-only properties are shown in the Properties pane.

2006/07/19

Visual Studio 2003 sets a breakpoint in another file

There is a bug in Visual Studio 2003 that sometimes makes setting a breakpoint in certain files impossible. When you try to set it, the breakpoint is set, but not in the file that you opened - the moment you hit F9, VS jumps to another file and sets the breakpoint there.

I struggled with this problem for quite a long time. I tried using the mouse instead hitting F9, setting the breakpoint on different lines, reopening the file, reloading the project, restarting VS, using another machine. Nothing helped.

Finally, I discovered that I could open a Breakpoints window (Crtl+Alt+B), press New button and create a new Function Breakpoint - a breakpoint of this type was created successfully.



Note that you can copy the full name of a function from the Class View window.

2006/06/21

Debugging a Windows service

OnPause, OnContinue and OnStop methods can be debugged by simply attaching to the [WindowsServiceName].exe process and setting breakpoints in the appropriate places.

The problem gets a little bit harder when it comes to debugging OnStart method, since there is no process that can be attached to, because the service is not running. There are many ways to solve this problem, but, in my opinion, the easiest one is to
call a System.Diagnostics.Debugger.Launch() method within the OnStart method in order to start a debugger programmatically.

A detailed description of this problem can be found here.

2006/04/12

Visual Studio - Command Window vs. Immediate Window

While debugging in Visual Studio, I often use Command Window to check values of variables (?mySqlStr), assign values to variables (mySqlStr = "SELECT FOO_ID FROM dbo.FOO") or execute short code snippets (myDS.Fill()).

Today I closed Command Window and re-opened it after a while. And I could no longer evaluate any expressions. I also noticed a > prompt that I've never seen before.

It turns out that Command Window has two different modes (clicky):
  • Command mode - used for executing Visual Studio Commands directly in the IDE, bypassing the menu system, or for executing commands that do not appear in any menu,
  • Immediate mode - used for debugging purposes, evaluating expressions, executing statements, printing variable values, and so forth.
Command mode (notice the prompt)


Switching from Command mode to Immediate mode (type immed and press Enter)

Command Window - Immediate mode (no prompt)

2006/03/12

devenv - building a .NET solution from the command line

The easiest way to build a .NET solution (or a project) from the command line is to use devenv command.

However, there are two devenv files - devenv.com and devenv.exe. Today, I have noticed one really essential difference between them. The former one is a console tool, while the latter one is not. If you type devenv.exe to build a solution, it will start a background process and immediately return control to the console. It means that, if devenv.exe is used in a batch file, the commands succeeding it may be executed before the build process completes.

UPDATE:

The above happens only when you type something like devenv.exe SomeSolution.sln /Rebuild Release in the command line and hit Enter. It does not happen when such a command is used in a batch file.

2005/12/02

Visual Studio add-ins and .NET tools

Just a few links today:

2005/11/01

VS 2005 Beta 2 - cannot create a new project or open an existing one

I have been using Visual Studio 2005 Beta 2005 for a few weeks and one day, completely out of the blue it failed to open my project. I tried to open another one - the same result. I also couldn't create a new project.

Unfortunately, I didn't jot down the error message, but I remember it mentioned Microsoft.Common.targets file.

I checked this file on my machine and it turned out that it was empty. I did some googling to make sure that it is not normal and then reinstalled .NET Framework 2.0 (use repair option) - it helped!

2005/09/15

How to insert multiline text when Form.AcceptButton is set?

I've just re-discovered it - I don't like re-discovering things. I have spent an hour trying to solve this problem and once I've figured out how to do it, I've realized that I had had exactly the same problem about a month ago and I had already worked it out back then.

Anyway, let's describe the problem first:
1. There is a form - myForm.
2. There is a TextBox (or RichTextBox) control on myForm - myText. There is also a Button - myButton - on the same form.
3. The AcceptButton property of myForm is set to myButton.
4. The myText.Multiline is set to true. However, pressing Enter key does not insert a newline, but activates myButton instead.

The solution is simple:
1. In myText.GotFocus (or myText.Enter) event set myForm.AcceptButton to Nothing (VB) or null (C#).
2. In myText.LostFocus (or myText.Leave) event set myForm.AcceptButton back to myButton.

2005/08/14

Why can't I decrypt a string I've just encrypted?

If you are using one of .NET CryptoService providers (like DESCryptoServiceProvider or RijndaelManaged), there's a trap that you can easily fall in (I did).

To encrypt data (a string converted previously into a byte array), you create a CryptoStream that reads bytes from this array, transforms them, and then writes encrypted data to a stream.

Then you can use ToArray() method of the stream to obtain encrypted bytes.

And what do you do next?

You run something like:
  Encoding.Unicode.GetString(cipherBytes)

And you have a problem. The encrypted string is encoded in Unicode. That's fine as long as you want to write it into a file or store in a database, but sometimes you want to be able to enter it using the keyboard.

To solve this problem use:
  Convert.ToBase64String(cipherBytes)

This way the encrypted string will be encoded with ASCII characters only.

If you want to know more, read this article.