#Google Analytic Tracker

Pages

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

Oct 25, 2013

Setting up TFPT Search

The TFS Power Tool comes with a very useful changeset search tool. This tool is not in Visual Studio 2012, maybe it will be in Visual Studio 2013 or in the feature.




Since every time when I install a new OS, I forget how to set one up. So here is how to do it.

  1. On the desktop, create a shortcut.
  2. Browse for the following exe:
  3. "C:\Program Files (x86)\Microsoft Team Foundation Server 2012 Power Tools\TFPT.EXE" searchcs"
    1. Target field "C:\Program Files (x86)\Microsoft Team Foundation Server 2012 Power Tools\TFPT.EXE" searchcs"
    2. Start in: "C:\Program Files (x86)\Microsoft Team Foundation Server 2012 Power Tools"
  4. Make sure the following path is in your System Environment Variable Path:
    "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE"
  5. Note: Make sure your Server Name has NO SPACE, use %20 for space, this throw me off many times because the search tool will able to find the changeset, but when you try to open the changeset details, it won't show anything. Most like because when it invoke tf.exe, it doesn't warp the server name argument parameter with quotations.

Download TFS Power Tools from Official Microsoft Download Center

Aug 30, 2011

Compiling C++ project using Visual Studio 2010 with .NET 4.0 from Visual Studio 2008 (MSB8009)

I know there are many posts on the internet for this solution. I like to blog about this so that next time when I have to update another C++ project file, I would remember I can reference my own blog post. Please note that I am not familiar with C++, but hopefully this information would help others.

Problem: When you try compile a C++ project that was created in VS 2008 using VS 2010, you get the following error:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(292,5): error MSB8009: .NET Framework 2.0/3.0/3.5 target the v90 platform toolset. Please make sure that Visual Studio 2008 is installed on the machine. [C:\dev\YourCPPProject.vcxproj]

It turns out that there are two places you have to change.

  1. Update the platform toolset from v90 to v100
  2. Update the target framework from v3.5 to to v4.0

Updating the platform toolset can be done in Visual Studio 2010.

  1. Right click on your C++ project (vcxproj) in Solution Explorer
  2. Select Properties
  3. Under “Configuration Properties” node, select “General”.
  4. You should see a property section call “Platform Toolset”, change it to v100.

image

Here is the part that I don’t understand why VS 2010 doesn’t have or implement such feature: How to change the target framework? Guess what, you have to do it manually.

  1. To update from .NET 3.5 to 4.0:
  2. manually open the .vcxproj file in Notepad (or I use Notepad++)
  3. Look for the xml tag <TargetFrameworkVersion>
  4. Update it to v4.0

By the way, you could also change the PlatformToolset manually too.

Once Visual Studio reload the project, your C++ should now be compiled using .NET 4.0 with the proper toolset.

May 28, 2010

My 1st Code Rush Experience – Can I Code Without ReSharper?

