2006-09-27
Spring.Net Schema
2006-09-25
Mem Usage vs VM Size
Design Time Master Page
GC.Collect not the solution
Many times i have come to situations where the memory usage in my program spirals out of control. Always i think it is a problem with anything but my program. I test the cleanups of the 3rd party libraries, and every other little thing. Then i resort to put GC.Collect statements around, thinky that it will magically free memory.
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Then i go searching for how to debug these things:
http://blogs.msdn.com/tess/archive/2006/09/06/742568.aspx
http://blogs.msdn.com/tess/archive/2006/08/11/695268.aspx
Finally i get stuck into reviewing my code with a fine tooth comb, and find one thing that was causing the leak, static array on a singleton, used in temporary processing, that didnt get cleared.
2006-09-23
HttpContext Items Strongly Typed
public abstract class AbstractObjectCacher<T> {
#region IoC
private IObjectCache<T> cache;
public IObjectCache<T> Cache {
set { cache = value; }
get { return cache; }
}
#endregion
public T Get() {
return cache.Get();
}
public void Set(T obj) {
cache.Set(obj);
}
public void Dispose() {
T obj = Get();
if(obj != null) {
Set(default(T));
if(obj is IDisposable) {
((IDisposable)obj).Dispose();
}
obj = default(T);
}
cache.Clear();
}
}
So for instance, the thread store i use for unit testing will look like this:
public class ThreadObjectCache<T> : IObjectCache<T> {
#region IoC
private string key;
public string Key {
set {
key = value;
ThreadStore.Initialise(key);
}
get { return key; }
}
#endregion
public T Get() {
return (T)ThreadStore.Get(key);
}
public void Set(T obj) {
ThreadStore.Set(key, obj);
}
public void Clear() {
ThreadStore.Set(key, null);
}
public void Dispose() {
ThreadStore.Dispose(key);
}
}
And the HttpContext store will look like this:
public class HttpContextCache<T> : IObjectCache<T> {
#region IoC
private string key;
public string Key {
set { key = value; }
get { return key; }
}
#endregion
public T Get() {
return (T)HttpContext.Current.Items[key];
}
public void Set(T obj) {
HttpContext.Current.Items[key] = obj;
}
public void Clear() {
HttpContext.Current.Items[key] = null;
}
public void Dispose() {
HttpContext.Current.Items.Remove(key);
}
}
2006-09-20
Changes are not allowed while code is running
Notice the lock icon next to the filename, showing its read only.
This is a feature of VS that allows you to change the code and continue running with the modified code.
It seems to be only useful for desktop applications, not web apps that we develop.
We know that if we change code in the binary then we will need to recompile anyway, so how do we turn off this annoying message.
To remove the message, turn off Edit and Continue by:
Going to options
Go to Debugging, Edit and Continue and uncheck the top box
By turning off Edit and Continue, you still can create and remove debug points why the process is paused.
And you can still edit aspx’s, ascx’s, and their code besides (in the web application) without problems.
db4o 5.7
2006-09-19
Updating Atlas
The other issue i had was i was gettting a debugger alert client side about
PageRequestManagerID not being an attribute on draggablelistitem. This is a custom drag item i have implemented, so i just went digging through AtlasControlToolkit and found something similar to what i wanted to do DragPanelProperties and it has go this code:
[EditorBrowsable(EditorBrowsableState.Never),
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string PageRequestManagerID {
get { return null; }
set { throw new NotImplementedException(); }
}
So i just copied that into mine, and things worked. Its weird that there is no need to have the "new" keyword on this method. And why didnt it work in the first place.
ASX Partition Table
Now there may be a better way, by using Partitioning. I will be able to have the same tables, and then a view on top of them that i can query. The partitioning will happen on the stock code. With sql server 2005 this will happen automatically. Nice.
http://weblogs.sqlteam.com/dmauri/archive/2005/07/18/7147.aspx
http://searchtechtarget.techtarget.com/originalContent/0,289142,sid91_gci1207038,00.html
http://www.google.com/search?hl=en&lr=&q=partition+mssql+2005
Unicode Kanji Characters
Javascript Triple Equals (===)
http://www.flashinsider.com/2005/07/25/null-equals-undefined-but-null-doesn-t-strictly-equal-undefined/
http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx
http://www.ejball.com/EdAtWork/PermaLink.aspx?guid=1a946f91-d37d-4104-a1d3-63e633afafba
So it does a comparison of the value, including the datatype. I don't know if i will ever use i, considering i have never used it, but it might come in handy later.
Output Stream Filtering
My prefered method would be to have a helper static class that references HttpContext.Current in runtime and something else a design time. Then use <%= HtmlHelper.AppRoot %> in templates instead.
Remember to wrapper the script tags in an asp:PlaceHolder if you get the can't add to controls collection error.
2006-09-18
Delete All Rows
Many a time i have wanted to delete all the rows from all the tables in the database. It usually involves a script getting all the names of the tables and deleting one at a time. This script is awesome where you can do it in one line:
EXEC sp_MSforeachtable @command1 = "TRUNCATE TABLE ?"
How many other things will this make easier.
2006-09-14
Random Selects
SELECT *
FROM MyTable
ORDER BY NEWID()
2006-09-11
.Net 2.0 RSA Encryption
The classes all exist in the System.Security.Cryptography namespace:
http://msdn2.microsoft.com/en-us/library/system.security.cryptography.aspx
I have choosen to use RSA asymmetric encryption:
http://msdn2.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.aspx
Many examples helped over the basic msdn documentation:
http://www.codeproject.com/dotnet/RSACryptoPad.asp
http://www.codeproject.com/dotnet/SimpleEncryption.asp
http://www.eggheadcafe.com/articles/20020630.asp
http://www.codeproject.com/dotnet/ComboEncryption.asp
http://blogs.msdn.com/lcris/archive/2006/05/08/592868.aspx
One of the annoying things to remember is that on a shared hosting server, you will most likely not have access to the underlying COM object directories. I thought this would be a show stopper, but this only restricts you from decrypting the values, you can still encrypt items fine. So if your requirement is to collect data and store it securely with a public key, then download it remotely and process it with the private key, this should work.
Some issues that may arise:
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q322/3/71.asp&NoWebContent=1
.Net Serializers
Interestingly though, the XmlSerializer does not implement the same interface as the BinaryFormatter, so i can't just sub in the constructor. The serialise method has the same parameters which is strange.
Heres the msdn doc on the XmlSerializer:
http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx
And this explains the trust issue:
http://haacked.com/archive/2006/07/09/ConfiguringLog4NetWithASP.NET2.0InMediumTrust.aspx
I really thought there might be a way to set the properties that get serialized, but it looks like a LinkDemand and Security assert is performed right at the start of the internal serialization class, so theres no hope of ever getting this to work.
2006-09-06
Inline Server Script in Header
<html>
<head runat="server">
<title></title>
<asp:PlaceHolder runat="server">
<link href="<"%= SomeVariable %>/style.css" rel="stylesheet" type="text/css" />
</asp:PlaceHolder>
</head>
</html>
This way you can still add controls to the header by doing:
Page.Header.Controls.Add();