# Tuesday, June 16, 2009
Today I wanted to make a Click-Once-Deployment of an application which uses the Gecko engine via the GeckoFX.dll. For some reason I decided to include the Gecko-Engine-Zip as a resource inside my .exe to unpack it after installation by the program itself. Everything worked just as planned except for my clickonce-downloaded Application - it simply did not work.
After some tries I noticed that it only wont work when started from the start menu rather than from the installation path itself. Then -later- it also worked from the startmenu... very strange...
I'll keep it short this time... so what's happened was that I started the clickonce from Firefox - it has a plugin that supports clickonce. This -like also the click in the startmenü- will start up the dfsvc.exe which then will start the application. The dfsvc.exe itself has a behaviour that it wont be started twice but also terminates after about 15 minutes when idle.
The clou is that Firefox will add its program path to its Process-Enviroments "Path" Variable which then will be inherited to the dfsvc.exe process and also then to my applications process and since firefox places its path at first - the gecko engine tried to pick all its needed dlls from the firefox path rather than the unpacked xulrunner path in my installation directory.
Since I tested very frequently at the beginning I kept the dfsvc.exe with the "wrong" Path-Vars alive and only later after a little idle time a new instance was started by clicking the prog in the startmenü and the pathes then were correct.
So do you still think ClickOnce is cool?? ;-)

posted on Tuesday, June 16, 2009 4:31:11 PM (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Monday, May 25, 2009
Linq to sql comes with a really nice GUI to create those .dbml-files (which then will be used to create code). This works well for SQL Server Databases. Anyway - Linq to sql may also be used to access Sql Compact Edition but you can't use the GUI to drag-drop tables from an SQL-CE-Database onto the dbml-Editor. There are a lot of articles on the web which use SqlMetal to create that dbml-file which then can be used inside Visual Studios GUI. Also there seemed to be not only few people that wanted SqlMetal to skip some tables - this would be very useful when you often change something in your DB-
Schema but not want to drop every unused table every time again in the GUI or maybe if you want to rename some columns afterwards... So - recently I was in this situation and it was absolutely clear that there will be more of that work... so what I was looking for was a way to script that dbml-generation with support to exclude and rename tables and more (since we often deal with prefixes at our tables which I dont want inside my LinqClasses). After some research I figured out a way that works pretty nice for me. I wont go too much into details here because its too much..
First of all I used ildasm to disassemble SqlMetal into IL-Code via dump. Then I replaced most of the private words with public and added public here and there later when needed. Then I re-assembled that code using ilasm with the /DLL option. Finally I had a nice DLL where all that stuff I needed was no longer internal - it was all public - so I went on and created an own console-project which uses the SqlMetal.dll (the filename really MUST be SqlMetal.dll). I took the important parts of the old main method using .NET-Reflector and finally I had the pieces seperated where the the dbml-structure was extracted from an .sdf-file and where this structure was used to generate the .dbml-file. Nice. This structure is very simple to modify and the changes are copied to the dbml without any problems except if you change a name of a type and not change the type-reference in the association objects. Finally I did not want to write special code into this project everytime I have to deal with a new .sdf-file I decided to use the luainterface project to embed the lua-scripting language (very often used in games) to use lua-code for callbacks such as table exclusion, table and relation renaming, column renaming and whatever comes away... all I now have to do when it comes to dbml creation is to start my console
tool with a little lua-script as an argument and this (might) register some hooks where I may react to some columns by returning a different name. quite simple isn't it?? Oh well - some might be wondering how this stuff works - since sqlMetal is strong named... well since I will use this tool only in development I simply skipped the Strongname verification on my machine for that assembly by reflecting its strong name and using sn.exe to add the skipping rule like that
sn.exe -Vr *,<strongname-key>
I don't know if this is possible with earlier versions of sn.exe - I am using VS2008 SP1 by now.
So in the end I named the prog SqlCerium - since it is SqlMetal specialized for SQL CE and Ce is the chemical symbol for Cerium which is also a metal :-)