I have been a big fan of ReSharper (R#). I started using R# probably about four years ago.  Back then, this tool was magical to me, I didn’t know why MS VS wouldn’t have R# features.

C# 4.0 and Visual Studio 10 are already out.  I notice Code Rush (CR) is gaining popularity.  I tried CR probably about 3 years ago, but I felt CR wasn’t the right tool for me, especially I was heavily relaying on R# code analysis refactoring features. CR may had some code analysis and refactoring tool back then, but I can’t seem to remember much.

About a couple month ago, one of my colleagues came back from the MIX10 and he was impressed by Devexpress demo. He actually got one free license for CR + Refactor Pro. Since I was not in MIX10, I can’t say much about the demo. From words I heard, some guy code a lot faster when using CR while another guy still haven’t finish playing his guitar.  My colleague would like me to try out CR + Refactor Pro.

I was still using R# 4.5, and 5.0 is out. It is about time to see if I should upgrade to 5.0, or try a new tool.  My development team has finished the development phrase, and has moved into the QA phrase. Ideally in this period, we no longer code any new functionalities, other than testing and fixing issues. I think this would be a good time to try a new code aiding tool like CR.

Btw, we try to be as agile as possible. We tested new features in each iteration.  However, our QA team still have to do many regression tests because we don’t have enough automation tests. The QA team is very good at finding issue where developers didn’t thought about. As a result we still have a QA phrase.

What I Want to Talk About

Please assure that I am NOT suggesting either one of the tools (CR or R#) is better than the other. I believe CR and R# have their strong and weakness.  What I like to talk about is my experience of switching from R# to CR.

Why Trying CR

As I said before, I have been a big fan of ReSharper. However, using ReSharper comes in a price.  Here are the issues that I have using R#

  • Averagely I has to restart VS once a day due to OutOfMemoryException
  • R# slows down VS when it tries to analysis large classes

Basically these are the only issues I have with R#. Please don’t get me wrong here, R# is an awesome tool. However it needs a lot of resources to do the code analysis so that you don’t have to keep recompiling to discover your mistake. Unless you are a programming god, who make no mistaking in coding, otherwise you would find R# save you time from recompiling.

I was actually hoping that CR + Refactor Pro would somewhat provide me similar features that I use in R#, and it would also speed up my Visual Studio.

About 3 years ago, my development team were using VS 2005 coding with C# 2.0.  I tried to convince my team member to use R#.  The result… I failed miserably.  R# was very slow. Even now I still try to get my team to use R#, but they refused to use it because they worry it will destabilize VS. This is the same for CR.

Also, I won’t dare to install both CR and C# together. It would be nice to have the best from both products.  However, the last thing I want is a messed up IDE with shortcut key clashing. 

Installing Code Rush

The first time I downloaded the DXperience Product installer, I was confused at first of what I needed to download. I want to download CR with Refactor Pro, but instead, I downloaded the DXperience Product installer, which actually includes all the DX product. I think this is a very nice integrated products installation setup.

Before I start installing, I shut down VS, just like installing R#. Unfortunately the first thing I saw is the following:

1

Not sure why it complains why MS Visual Studio .NET is still running. I checked the Task Manager and found nothing running that may be related to VS (devenv.exe).  I wasn’t too impress. So I had to  log out and log in into Windows. That seems to fixed the issue.

During the installation, I like how it takes ask for your experience level. I saw a number of posts complaining R# has too much dialogue boxes when performing refactoring. I think R# should have a similar feature, that allow beginner to learn the tool though dialogue boxes, and no dialogue boxes display for expert users.

 2

First Thing I See in CR

Great, the installation was successful, let see how this work. What is this red line on the left of my code?

3At first, I wasn’t too sure the meaning of this, but soon I realized it means there are errors in the code. It was confusing because I can’t understand why the entire piece of code are errors.  My solution compiles. I wasn’t too impress about seeing the red line.

In the above example, It is nice that it point out the “issue”, but I don’t really understand what it means by “Complex member”. I think it needs to have a link for me to learn more about what it means.

Incorrect Analysis?

I started getting more confused because CR can’t seem to analysis the solution I was working with.  For example, why would Data.EmployeeName is an Undeclared element in the following screenshot? One possible reason I guess is that CR failed to analysis this data class. This class is a code generated ADO dataset definition. The generated definition is huge, more than 100,000 line of code, I think. From a design perspective, I want to get rid of this class and try other technology like the Entity Framework, but it is too hard to get rid of legacy code!

Anyways, I was disappointed that CR not able to analysis this class properly, but I understand if CR need to analysis this class, it will slow down VS. However, seeing the error indicators on your code while there isn’t any errors really bugs me. That makes the analysis useless because I can’t really tell what is working and what isn’t working. I would rather not see any code analysis.

Btw, R# usually takes about 3 minutes to analysis this data class (if I accidentally navigated to class designer file). So, better remember to add exception file to R# option so that it won’t do code analysis.  Also, if I keep the designer file open for too long, I may run into OutofMemoryException. However, the bottom line is that R# has no problem of analysis the designer code or code that uses the class.

4

Another thing that I didn’t like to see is the following “Member is not implemented” warning. It is true that I didn’t implement anything in this method. However, I have to implement this because the class implemented an interface that requires the following method. I wonder if there an option I can mute this warning.

9 - Cant check the interface

Undisposed Variable Detection

CR can detect if I remember to dispose a IDisposable object. I think R# should have this feature. Good job to CR.

5 - Disposable check

No Linq or Extension Method Supports

It starts hurting my eyes when CR keeps giving me incorrect analysis. Linq and extension method is out for quiet some time, so I was disappointed of not seeing the correct analysis.

11 - Linq not supported

Testing Tools

One of the most use features in R# is the testing tool.  I can’t live without an integrated testing tool in a test-driven development.  With R# 4.5, it even supports native NUnit framework, which I greatly embraced.  In the older version, some of my NUnit doesn’t work because I was using new NUnit feature that R# doesn’t support. With R#, I don’t even need to install TestDriven.

I was also hoping CR would have something similar. Unfortunately I wasn’t too impress when some of the working tests failed to run correctly. Also, why CR would have the “Run test(s)” option when I right click on a private method. The code wasn’t even in a test suite. That’s confusing.

6 - Incorrect Test detection

Alt + F12 Reference Search

Another set of features that I used a lot in R# is search and navigation tool. I know that CR may not be as powerful as R#. When I tried to use the normal Alt + F12 reference search feature, CR failed to find reference call by interface.  Maybe there is an option to turn on search by interface, but I couldn’t find one.

Also, the CR search result does not look appearing with my IDE color schema (screenshot bolow). Maybe that’s why R# would rather has its own search result tab, instead of integrating the IDE color schema in the search result.

7 - busy screen and find all reference is werid

I have to admit that I am so used R# navigation and search tools that I will have to find an exact replace before I can give up on R#. Being an expert user in one tool makes it a lot harder to switch to another tool.

One thing that I find annoying is CR can’t find interface reference call. In R# it can do searches on both search using interface or concert reference call.

Learning from Shortcuts

So, one way to learn how to use a new tool is from reading it shortcut. Like R#, so I printed out an CR shortcuts reference and sticks it on my wall. Of course the list of shortcuts can only help me so much, so I tried to discover new feature from the option menu. Whoa…

8 - complicated screen

I didn’t realized you can customize how your shortcut key can execute. You can decide how an shortcut work if your cursor is at the beginning of a word, in the middle, after and many more.

I am guessing this is for the advance users. You can customize the way that you want your IDE to work. However, I have to debate that is this feature best for the users. I think having this many options can be overwhelming, and it is too powerful. It may cause key clashing with other VS shortcuts. If you didn’t backup your sophisticated shortcut settings and lose it, you can get very upset.

Refactoring

One of the big selling feature of CR + Refactor Pro is that it has many refactoring tools you can use.  From what I heard, you can do a lot more refactoring using CR then R#. However, since I only do C# development, I can’t see much benefit for me, like refactoring HTML.

Another thing I find that weird is the following: Can you consider “line-up parameters” refactoring? I would have considered this is a matter of code formatting. I use R# code reformatting tool a lot.

10 - Formatting vs Refactoring

CR also has code clean extension. One thing I heard a lot from CR fan is the power of the DXperience extension framework.  It has a strong community and it provides many free extension. However, I haven’t realized this power during my CR experience.

Conclusion

So, for the CR fans who happen to be reading this post, you may notice that I have been complain CR and rarely talk about CR advantage.  In the beginning of this post I have mentioned that I am not here to say which product is better or not. I merely want to share my experience. 

I believe CR has many good features for developers. At from what I read online, if you can master CR, you can be a very fast coder. 

For me, I don’t need to be a faster coder, but I do good code analysis tool. R# code analysis, search and navigations feature helps me a lot. In the end, you need to pick the right tool that suit your need.

It may also be a bad time for me to try CR since I was in the QA phrase. It may have been better if I use CR for new development, then I may see more benefits in CR. I have only tried CR for 3 days. So I can’t really do feature by feature comparisons.

The only reason that I was considering switching from the beginning was because of R# performance.  The good news is that these frequent OutOfMemoryException that I got from R# has NOT been crashing the entire VS since version 4.5. I can live with it. Resharper exception can be reported back to JetBrains. That’s pretty cool.

image

As a result, I stick with R# for now.

Mar 13, 2009

The Data Binding, the Invoke, and the Deadlock

When it comes to Windows Application programming, there are a number of things to be considered.

  1. Data Binding – the ability for the windows control to automatically refresh its UI when the underlying data changes. This feature saves developer’s time from writing code to update the UI when the underlying data change.
  2. UI Thread Invoke – When an UI needs to be updated, the updating code has be execute by original thread that create the UI (i.e. UI Thread, or usually the Main Thread). For example:
private void OnDataRowChanged(DataRow oDataRow)
{
if (this.InvokeRequired)
{
this.Invoke(new OnDRChangedDelegate(OnDataRowChanged), oDataRow);
return;
}

//Do Your UI Update ...
}
  1. Deadlock – In a multiple threaded application, when thread A waiting to acquire a resource and never able to get it because thread B is holding this resource, while it is waiting for thread A to release its resource. You will end up having two threads waiting and your program hangs. This can happens for more than two threads locking each other resources.


    image

 

The Problem

In a multi-threaded application, there are many threads interacting with the application data. In my case, it is a DataSet. A DataSet is an ADO.NET (old) technology that acts like a in memory database. It contains tables, columns, constraints, relationships and etc. To ensure the program is thread safe, we have to lock the DataSet before modifying the data using the lock keyword in C#.

This all sounds good until we start doing data blinding. In my case, I have a number of grids (Infragistic UltraGrid) blinded to the DataSet. In the beginning, everything look great. Data are loaded by thread to the data model and grids automatically updated.

Here is the model that causes problem:

image

Each time when our server updates a piece of data to a client DateSet, it creates a .NET remoting thread (represent by the green), and update the DataSet. To ensure we are thread safe when updating the DataSet, we have a lock to prevent more than one thread updating (writing) the DataSet.

Unfortunately during QA, we occasionally see the UltraGrid display a big red X. The entire gird basically crashes and it no longer able to display data.  The exceptions we got includes NullReferenceException, IndexOutOfRangeException and etc.  Initially, we thought that was a Infragistic bug in the UltraGrid, but in the end, we realized it is another type of Cross Thread operation. For example: InvalidOperationException was unhandled (Cross-thread operation not valid: Control ‘XXX’ accessed from a thread other than the thread it was created on.)

To prevent cross thread operations, we decided to ensure we called the ISynchronizeInvoke.IsInvokeRequired when we updates the DataSet.

Revised model (Deadlock on Invoke and Lock DataSet):

image

For the first couple of runs, the application seems to be executing correctly using the revised model. However, we got the application to hang.

From the diagram, it is probably obvious  that there is a deadlock from the pictures. However, it isn’t obvious when the order of locking and invoking calls are in different modules.  Because we didn’t standardize how we should do Invoke call and lock the data set first, we end up having random deadlocks on the Invoke call, and at the lock statement block.

Where is the dead lock?

In case the diagram is not obvious to some of the readers, here is what happening. Assuming you have an UI Controls created by only one thread, called the UI Thread (Main Thread), when Thread 1 called ISynchronizeInvoke.Invoke(), the UI Thread is locked to execute the Thread 1 request. At the same time, Thread 2 has locked the DataSet which prevents other threads updating it. When the Main Thread try to lock DataSet, it has to wait for Thread 2 to exit the lock block. At the same time, Thread 2 is waiting for the UI Thread to complete so that it can do the Invoke(). Since 2 threads are waiting for each other resources, we have a dead lock.

Solving The Problem

This model may not be the best solution, but it is simple to understand and it works:

image

In this model, all I did is to ensure all threads call Invoke() before locking the DataSet.

This design ensures we only have one thread access to the Lock. In our case it is the UI Thread. Whenever called the Invoke() on a Windows Form, your execution is passed to the UI Thread.

Now, you may wonder, why do I still need to lock the DataSet when there the Invoke there there.  From this simplistic diagram, we don’t.

But, you may have N number of Threads that didn’t call the Invoke for whatever the reason. An application can be complicated. To be safe, always lock the DataSet before applying changes.

 

 

 

 

 

How to Find a Deadlock?

You probably don’t want to ship a software that hangs in front of your customs, so you want to find these deadlocks before your customers find them for you.  Well, there is no easy way to determine where are the deadlocks in your application. Here is a couple of suggestions that may help:

  • Peer Code Review – have someone double check your check before check in the code. Check for possible deadlock by examining where lock, monitor class, invoke class are used.
  • Use a Deadlock Monitor – using a custom locking mechanism to determine if there is a possible dead lock.
  • Have a lot of tests – this can be unit tests, integration tests and your manually user tests. Whenever you see the application stop responding, report it and try to solve it.

Find Your Dead Lock using VS.

If you do find your application stops responding, what can you do? First, determine if your application is actually “working” by checking its CPU usage. If it is around 100% for one of your core, your application may be working hard or got simply running an infinite loop. This is NOT a deadlock!

In this case, your best tool would be using Visual Studio! Assuming you have all the debug files (.pdb) and source code for your program:

  1. Debug->Attach To Process, and attach to your non-responding application.
  2. Click on the pause button or Debug->Break All to stop the application
  3. Debug->Windows->Threads

A deadlock usually happen between two threads that hold on two resources, so you need to check where your executing threads has stopped. In the following example, I have a number of threads running, but I am only concerning my owns. These are the last two items in the Threads grid below.

image

  1. Double click on the Main Thread and the Worker Thread to see their executing locations.

For example:

image Main Thread executing location

  1. Notice the “green” highlight represent were is your thread executing.
  2. If you hit F5 (run) to un-pause the thread, and hit pause again, your thread execute would most likely remind at the same place.

image Worker Thread executing location

So, at least we know these two threads are trying to get some resources. However, how can you tell if they are holding each other requesting resources?

In this example, we know that the Main Thread waiting, so the Worker Thread have to wait at the “this.Invoke()” line. However, how do you know if the Worker Thread lock the m_oDataModel?

The only way to find out is to trace the executing code through the call stack. (If someone have a better way to find a dead without going though the code, please let me know!!!)

  1. Double click on the Work Thread
  2. Debug->Windows-> Call Stack

image

By tracing through the stack, I soon discover that the one of the call stack got a lock on m_oDataModel. Luckily in my case, I only have 2 visible stacks for this thread. If you have more, you will have to walk though them.

image

Ah, from the above, I see that I called lock(m_oDataModel), follow by calling the AddDataWorker() method.

Once you find out there is a dead lock, you will have to resolve it. Either by fixing the order of the locks or provide a better architecture that prevent developers run into this situation.

Sample Deadlock Code

Sorry that I don’t have a web space to store code file. I can only post the source code as it is. In this example, I have a form that has one button. If you click on the button, a dead lock will occur.

public partial class Form1 : Form
{
private DataSet m_oDataModel = new DataSet();
public Form1()
{
InitializeComponent();
m_oDataModel.Tables.Add("MyTable");
m_oDataModel.Tables["MyTable"].Columns.Add("SomeKey");
m_oDataModel.Tables["MyTable"].Columns.Add("ItemName");
}

private void button1_Click(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(AddData));

//Similate doing something
Thread.Sleep(1000);

lock(m_oDataModel) //Wait for lock forever (deadlock)
{
m_oDataModel.Tables["MyTable"].
Rows.Add(Guid.NewGuid(), "Some Data");
}
}

private void AddData(object oState)
{
lock(m_oDataModel)
{
AddDataWorker();
}
}

private void AddDataWorker()
{
if (this.InvokeRequired)
{
//Wait for Main Thread to be free forever (deadlock)
this.Invoke(new Action(AddDataWorker));
return;
}

//Update a textbox
this.textBox1.Text = m_oDataModel.Tables["MyTable"].
Rows[0]["ItemName"].ToString();
}
}

Conclusion

As you get more experience and understand the structure of your application, the easier it will be for you to identify a deadlock. Deadlock isn’t just cause by the “lock” keyword in C#. It can be an Invoke() call, a read/write lock on a file, an database transaction lock and etc.  For those who read though the article to this end, thanks for reading and I hope this post helps you solving your deadlock issue.

Dec 12, 2008

C# Casting using Extension Method and VS2008 Debugger Issue

 

Since the creation of extension method in C# 3.0, my college and I have been happily writing extension methods which make our code look a lot nicer.

Then, I was surprised by my college when he took leverage of this by create an extension method for casting. Why not using the normal C# casting syntax?

   1:  public static TTargetType To<TTargetType>(this object oObject)
   2:  {
   3:      return (TTargetType)oObject;
   4:  }

Initially, I didn't like this idea too much, because it does have disadvantages when using a method to do casting:

The advantage of this method is that it makes typecasts way cleaner. The disadvantages are that you'll have to go one level down the stack trace to debug properly, and some erroneous casts might not get caught by the compiler.

However, after using the extension method for cast a couple of times, I really like use it. It does make the code a lot cleaner to read. In fact, whenever I notice my assignment is incorrect as I type, I can immediately hit the dot key to casting instead of moving my cursor back to the being of variable and type out the C# cast syntax:

   1:  private bool ApplyUnsplitWorkWorker(object[] oArgs)
   2:  {
   3:        sch_WorkData oUnsplitWork = oArgs[0].To<sch_WorkData>();
   4:        sch_WorkItemData[] aUnsplitWorkItems = oArgs[1].To<sch_WorkItemData[]>();
   5:        sch_WorkItemData oDeletedWorkItem = oArgs[2].To<sch_WorkItemData>();
   6:        sch_WorkData oDeletedWork = oArgs[3].To<sch_WorkData>();
   7:   
   8:  //...
   9:  }

Check out the bottom two examples , see which one you like more:

private string SomeMethod(DataRow oRow)
{
    //Extension cast
    return oRow.To<EmployeeRow>().Department.To<MathDepartment>().MathRoomCount.ToString();
}

private string SomeMethod2(DataRow oRow)
{
    //C# Cast
    return ((MathDepartment)((EmployeeRow)oRow).Department)).MathRoomCount.ToString();
}

