Bouncing Ma'ss

Techinical bits from a Bouncing Fish.

Monday, January 29, 2007

Master Pages and Relative Links

So you have a master page thats used for content pages in sub folders.
ASP.NET will be smart enough to catch some urls in the master page and rebase them according to where the content pages is. Most of the time. In a few cases such as:

< style type="text/css">
@import url(/s/main.css);
@import url(/s/schedular.css);
< / style >

ResolveClientUrl() does the trick we're looking for here.

< style type="text/css">
@import url(<%= ResolveClientUrl("~/s/main.css")%>);
@import url(/s/schedular.css);
< / style >

Thanks to: http://www.odetocode.com/Articles/450.aspx for the answer.
Reading the post makes me think I should prefer the type of links .NET recognises.

NB: Stop mangling my style tags blogger!

Labels: ,

Wednesday, October 11, 2006

Calling virtual methods in constructors.

So I got given this warning today and went hunting for an explanation. It's an interesting point so I thought I'd use it to mark a return to some blogging.
I got my information from these two links: Meyer Effective C++ and a discussion on it's implications in C#.

You have class A and B.
B derives A.
B implements some virtual method foo();
A's constructor calls foo();

C++:
In C++ when you're calling constructors, at the time you call the base constructor your object instance is not yet of type B and so A's implementation of foo() is called. This is safe and good.
Why? Well consider what happens when B's implementation of foo() depends on some setup on B's ctor.

C# and Java:
These two recklessly call the lowest implementation in the polymorphic chain. Again consider what happens when B uses some custom setup in B::ctor(). Kablamo.

So there you go.

Friday, June 02, 2006

ASP.NET 2 Site Won't Start Server Error followed by Mutex Could not be Created.

Trying to reinstall asp.net and resetting permission on the directory, will get rid of the server error message and then give you the

Mutex Could not be Created.

Follow this one up by hitting:

C:\Windows\Microsoft.Net\Framework\v2.xxxx\Temporary ASP.NET Files
Delete everything in here. You'll find Visuals Studio has a lock on one of the files and so close visuals studio clear it up and the site should start working.

Monday, April 10, 2006

.config files with NUnit and TestDriven.Net

So how do you do it?

Get an assembly to read config when you're testing it with NUnit and TestDriven.net that is.

NUnit GUI has plenty GUI options up in the menus to select different configs. This is very nice.
Also in visual studio 2005 I noticed TestDriven.net copy app.config to where it was running its tests. But for the life of me I couldn't get it to do the same in 2003 /1.1 [.]

I doubt the problem is with the two frameworks. It's just me being rubbish. But here is how you get an assembly to read settings from a config file via TD.NET.
  • Name the file the test assemblies name including the dll .config So
  • TestAssembly.dll.config
  • Copy it in the build directory bin / debug (or release maybe).
  • Kablamo. It will read that one.

Note don't name it the name of the assembly under test. That's is if TestAssembly tests code in Assembly.dll don't call the file Assembly.dll.config.

Thursday, March 16, 2006

Getting Bloomberg COM Interop to Work

Or: How to edit interop stubs automatically generated by VS.NET etc,

Or: How to deal with COM's optional parameters in .NET

Broken ASP

Keywords:

Reinstall COM+
OC_COMPLETE_INSTALLATION
ASP
DCOM got error "Logon failure: unknown user name or bad password. " and was unable to logon
The server failed to load application '/LM/W3SVC/1/ROOT'. The error was 'The server process could not be started because the configured identity is incorrect. Check the username and password.

Symptoms:

ASP and ASP.NET pages broken, HTML and graphics OK, attempting to debug web applications kills server, various COM+ errors in event log, COM+ browser in Component Services crashes.

Cause:

COM+ install has been corrupted.

Solution:

Reinstall COM+ by deleting HKLM\SOFTWARE\Microsoft\COM3 key and rerunning add/remove windows components. If this doesn't work, follow instructions here (cached), paying attention to the regsvr32 /s ole32.dll and regsvr32 /s oleaut32.dll commands not documented in the MSKB solutions.

New member Shak!

Bouncing Ma'ss welcomes Shak to the group.
Me feels a name change coming.

Thursday, March 09, 2006

ASP.NET Event firing

How do you spell firing?

Anyway, recently I had a baffling problem with ASP.NET which when resolved changed my understanding of the ASP.NET Event Firing Sequence. (Fixed it if you will).

I had a GridView. I as was adding buttons to a cell of the GridView .
Problem:
  • Data-Binding only occurs on the !IsPostBack load of a page.
  • Dynamically added controls do not persist over post backs like a controls value (or a GridViews rows) do.*
As my controls were being added by RowDataBoundEvent, they'd disappear unless I explicitly called DataBind in Page_Load.

Here's the event conundrum that had me for a while and taught me the lesson.
My dynamic buttons survived the first load so I didn't muchly care they disappeared after clicking them, well I did but I was still perplexed as to why they didn't actually do their work.

I expected adding a handler to the dynamic button to give it Client side button something like this:

onclick="do what you're told"


But it didn't.
Why?
Because it does this.

onclick="tell me you were told to do something"


Then when the postback happens. ASP.NET rebuilds the page, figures out who's interested and calls them. Therefore, as my dynamic buttons weren't put back on the page (as there was no databind()) this happened:

onclick="I got clicked"
asp="I don't know who you are, sorry"


I don't think I like ASP.NET because it does such simple thing in such convoluted ways. I understand its a result of the internet and not ASP.NET's fault. I just don't like it.

I'm going to install Ruby On Rails.

*This to me says that a GridView is bound once when its loaded and once again when it fires an event. Hmmmmm

Tuesday, February 28, 2006

Updating a form / control from another thread

A common problem this must, as VS2005 Exception dialog walked me through the fix nicely.
So I get you can update a control from different threads, but I didn't think a timer callback counted as a separate thread. Duh!

Well it does and VS will throw an exception when you try and access a control from a separate thread, always in debug mode and sometimes in release mode.

In debug the exception box will lead you to this article directly.

Which simply tells you to do some stuff with a controls Invoke method and InvokeRequired property.

Before the offending code add this check:

if (this.InvokeRequired)
{
//Make a delegate version of this function and call:
this.Invoke (delegateObject, [parameters]);
}
else
{
//As normal
}


Pretty easy, best to do it at the event handler that the timer calls or fires.