Do not pass data between static methods using static data members.

In one of static class in our application, I found local static members that were used to pass data between calls of static methods.
It’s wrong and can cause errors that are intermittent and very hard to reproduce.
The problem will happen if the same code executed for 2 users simultaneously. In this case value for one user could be used for the second user and result will be unpredictable.
 
The code was similar the following:
 
    public static class HelperClass
    {
       private static string _dataToPass = “”;
   static void Method1(string param)
{
_dataToPass =param;
}
   static void Method2()
      {
//logic based on _dataToPass value;
}
 }
The pattern is popular for instance object, when one method saves state in the instance, and other method use it, but it is not acceptable for static class.
Consider to use singleton pattern, if you have shared for the domain object.
The issue is well known(e.g. see Statics & Thread Safety: Part I   and Part 2 ), but I decided to write about it again.

Attempt to get Visio Class Diagrams from VS XSD files.

I wanted to have a diagram from .Net Dataset (stored as XSD) and include elements from XSD generated from WCF service.
I found that is not supported by MS tools. Dataset Designer doesn’t have any export facility.XSD files generated from WCF service, do not have any graphical interface at all.
I ended up with manually drawing in Visio objects used by WCF service and merge PrintScreens from VS Dataset Designer and Visio Class Diagram in Paint.Not a nice solution.
 I’ve posted a suggestion “Ability to export diagrams from XSD files.”. to MS.
 
Below are the links that I’ve read to find the solution.
From the thread “Import XSD to Visio?” :”The only way I know of is to write a little visio add-on using Visio SDK that reads the xsd and creates the corresponding Vision shapes”
Design and Generate Code with VisioVisio for Enterprise Architects
 
sparxsystems Enterprise Architect Modeling & Design Tools for your Enterprise -actually didn’t try.
 

Could not load type ‘System.ServiceModel.Configuration.BindingsSectionGroup’

After installing .Net 3.5 SP1 on the existing server, that runs .Net 2.0, I’ve got the exception: 

Source : mscorlib

Message : An error occurred creating the configuration section handler for system.serviceModel/bindings: Could not load type ‘System.ServiceModel.Configuration.BindingsSectionGroup’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

Filename : c:WINDOWSMicrosoft.NETFrameworkv2.0.50727Configmachine.config

Line : 100

Errors : System.Configuration.ConfigurationException[]

Stack Trace :

Server stack trace:

   at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)

   at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)

   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)

   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)

   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)

   at System.Web.Configuration.HttpConfigurationSystem.GetApplicationSection(String sectionName)

   at System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName)

   at System.Web.Configuration.WebConfigurationManager.GetSection(String sectionName)

   at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetSectionFromWebConfigurationManager(String sectionPath)

   at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetAssociatedSection(ContextInformation evalContext, String sectionPath)

   at System.ServiceModel.Configuration.ClientSection.UnsafeGetSection()

   at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard)

   at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)

   at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)

   at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)

   at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)

   at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()

   at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()

   at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)

   at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()

   at System.ServiceModel.ClientBase`1..ctor()

I’ve searched the Google and the post  http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/bde7c986-25c3-443b-9d8e-db8579ae1478 suggested to use ServiceModel Registration Tool (ServiceModelReg.exe)  .But it didn’t help.

 

With a hint from post Unrecognized configuration section system.serviceModel

I manually updated 2 lines in Machine.config (that probably were left from some previous beta installation) based on Machine.config from my development machine, that didn’t have the problem. 

      <!–<section name=”bindings” type=”System.ServiceModel.Configuration.BindingsSectionGroup, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″/>–>

      <section name=bindings type=System.ServiceModel.Configuration.BindingsSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089/>

<!–<section name=”extensions” type=”System.ServiceModel.Configuration.ServiceModelExtensionsSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″/>–>

<section name=extensions type=System.ServiceModel.Configuration.ExtensionsSection, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089/> 

And the errors disappeared.

SQl Server Management Studio doesn’t show new lines in records.

We are storing in the database plain text messages formatted with new lines.
When it was required to update the message, my colleague used  SQL Server Management Studio to retrieve text in Grid View.
The text was shown as one long string without any newline separators. She copied the text to editor, updated it and use SQL Update statement to save the text back to the database row.
The problem was that all  new line formatting was lost.
SQL Server Management Studio  didn’t indicate new lines and causes confusion to user.
I beleive that SQL Server 2000 enterprize manager showed multiple lines correctly
As a workaround(if user is aware of this behaviour) user can use “Output to Text”, because text output handles new lines correctly.
Note: if you are using “Output to Text”, don’t forget to change in Tools/Options/Query Results/SQL Server/Results to Text Maximum Length of the output to 8192  to avoid output truncations. 
 I’ve posted a suggestion “SQl Server Management Studio should show new lines in records“. to MS.
 
There are related active(!?) bugs since 17/04/2006 Data editor under “Open Table” does not properly support multi-line data and since 1/06/2005

Upgrade VS Web Site Project to be VS Web Application Project (WAP)

One of my colleagues wanted to upgrade VS 2005 Web Site Project to be VS 2005 Web Application Project.
Then we had an issue with non-compiling files from OLD_APP_CODE folder-they had Build Action as Content (see http://forums.asp.net/p/1065290/1743735.aspx#1743735)
 
And now I’ve read  Rick Strahl‘s post. VS 2008 doesn’t have conversion wizard at all. The process has become fully manual-but well described in Rick’s post From ASP Stock Projects to Web Application Projects in VS 2008

CSS TD element style overrides Table class style.

I’ve created the MyTableClass CSS class(stored in .CSS file)  and specified it to a HTML table.

.MyTableClass

{

font-size: 8pt;

}

 

However the size of font inside the table was bigger than I specified.

Thanks to VS 2008 CSS properties pane – Applied Rules section I was able to find that the rule was overridden by TD element style

TD

{

font-size: 12px;

}

 

It was not hard to create hack to override global TD.

.MyTableClass TD

{

font-size: 8pt;

}

 

I feel that having global element rule is not a good idea.

Unfortunately I am scared to change the style, because it is used in many places in production.

Update: I found very similar post Tackling Stubborn TD Style Definitions, written by Jovan.    

Related articles:

CSS Style Table – styling tables with only one class 

My post Adaping CSS and Javascript from Html Prototype. 

 

TFS Source Control Explorer -no commands shown

We needed to setup TFS for a new user and he had a problem:
When open TFS Source Control Explorer , he can see folders, but was unable to run any commands , e.g Get Latest.
Trying to find a reason, we gave the new user different security permissions, but it didn’t help.
Finally I suggested to check in VS Tools/Options/Source Control/Current Source Control Plug-in. and ensure that
VS TFS is specified.
It fixed the problem.