In addition, there is as a extension method for casting that return a null if object is null or default value (such as DateTime), and an extension method for "as" syntax.

Yesterday, I encountered an exception when I was running a project. When I try to debug the issue, to my surprise one of the objects can't be analysis by the debugger, neither can it be display in the Watch Windows or the Immediate Windows. For testing, I create an extra variable call "l_oWorkItemRow2" using .C# casting, so that I can compare with "l_oWorkItemRow1"

Before:

 

Once I continue hit next line in the debugger, a null reference exception occurs:

What's going on? Why am seeing the variable properties saying "threw an exception of type 'System.NullReferenceException'"...

In fact, occasionally the debugger failed to analysis the property value in certain stack. If I move the debugger back to one stack where I pass the value, that I could than see the value.

The question is why the debugger was able to analysis the regular casting, and not the extension method cast. Is it just a current limitation to the debugger, or it is actually a bug? For example, do you know that only certain cases you can do "Edit and Continue" in the debugger.

Anyhow, if I find out more about this strange behaviour, I will definitely write another post!

May 8, 2008

No files were found to look in. use Ctrl+Scroll Lock!

 

Credit goes to: http://blogs.ugidotnet.org/franny/archive/2005/12/08/31303.aspx

Today, one of my colleges ran into a problem. He click on "Ctrl + Shift + F" to open the Find and Replace dialogue, and he tried to find a string in his solution.