posted on Monday, May 25, 2009 11:07:35 AM (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Tuesday, May 19, 2009
Recently I tried to add a WCF based service channel to my NT-Service to be able to handle client requests from a GUI. I never noticed any problems with that kind of stuff so the more I was surprised as I got that error from the headline... Well the difference was that I usually worked (as developers mostly do ; ) with an useraccount which had administrative privileges. The service instead runs as a Network Service... interesting... even if it would be able to open a port and listen to it - it was not abled to use WCF to listen on an httpBinding. I found a few infos in the web but they were mostly regarding problems under Windows Vista and their solutions were all using netsh - which on my system (WinXP SP3) worked totally different so I skipped those experiments. Finally I found a much better Blogpost which featured some more solutions. On my system I succeeded by using the HttpNamespaceManager and adding the base-address (with that strange http://+:port/ Syntax) with access to the Network Service. So thx for that blog : )
Anyway - it might seem a little strange that a network service program can open any port and listen to it and maybe handle http-protocol by itself but not use some sort of windows-aided http-listening. So this may be more of a feature restriction than a real security issue I think...

Supplemental: I worked around that stuff by now with using a net.tcp binding instead of a Http. So - even it seems possible to add these http-stuff programmatically in the installer - this may be an alternative for someone too.
posted on Tuesday, May 19, 2009 10:39:48 AM (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Monday, March 30, 2009
Today I was adding a simple timeout functionality that should stop a thread after a period of time by calling thread.Abort(). It always did the right thing in my testProject so the more I was wondering why my actual thread survived the abort by just catching the exception instead of the usual pattern that even if the ThreadAbortException is caught it automatically will be re-thrown at the end of the catch (or at the end of the finally...) unless you disarm it by calling Thread.ResetAbort(). I did not call ResetAbort at all so I took a closer look to what I was doing in this thread... I was using IKVM to create a .NET library out of an JAVA-jar-file to use it from C#. The clou is, that ikvmc compiles java-Catch-Blocks to C# with an additional MapperCall and this will call ResetAbort which avoids rethrowing after the fellowing nested catch blocks. Not exactly what I expected but you deal with this behaviour easily since the exception is still thrown so you can add an extra catch Block for ThreadAbortException and exit as wanted.

posted on Monday, March 30, 2009 7:45:18 PM (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Friday, February 20, 2009
Since I was using ODBC to read/write Excel documents recently I was surprised not to have too much problems with it. Today a problem occured - funny thing because I was nearly through with changing the application to finally use SqlCE as persistency layer...
The problem was that we needed some large texts placed in some columns but excel just truncated it down to 255 chars (256 if you count the ' thats visible in excel). I didn't had much time to write some workaround at this point so I tested a little bit hoping to find a shorter workaround.
Of Course todays excel can handle more than 256 chars in a cell but when you save the document you'll get a warning for some incompatibility issues. Nice - file saved in "new" format - opened my program again - inserted a large text and ye......no - again truncated to 256 chars. So the ODBC driver seemed to switch back to old format. Since the driver seemed capable of handling xls files of office 12.0 (2007) according to the descriptions in the ODBC-Administration dialog I was looking for a simple way to make him use the new format. Finally I found something on the web saying that the driver determines the format by scanning some rows and while reading this I rememberd something I red earlier; there is an option "Rows to scan" in the ODBC-config and/or in the connection-string which was always set to 8. Well putting a large text in one cell in the first 8 rows and SUCCESS now even my application can write texts with more than 256 chars...
At this point I stopped testing so maybe it is possible to increase the RowsToScan variable to a max value or something - for me my quick and dirty workaround was done here ;-)

posted on Friday, February 20, 2009 5:52:47 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Thursday, February 19, 2009
Today I wanted to Show a Modal Dialog until something was stored in the FormClosing event. For some reason at another point in an UnhandledExeptionHandler I called Application.Exit(). The result was another Exception "Collection was modified; enumeration operation may not execute"...
I was abled to reproduce this effect in a very simple WinForms-example with two forms and a button:
 private void button1_Click(object sender, EventArgs e)
 {
     Application.Exit();
 }

 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     using (var frm = new Form2())
     {
         frm.ShowDialog();
     }
 }
So the clue is that Application.Exit enumerates its forms and raises the FormClosing event - which... opens a window on its own and so modifies the Applications Form Enumeration which led to this bug.
btw a MessageBox.Show did NOT produce this problem maybe because its just mapped to an Win32 API-Call that wont modify the .NET-Applications-Formlist.
I worked around that problem by simply Closing the Window instead (or just before App.Exit).

posted on Thursday, February 19, 2009 12:06:51 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Tuesday, February 03, 2009
A few days ago I was about to use the linq to SQL column property "Delay Loaded" for the first time. I wanted to return some plain data objects with an (propably larger) Image field left empty to load it later only if the entity would be selected in the GUI. So I used one Method to give me a set of objects with an empty image field and later another method to give me a specific image.
I already knew this Delay Loaded-Property would cause the creaton of a System.Data.Linq.Link<T> internally. So I thought as soon as I would do a read-access to that image-column the full content would be loaded from the database (though even write-accesses will imply a pre-read of that data so dont think about avoiding loading huge data by setting the field to another value).
I used my datacontext in a using block where I typically set the ObjectTrackingEnabled to false because I dont needed that if I only do readings to the DB. But in fact it turned out that this would also avoid loading fields that are "Delay Loaded" - so ObjectTrackingEnabled set back to true and everything worked fine as long as I initially accessed the image field inside the using-construct (ok that makes sense easily..).
I checked against the documentation where I found a short page about how to retrieve information as read-only and found out that setting OTE to false will also set DeferredLoadingEnabled to false and that would skip the expanding of one-to-one and one-to-many relations - BUT no word about Linq.Links :-)
Looking into the docs of DeferredLoadingEnabled also told me that if OTE is false DLE is not only set to false - its ignored completely - and again nothing about Delay-Loaded Fields. So maybe this info was helpful..

posted on Tuesday, February 03, 2009 3:54:21 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
-