I previously posted about using the InternalsVisibleTo attibute for testing with NUnit.
I've had some problems building this with a stronly named assembly. I found the following post on Kent Boogaart's blog that describes how you should change the code in your assemblyinfo.cs file as follows:
[assembly: InternalsVisibleTo("Company")]
to
[assembly: InternalsVisibleTo("Company, PublicKey=xxxxxxxxxxxxxxxx")]
Richard Jonas's blog about .NET, web development and agile methodologies.
Tuesday, June 12
Adding a strong name to a third party dll
I've been trying to build an assembly with a strong name and had some problems as it referenced a 3rd party assembly which had been built without a strong name.
To add a strong name I disassembled and reassembled the 3rd party assmbly as follows:
ildasm /out:thirdparty.dll.il thirdparty.dll
ilasm /dll /resource=thirdparty.dll.res thirdparty.dll.il /out=thirdparty.dll /key=mykey.snk
To add a strong name I disassembled and reassembled the 3rd party assmbly as follows:
ildasm /out:thirdparty.dll.il thirdparty.dll
ilasm /dll /resource=thirdparty.dll.res thirdparty.dll.il /out=thirdparty.dll /key=mykey.snk
Tuesday, June 5
World Environment Day
To celebrate World Environment Day, we have all been given a flowerpot, some peat and some forget-me-not seeds. You can follow whether the seeds grow into a beautiful plant or not here.
Refreshing Progress Bars
I've been having some problems getting a progress bar to refresh, trying various calls to Refresh() and Invalidate() without much success. The solution to this is to create the dialog containing the progress bar in another thread, as described here.
Although the dialog is modeless, it should be displayed using ShowDialog(), not Show().
Although the dialog is modeless, it should be displayed using ShowDialog(), not Show().
Wednesday, May 16
Standard for improving Standards
Simon Baker suggests that standardisation does not have to supress innovation.
It's important to communicate the best ways of doing things, but standards are often enforced in a way that people are expected to accept without question. However, there are often many ways of doing something, and the best way will change over time with changes in technology and changes in people.
Perhaps standards should be seen as something that should be followed, but when its thought they cause a problem, judgement should be used as to the correct procedure should be followed. However, if people use judgement to deviate from the standard, any differences should be noted and their effect should be considered afterwards.
The differences can then be assessed to see if deviating from the standard was the right thing with hindsight and if so, the standard should be improved. if it was the wrong thing to do, we might need to explain the rationale behind the standard better.
It's important to communicate the best ways of doing things, but standards are often enforced in a way that people are expected to accept without question. However, there are often many ways of doing something, and the best way will change over time with changes in technology and changes in people.
Perhaps standards should be seen as something that should be followed, but when its thought they cause a problem, judgement should be used as to the correct procedure should be followed. However, if people use judgement to deviate from the standard, any differences should be noted and their effect should be considered afterwards.
The differences can then be assessed to see if deviating from the standard was the right thing with hindsight and if so, the standard should be improved. if it was the wrong thing to do, we might need to explain the rationale behind the standard better.
Monday, April 16
Visual Studio 2005 - Disappearing controls on Windows Form
My computer crashed the other day and when I returned to edit my application, to my horror I noticed that the controls on a very complicated windows form that I was working on had vanished. When I tried to edit it, all I got was an empty dialog box, but all the source code for my form was still there.
I found several references to disappearing controls in VS2003, but they all said the problem had been fixed in VS2005.
The cause of this turned out to be that some lines had removed themselves from the designer.cs file :-
Copying these lines from the version in source control seemed to restore all the controls in the dialog.
I found several references to disappearing controls in VS2003, but they all said the problem had been fixed in VS2005.
The cause of this turned out to be that some lines had removed themselves from the designer.cs file :-
///
/// formMyForm
///
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ClientSize = new System.Drawing.Size(869, 717);
this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAccept);
this.Name = "formMyForm";
this.Text = "My form title";
Copying these lines from the version in source control seemed to restore all the controls in the dialog.
Thursday, March 1
Complete years between 2 dates
A problem we have had calculating ages was due to it using the SQL Server "DateDiff" function. This counts the number of times a day crosses a boundary, e.g.
DateDiff(year,'12/31/2006','1/1/2007') is 1, as it crosses the 2006-2007 boundary.
DateDiff(year,'1/1/2006','12/31/2006') is 0 as it doesn't cross a year boundary.
I have written a function "yeardiff", which calculates the number of complete years between 2 dates, so
YearDiff('12/31/2006','1/1/2007') is 0
YearDiff('1/1/2006','12/31/2006') is 0
YearDiff('12/31/2006','1/1/2008') is 1
This function works by calculating the number of days the start date is into the year, subtracting this from both start and end dates (so the start date is 1 January), and calling DateDiff on the resulting date.
Here's the source code for this function:
DateDiff(year,'12/31/2006','1/1/2007') is 1, as it crosses the 2006-2007 boundary.
DateDiff(year,'1/1/2006','12/31/2006') is 0 as it doesn't cross a year boundary.
I have written a function "yeardiff", which calculates the number of complete years between 2 dates, so
YearDiff('12/31/2006','1/1/2007') is 0
YearDiff('1/1/2006','12/31/2006') is 0
YearDiff('12/31/2006','1/1/2008') is 1
This function works by calculating the number of days the start date is into the year, subtracting this from both start and end dates (so the start date is 1 January), and calling DateDiff on the resulting date.
Here's the source code for this function:
CREATE FUNCTION yeardiff
(@start as datetime, @end as datetime)
returns int
AS
BEGIN
declare @years as int
declare @daysintoyear as int
declare @firstdayofyear as datetime
declare @newstart as datetime
declare @newend as datetime
set @firstdayofyear = convert(datetime,
'1/1/'+convert(varchar,year(@start)))
set @daysintoyear =datediff(day, @start, @firstdayofyear)
set @newstart = dateadd(dd, @daysintoyear,@start)
set @newend = dateadd(dd, @daysintoyear,@end)
return datediff(year,@newstart,@newend)
END
Subscribe to:
Comments (Atom)