image 

The text that he wants to search is right in front of his eyes, yet clicking on the Find All button only returns: "No files were found to look in.Find was stopped in progress."

He thought that he must be tired today.  Double check his spelling, his cap lock, and all other options. There it goes his 1/2 hr of work.  So, he came over to me to make sure that ensure that he is not hallucinating.  I said no, surely something is wrong with VS.

Another one of my colleges overheard our conversation, and said, "Try Ctrl + Scroll Lock".  WT..., how does Ctrl + Scroll Lock helps to solve this issue? Surprisingly, it worked!

The annoying part is that there is no explanation on how you get into to this state and how to fix it.  Obviously, no one will spend time continue investigate into this, because your main job is to develop your product and not debugging your development tools.

I suspect this maybe due some incorrect interaction between Visual Studio and the OS layer. The Scroll Lock button is rarely being used in modern software. In the past, when people still uses text-based UI, this button is used to make the arrow key to scroll the contents of the text window instead of moving the cursor.

Mar 16, 2008

Visual Studio Installation Strange Disk Space Requirement

Recently I attended "Hero Happen Here" event in Calgary, and obtained a copy of Visual Studio 2008 Standard Edition.  Similar to the Visual Studio 2005 lunch event, everyone get a copy of Visual Studio Standard edition. But since this is my first time attending such event, I was pretty excited that I got my own Visual Studio 2008.

After I got back home, I immediately uninstall my Visual Studio 2008 beta version.

Surprisingly, the first error that I encountered is not during VS installation (although I usually have faith that VS will install properly), but rather when I uninstall the beta.

"no disk Exception Processing Message c0000013 Parameters ...."

By doing a quick google search, I found this forum.  I recalled that I installed the beta from a external hard drive. I must have removed the VS 2008 installation file or changed the drive letter. My quick fix was to unplug my external hard drive, and uninstall the beta. But really, a software shouldn't need to check for disk during un-installation.

Anyhow, here is what strange about my VS 2008 installation experience. Notice my installation path is on C drive, but the Disk space requirements show that I need 204 MB on my E drive.

Strange VS Installation with Hightlight

My E drive only stores my media files like music. I never use this drive for program installation of virtual memory mapping.

After I installation, I checked my E drive and it doesn't seem to have any extra file installed. It would make more sense if it is D drive because this is where I store my user profile!

Jan 20, 2008

Bad Error Message : System.IO.Filenotfoundexception in Visual Studio 2005 Designer

 

Have you ever use Visual Studio Form or User Control designer?

Have you ever run into construction error where the designer can't display your form?

Well, if you use Visual Studio, you would most likely have encounter error displaying your form if you:
A. manually manipulate the designer file (i.e. myForm.designer.cs)
B. you add runtime code to the form/user control's constructor causing your designer not to load.

Today, as I was working on my project, I don't know what I did to the code, but when I open my main form on the designer, Visual Studio crashed, and I got the following error:

image

At first, I thought it is something to do with the ActiveX control that I was referencing. I unregistered it and re-register it. No help at all. After I start playing around with my code by recreating my project, I found out what I did wrong.

It turns out that I add a System.Threading.Timer object to one of my user control's constructor. For example:

public partial MyUserControl : UserControl
{
//....
System.Threading.Timer myTimer = new Timer(DoSomeWork, null, 0, 180000);
//....
}

Since the user control is in any project, VS didn't crash until I rebuild the project and I reopen my main form that contains this user control. The confusing part is that instead of seeing error like the following, VS crashed and ask me to restart.

image

Hopefully the designer in Visual Studio 2008 will improve error handling and not crashing Visual Studio.

May 30, 2007

InternalsVisibleTo and Strong-Name signed assemblies

 

By now I am guessing only newbie like me would encounter this issue.  Today I was working on my project for my friend. Basically I am writing some kind of user name checking tool that can be call externally by a unmanaged program.  So, I figured that I need to expose my assembly as a COM object. I haven't test out my class yet, but hopefully it works.

Based on the article from my favorite CodeProject website:

Calling Managed .NET C# COM Objects from Unmanaged C++ Code

I need to accomplish 3 things

My class must be implement a specific interface

Both the interface and the class must have a GUID attribute to identify themselves

The assembly must be a strong-name type. (This is the part I am not sure why it has to be a strong-name type, but I am guessing it is because the writer decided to add the assembly to the GAC in his example from the article)

So, to ensure that I have a strong-name type, I followed the article procedure to create a snk (Strong Name Key) file.

Using Visual Studio 2005 Command Prompt,

> sn -k TestKeyPair.snk

The article suggested to do add "[assembly: AssemblyKeyFile("TestKeyPair.snk")]". After trying it, VS2005 warned me that I should added the snk file thought the Project->Properties->Signing tab, which I did

Now, here comes the tricky part, I have a UnitTests that test my internal method of my class.

SO, LET COMPILED

Error: Friends assembly must be strong-named signed (some error like that)

Ok, so it looks like I need to make sure that my UnitTests assembly need to be strong named too. So, I created another snk file call UnitTestsKey.snk, and added this file to my UnitTest project

Try again

   1:  
   2: [assembly: InternalsVisibleTo("UnitTests"]
   3:  
   4: // Compiling Error
   5: // Error 1 Friend assembly reference 'UnitTests' is invalid. 
   6: // Strong-name signed assemblies must specify a public key in 
   7: // their InternalsVisibleTo declarations.

What the heck is this "Public Key" I am missing? After hitting the F1 (for help, really I used F1 for help). Once again, MSDN helps doesn't explain much, especially for newbie like me. Let's GOOGLE it.

Ok, somehow I need to retrieve the public key from either the compiled DLL, or from the snk file.

This blog explains what I need to do, but it missing explain one important thing!

Which DLL's or SNK public key I need? My class, or my UnitTest class? It is important to know because I was confused on how this strong name type work.

After trials and errors, obvious it is the UnitTests's public key that I want.  The idea is that since my UnitTest is strong named and it is encrypted with this special snk file, to allow My Class shares its internal method, it needs to know the UnitTests assembly's public key.

Following the blog's explanation, I obtained the public key though the UnitTests.snk file. I can't get public key from the UnitTest assembly because it didn't compiled.

3rd Try

   1: [assembly: InternalsVisibleTo("UnitTests, PublicKeyToken=8c40a2440ba23747")]
   2:  
   3: // Compiling Error
   4: // Error 1 Friend assembly reference 'UnitTests, PublicKeyToken=8c40a2440ba23747' 
   5: // is invalid. Strong-name signed assemblies must specify a public key in their 
   6: // InternalsVisibleTo declarations.
   7:  

WTF? Let's Google it again.... hmmm... interesting some site is using PublicKeyToken, but some other doesn't, it uses PublicKey in the parameter string. Let use PublicKey

4th Try

   1: [assembly: InternalsVisibleTo("UnitTests, PublicKey=8c40a2440ba23747")]
   2:  
   3: // No compiling Error
   4: // but with Warning
   5: // Warning 1 Assembly reference 'UnitTests, PublicKey=8c40a2440ba23747' 
   6: // is invalid and cannot be resolved

Well, better, but when I compile my UnitTests project, it still failed. My UnitTests doesn't see the internal method of my Class....must be something do with the warning.

Finally, after reading more from an webpage (which unfortunately the webpage link is no longer working), it turns out that in Visual Studio 2005, you need to get the hex value for your public key.

5th Try

   1: [assembly: InternalsVisibleTo("LicenseKeyGeneratorExtendedTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000735a079d1bc7b8ea2b3e6706544e7396e4f3110b49c6529361d83ed66111c2fa4b38bbfb3d074d8ce76ed0a2813a2b9901ae0a88b79c85712e3ec4852fef4435426269f1009e2d79dc90644db171ec0566919f4945b06bce3603cc7af098d2774ec80b79bd182d4394bf75f775d0fecbf1b4ecb21a53aa6b0d9e218a1c223d0")]
   2:  
   3: // No Errors or Warnning

Finally, my solution compiled!

-------------------------------------

Update - Feb 11, 2009

If you still having trouble of making an assembly visible to another, check if you have the following line in your assembly.cs file and remove them:

[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

Recently I tried to expose internal methods in a project to a unit test project.  My solution wouldn't compile, and after checking the assembly.cs in the project, I found these two line. Initially I thought it doesn't really do anything, but after I removed it, the solution compiled. I don't know why it was there in the beginning, but in any case, it works now.

Update – Mar 11, 2009

Some of the references were broken and they are now fixed.

Other References

Strong Names Explained

May 8, 2007

Goodbye ReSharper (at least for now)

 

ReSharper is a very intelligent tool and I like it a lot. It helps me analyze unfamiliar code much easier.

Unfortunately its performance slows down a lot when your project that has large data model and other code generated classes.

I have classes that contain more than 10,000 LOC due to code generation. Even a 4000 LOC file takes a while for ReSharper to parse on my machine, which only has 1GB of ram.

In my case, ReSharper is a memory hog. I often have to check my memory usage so that I know when it is a good time to restart VS2005. Restarting VS2005 is no fun at all. It takes time to shutdown and load the solution.

For some reason, ReSharper memory usage keep increasing as time pass. I am not sure if there is a bug, memory leak, or it caches all the parsed data.

I see the memory of devenv.exe Mem Usage goes as high as 700MB and 1500MB VM size. Page Fault is so high that my computer basically is thrashing.

The memory issue is a big issue since the first time I used ReSharper 2.0 in another company. However, because the project I worked on doesn't involve much code generation, ReSharper performance is fairly alright. Even so, I occasionally unload ReSharper (though registry importing), so that I can quickly open up a solution and inspect the code.

My colleague suggested if ReSharper has a button to stop code analyzing, or skip parsing certain classes for increase in performance, he would like to install ReSharper again. I just hope that next release of ReSharper would have a better perform.