Developing on Staxmanade

i4o: IndexSpecification<T> for the IndexableCollection<T>

We've removed the IndexableAttribute from the i4o library and replaced it with the IndexSpecification<T>. Below I'll explain how you can add/remove/change the index for an IndexableCollection<T>.

Let's show several examples on how to create an IndexableCollection<T>.

Given any enumeration of objects you can translate into an IndexableCollection<T>. For the examples below we're going to use an enumeration of the System.IO.FileInfo class. We are going to index the list of FileInfos by file Extension and weather the file IsReadOnly or not.

Setup the list:

// Get our thing to index
string dir = @"C:\Windows\System32\";
var fileInfosFromDir = (from f in System.IO.Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories)
select new FileInfo(f)).ToList();


Can create the IndexSpecification...

...for the FileInfo's "Extension" and "IsReadOnly" properties and turn the list of FileInfos into an IndexableCollection using the IndexSpecification.

// Create the index specification
var spec = new IndexSpecification<FileInfo>()
.Add(i => i.Extension)
.Add(i => i.IsReadOnly);

// Turn the list of files into an Indexed collection of files
var indexedFileInfosFromDir = fileInfosFromDir.ToIndexableCollection(spec);

Create IndexableCollection<T> without IndexSpecification<T>:

You are not required to specify and IndexSpecification<T> when creating the IndexableCollection<T>. You can translate the list into an IndexableCollection<T> and add properties to index after the fact. EX:

var indexedFileInfosFromDir = fileInfosFromDir.ToIndexableCollection();

// Specify the properties to index dynamically (more late bound)
indexedFileInfosFromDir
.CreateIndexFor(i => i.Extension)
.CreateIndexFor(i => i.IsReadOnly);

Swap one IndexSpecification<T> for another:

If you want to completely swap out the index at run time, you can give the IndexableCollection a new IndexSpecification

var list = new List<FileInfo>();
var indexedList = list.ToIndexableCollection();

indexedList.UseIndexSpecification(
new IndexSpecification<FileInfo>()
.Add(o => o.Directory)
.Add(o => o.Name));

I think that should cover most of the general cases. Hope this helps...

Comments

Alex
Nice Blog, i recently come to your blog through Google excellent knowledge keep on posting you guys.

___________________
Dissertation Sample
___________________
marry
Blogs are so informative where we get lots of information on any topic. Nice job keep it up!!
_____________________________

Dissertation Topics
Satyanarayana Muddu
Hi Jason,

Thank you for your response.
My Xml looks like

University1
Course1
Student1
Student2
University1
Course2
Student3
Student4
University2
Course1
Student5
etc...

XElement cimXml = XElement.Load(@"C:\Students.xml");

So, here I am grouping on Universities.
var universityGroupedElements = from ele in cimXml.Elements() group ele by ele.Name;

Now I want to add indexes to University, Course, Student elements to make queries faster.

Also, I want to group the courses in each university and also students in each course

Please help, in writing some code.
Jason.Jarrett
Hello @Satyanarayana

I would be happy to help you, but have a request and a couple questions...

1. I've realized my blog comments are starting to become a bit more of the i4o knowledge base than it deserves. Would you please ask your question over on the i4o Discussion board?

2. I'd like a little more detail. What does the xml structure look like? What does the linq query look like that returns your "grouped" data? What is it you are trying to index/search?

Thanks,
Jason
Satyanarayana Muddu
I have a question how to use IndexSpecification for a nested collections in a xml file. For example
University
Course
Student

I have list of Students from a various Courses and various Universities. I used Linq for Grouping Universities and Courses of Students. Now, I have question how to implement Indexing on Students, Courses and Universities.
Please give the implementation details .

Thanks
Satya
Paiwan
At first, I was thinking of modifying i4o but after I have been testing, I have found the power behind i4o with simple changes the way you write query.

For example:

Instead of writing this..
var f = indexedFileInfosFromDir.Where(fi => fi.Extension == "txt" && fi.IsReadOnly == true);

Try this..
var f = indexedFileInfosFromDir.Where(fi => fi.Extension == "txt");
var f2 = f.Where(fi.IsReadOnly == true);

(fi.Extension should be smaller group than fi.IsReadOnly)

From what I have tested,
It responses within a few milisecond.
I am happy with this.

Thank you for great work.
Jason.Jarrett
@Paiwan - I'm glad to see you're running your own benchmarks to test out the library.

Please keep in mind that this library is very simple, and is not a complete Linq implementation.

It provides some great benefits in the scenarios it was designed for. And I know Aaron has some more improvements on the way.

If you create any patches for the project, we are happy to take a look at any improvements you can come up with.

Thanks again
Paiwan
I have found another limitation of i4o and would like to share.

From the 'Demoi4o' project.

If I change this below query

var studentsNamedAaronFromConstant =
from student in _testStudents
where student.FirstName == studentNameBox.Text
select student;

To

var studentsNamedAaronFromConstant =
from student in _testStudents
where student.FirstName.Contains(studentNameBox.Text)
select student;


It takes longest time!!
Paiwan
Thanks so much for unit test.
Jason.Jarrett
@Paiwan To test your question I wrote a unit test and just checked it in. You can view the test here http://i4o.codeplex.com/SourceControl/changeset/view/31862#398075

If this is what you were asking, then no it will not update the index.

You need to call the IndexableCollection<T>.Add/Remove and not it's base type Collection<T>.Add/Remove for the indexes to be updated.

This is however something we'd like to support in the future, which is why I checked in the failing test. We probably need to just implement ICollection<T> etc... and to fully support this.
Paiwan
Hi Jason,

I have a question.
If we have some changes on our base collection like add or delete, do we have to re create index or do some special steps?

Thanks,
Paiwan
Kevin
Ok, thanks for the confirmation. I wanted to make sure I wasn't crazy. :-)

I was excited when I saw your post and really like the syntax for adding properties to the IndexSpecification. Now, I guess I'll just wait until I can actually use it like that. From Aaron's blog, it sounds like he plans to introduce updates to the Where expression in the next release.

Thanks for your work on this library. I'm hoping this will make it possible to replace a subsytem of our app which currently relies on looking up factors in large in-memory sets of data by using XML. It loads large XML documents into memory and builds XPath queries to get to individual factors that it needs. The XPath queries themselves are pretty past, but I'm trying to use Linq-to-XML to project the XML into collections of strongly type objects that I can query with Where lambda's instead. It works well, but when the collections are large enough the queries are too much slower than the XPath version. I'm hoping the IndexableCollection will make it possible.

Kevin
Jason.Jarrett
That's a good point and I think you are correct...

I was just illustrating the power of the IndexSpecification. Unfortunately the extension methods used to evaluate the expression need some work.
Kevin
Hi Jason,

Thanks for this post. I got to it from the i4o home page on Codeplex. I noticed in the discussions that someone mentioned the fact that if you have multiple expressions in your Where expression, that it won't use the index.

So does that mean, your example showing multiple properties being added to the index doesn't really help if you wanted to search your collection on both of the properties in the index?

For example, would this code use the index?

var f = indexedFileInfosFromDir.Where(fi => fi.Extension == "txt" && fi.IsReadOnly == true);

From my testing, it appears that no benefit is achieved from using an IndexableCollection vs. a regular List in this case. Seems like there's no point in using the IndexableCollection if you need more than one property in the index. Am I missing something or is that correct?

Thanks,
Kevin

i4o: Update (Index for Objects)

Recently I was added as a developer to the i4o codeplex project by Aaron and last night I made my first commit.

There were a few pretty big changes to the library. I'll highlight some of them below, and in a couple future posts will describe in a little more detail how you can use these features.

Removed the IndexableAttribute:

This was removed for two reasons.

  • It did not allow you index objects you didn't own.

Say you want to index a collection of System.IO.FileInfo objects. Since that's owned by the .Net framework, you can't apply an attribute to the properties of the class you want to index.

The solution to that was to allow adding indexed properties dynamically, however you had to give it a string representing the property name, which leads into the second issue...

  • Didn't provide any compile time checking or refactor support for properties using the dynamic add/remove methods.

If you refactored a property and forgot to rename the string to match the refactor you would end up with a runtime error.

To resolve the two issues above I've introduced the IndexSpecification<T> (I'll describe how to use it a later post)

Performance tuning:

Although we haven't enhanced the Linq support for IndexableCollection (should come soon), I was able to eek some performance by doing some internal caching of property types and a few other tweaks resulting in the Index creation becoming about 30% faster...

Fluent interface for managing the Indexes

The last big change which fits in with the IndexSpecification<T> is the Fluent interface for dynamically adding/removing properties to be indexed. One short example could be:

image

Leverage Live Mesh to sync Windows Live Writer blog drafts between and multiple computers.

I decided to start blogging a little more regularly and one of the first things I ran into when researching the easiest way to create/publish blogs was Windows Live Writer.

I'm sold... This program handles just about everything I could need for blogging (I'm new to it, so haven't pushed it's limitations to far).

One problem I had with Live Writer was it saved all my drafts/posts on the computer I was logged into at the time. This meant the drafts I write at home can't be accessed at work and visa/versa...

To solve this I decided to wire them through the Microsoft Mesh. If you haven't setup your mesh yet, I would highly recommend it. Just go to Mesh.com, sign up/or in with a Windows Live account, install the client application, and your meshified...

With Live Mesh, you can synchronize files with all of your devices, so you always have the latest versions handy. Access your files from any device or from the web, easily share them with others, and get notified whenever someone changes a file.

This means I can synchronize folders between my connected computers.

Below I'll show the steps I used to setup my meshified weblog posts.

  1. Find the location your Live Writer is storing your drafts/posts.

    For my Windows XP machine it was in...
    C:\Documents and Settings\JasonJ\My Documents\My Weblog Posts\

    For my work Vista pc the folder was in...
    C:\Users\JasonJ\Documents\My Weblog Posts\
  2. Next I created a folder in my mesh called "BlogDrafts".

    image To do this you can right click in the mesh folder area and select "Create folder in Live Mesh".image
  3. A window will popup asking for the name of the new folder and the location this folder will live on your hard drive.

    image 

I think that's everything... follow similar steps to get your other computers synced up to the mesh and you should be relieved that you can work on any computer and on any post.

I can't stand mass mailings... (Especially when you can't turn them off)

 

WTF?

 

image

 

UPDATE: Thanks to Justin for pointing out my tarddedness... I should have left the boxes checked. However when I tried that I got the same error :(

image

Apparently it's not a "temporary problem"... or they could define temporary since this has been there for several days now.

Comments

Jason.Jarrett
Justin: Good point... Unfortunately I just re-tried it with the check boxes checked and received the same error :(
Justin Chase
Looks like you have your checkboxes backwards. If you can't stand mass mail then you should check "do not recieve..." boxes, right?
Will Hull
Weird. I specialize in e-mail marketing. Looks like their form isn't set up properly.

T4 Text Templating in Silverlight (Thanks Oleg Sych!)

First if you're new text templating, please go read Oleg Sych's blog. This, as far as I've found, is the (Bible, Koran, TheWord, etc...) of visual studio's T4 Text Templating.

If you already know how to add a T4 template to a project, skip this how to and go to "How to make a T4 template work with a Silverlight project:".

How to add a T4 template to a Visual Studio .Net Project:

Given the following project:

Initial Silverlight Project

Bring up the add new item dialog.

Add New Item

Select a "Text File" and rename the extension to a .tt.

Add a new t4 template

You should end up with a .tt template file and under it where the generated out put of the template will land.

T4Sample.tt

You may also notice the following errors in your errors pane.

  • Compiling transformation: The type or namespace name 'CompilerError' does not exist in the namespace 'System.CodeDom.Compiler' (are you missing an assembly reference?)
  • Compiling transformation: The type 'System.CodeDom.Compiler.CompilerErrorCollection' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
    Compiling transformation: 'System.CodeDom.Compiler.CompilerErrorCollection' does not contain a definition for 'Add'
  • A namespace does not directly contain members such as fields or methods

This is where Oleg Sych comes to the rescue...

How to make a T4 template work with a Silverlight project:

Side Note: So, I had a couple emails back and fourth with Oleg about trying to get T4 to work in Silverlight. Almost all of his emails had some sort of sentence that went like this. "Try adding {SomeSpecialT4RelatedWord} and then do {this special thing} and report your findings back to me". This is where the {SomeSpecialT4RelatedWord} would stump me. So I would search Google for "T4 {SomeSpecialT4RelatedWord}" and Oleg Sych's blog was the first hit for each search. And not only was it the first hit, but when I would look the post for that {SomeSpecialT4RelatedWord} the answer was there and exactly what I needed. Thanks Oleg.

 

Fortunately, to get the T4 templates to work within a Silverlight project you only need to put an <#@ assembly #> directive telling the template where to get a reference to the System.dll.

Below is a sample template:

<#@ template language="C#" #>
<#@ assembly name="C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" #>
namespace SampleT4
{
public class SomeClassSample
{
}
}



And below is the output:




namespace SampleT4
{
public class SomeClassSample
{
}
}



That's it!!!

Comments

Jason Jarrett
@Bill I'm afraid I don't have enough context to really help you. On top of that I haven't worked with silverlight in a long time :(.

Hope you get it figured out.
Bill Lanza
I know this post is old, but....
I am using VS2010 and Silverlight and am trying to implement T4 templates with inheritence. I create a baseclass.tt in a separate assembly and it compiles. However, when I try to inherit from it I get the error:

An invalid base class was specified for the Transformation class. The base class must derive from Microsoft.VisualStudio.TextTemplating.TextTransformation.

Is this not possible in SL?

Thanks,
Bill
Jason.Jarrett
Could you help me understand why you have to have a reference to the two different assemblies with the same type?
Anonymous
Regarding Aquilax comment, using objects defined in both assemblies. Is there any solution for that problem ?

Regards Swan B
Aquilax
It works as long that you don't use objects defined in both assemblies, for example System.Text.RegularExpressions.Regex, otherwise it throws the exception:
Compiling transformation: The type 'System.Text.RegularExpressions.Regex' exists in both 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll' and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v3.0\system.dll'
timvw
Thanks for publishing this knowledge. Saved me a lot of time.
br1
Thank you.
Алексей
Nice! Thx man.

Best regards,
Alexey Zakharov
Blog: http://weblogs.asp.net/alexeyzakharov/

i4o & Silverlight Unit Tests (A little more work than the i4o library)

Follow up to my post on i4o & Silverlight (compiles first try)...

 

I took a stab at porting the i4o unit tests to Silverlight which was quite a bit more work than I initially expected.

After creating a Silverlight Unit Test project and linking the original test files into the Silverlight project, I compiled...

  • First the VB using statement wasn't even needed, so I removed that. using Microsoft.VisualBasic;
  • Second there is no System.Diagnostics.Stopwatch() class in Silverlight, so I basically implemented a quick one using DateTime to get the unit tests to compile in Silverlight. Here's the class, except the Frequency property has been commented out (didn't spend time to figure how to make that correct, or what is correct???)
public class Stopwatch
{
private DateTime _StartUtcDateTime;
private DateTime? _EndUtcDateTime;
private bool _IsRunning = false;

//public static readonly long Frequency { get { throw new NotImplementedException(); } }
public static readonly bool IsHighResolution = false;
public Stopwatch()
{}

public TimeSpan Elapsed
{
get
{
if (_EndUtcDateTime.HasValue)
{
return new TimeSpan(_EndUtcDateTime.Value.Ticks - _StartUtcDateTime.Ticks);
}
else
{
return new TimeSpan(DateTime.UtcNow.Ticks - _StartUtcDateTime.Ticks);
}
}
}

public long ElapsedMilliseconds { get { return Elapsed.Milliseconds; } }
public long ElapsedTicks { get { return Elapsed.Ticks; } }
public bool IsRunning { get { return _IsRunning; } }

public static long GetTimestamp()
{
return DateTime.Now.Ticks;
}

public void Reset()
{
_EndUtcDateTime = null;
_StartUtcDateTime = DateTime.UtcNow;
}

public void Start()
{
_EndUtcDateTime = null;
_IsRunning = true;
this._StartUtcDateTime = DateTime.UtcNow;
}

public static Stopwatch StartNew()
{
var w = new Stopwatch();
w.Start();
return w;
}

public void Stop()
{
_EndUtcDateTime = DateTime.UtcNow;
_IsRunning = false;
}
}


The only other issue that came up was some of the Stopwatch dependent tests happened so fast that they would fail intermittently... the quick hack/solution for this was to up the iteration count of whatever they were testing.


After all the above taking care of all the above issues, I was able to get the unit tests to pass.


image

Comments

Tiaan
You might also want to look at my implementation of the Stopwatch for Silverlight, which supports resuming.
Tiaan
For the Frequency property's implementation, you probably just need to return the System.TimeSpan.TicksPerSecond value.

Is my HSA trying to tell me something?

 

This is my "randomly" generated "Site Key". My login's special word...

Would anyone else feel a little uneasy about this in a health related site?

 

clip_image002

i4o with Silverlight (Compiles first try)

So I've been thinking lately of a problem that we will be solving at work that will require a user to follow these steps...

1. User selects some set of data to work with
2. Some number crunching has to happen to give the user a report like interface
3. User analyses that data, tweaks some value and will basically go to step 2 above...

This application is being build with Microsoft Silverlight and in thinking about how to make step 2 above as smooth and responsive as possible, I thought "Hey, what about i4o?"

A quick Google for "i4o Silverlight" and without digging too far I basically found nobody had tried it, or at least tried and told about i4o in Silverlight. So I thought I'd give a go...

 

Step 1: Go get the code from from codeplex/i4o. I downloaded the latest source bits.

Step 2: After extracting the .zip...Open up the project i4o.sln

Step 3: Add a new Silverlight class project

image

Step 4: Now use the "Add existing item" option to add files to the Silverlight project. Browse to the i4o project folder to select the 3 i4o class files. You can add those to you Silverlight project as is or use the "Add as Link" feature to share the code across the platforms.

image 

Step 5: once you've add the files to the Silverlight project final step is to "BUILD" the solution...

What's that you say? "That's all there was to it?" YA, my thoughts exactly, the project just compiled on the first try...

 

DISCLAIMER: I haven't tried to use it yet... It's late and this idea popped into my head distracting me from getting to sleep. So I tried it and am quite satisfied for now.

 

Up NEXT: Don't know if I'll do this sooner than later, if at all, but figure out how hard it would be to port the existing unit tests to see how they run in Silverlight...

Db4o with System.Transactions.TransactionScope

After after reading Rob Conery's post http://blog.wekeroad.com/blog/crazy-talk-reducing-orm-friction/. I thought I'd give it a whirl and didn't get very far before I ran into my first roadblock. DB4O version 7.4.68 doesn't support any .NET System.Transaction. (For what I could tell...)

Below I'll explain how I pieced this together and made it work (At least an alpha type version to work...)

Assume I've followed almost everything Rob has in his blog for setup (IRepository, DB4O container class, ObjectRepository<T>, etc...)

My first unit test was the following

[Test]
public void CanRollbackSavedObjectInRepository()
{
  using (TransactionScope scope = new TransactionScope())
  {
    _repository.Save(_dummyObject);
    //NO: scope.Complete(); Implied rollback
  }

  if (_repository.GetAll().Count() > 0)
    Assert.Fail("TransactionScope Failed - count[" + _repository.GetAll().Count().ToString() + "]");
}

And the above test fails...

Next was some research to figure out why this was failing... I didn't find much out there, except for some pending TODO's on the DB4O project.

http://tracker.db4o.com/browse/COR-1376
http://tracker.db4o.com/browse/COR-1143

 

So then it was off to figure out how frameworks implemented there resource managers to hook into the System.Transaction goo...

(Long story short, and several trial and error failures) The best of the solutions I found was in this open source code base. (http://code.google.com/p/uniframework/)

In that project there was a class that managed the enlistment of a transaction, and some examples of how to use it...

http://code.google.com/p/uniframework/source/browse/trunk/sources/Uniframework/Db4o/Db4oEnlist.cs is the enlistment class.

 

I placed this Db4oEnlist class as a private nested class inside the ObjectRepository<T> since I can't see why it would be used anywhere else...

And below is how I use them in the ObjectRepository<T>.

public void Delete(T item)
{
Db4oEnlist enlist = new Db4oEnlist(Container, item);
bool inTransaction = Enlist(enlist);
Container.Delete(item);
if (!inTransaction)
Container.Commit();
}


public void Save(T item)
{
Db4oEnlist enlist = new Db4oEnlist(Container, item);
bool inTransaction = Enlist(enlist);
Container.Store(item);
if (!inTransaction)
Container.Commit();
}


 



We first create an instance of the Db4OEnlist class with the current container. This class implements the IEnlistmentNotification interface and knows how to commit/rollback/etc on the object database. We then use the private helper method Enlist() giving it the Db4OEnlist instance. This helper method enlists the sequence in any existing transactions returning if it enlisted in a transaction or not.



private static bool Enlist(Db4oEnlist enlist)
{
System.Transactions.Transaction currentTx = System.Transactions.Transaction.Current;
if (currentTx != null)
{
currentTx.EnlistVolatile(enlist, EnlistmentOptions.None);
return true;
}
return false;
}


If we aren't in a transaction we commit the action right away, however if we are in the transaction we let the .net System.Transaction framework take care of committing the transaction.



Once I found the example in the "uniframework" it came together rather quickly...



Below is the ObjectRepository<T> I'm going forward with on testing Rob's idea of developing an application using the object database first... (we'll see how it goes)



public class ObjectRepository<T> :
IRepository<T> where T : class
{
/// <summary>
/// Returns all T records in the repository
/// </summary>
public IQueryable<T> GetAll()
{
return (from T items in Container
select items).AsQueryable();
}

/// <summary>
/// Finds an item using a passed-in expression lambda
/// </summary>
public IQueryable<T> Find(System.Linq.Expressions.Expression<Func<T, bool>> expression)
{
return GetAll().Where(expression);
}

/// <summary>
/// Saves an item to the database
/// </summary>
/// <param name="item"></param>
public void Save(T item)
{
Db4oEnlist enlist = new Db4oEnlist(Container, item);
bool inTransaction = Enlist(enlist);
Container.Store(item);
if (!inTransaction)
Container.Commit();
}

/// <summary>
/// Deletes an item from the database
/// </summary>
/// <param name="item"></param>
public void Delete(T item)
{
Db4oEnlist enlist = new Db4oEnlist(Container, item);
bool inTransaction = Enlist(enlist);
Container.Delete(item);
if (!inTransaction)
Container.Commit();
}

private static bool Enlist(Db4oEnlist enlist)
{
System.Transactions.Transaction currentTx = System.Transactions.Transaction.Current;
if (currentTx != null)
{
currentTx.EnlistVolatile(enlist, EnlistmentOptions.None);
return true;
}
return false;
}

private static IObjectContainer Container
{
get
{
return ServiceLocator.Current.GetInstance<IObjectContainer>();
}
}

/// <summary>
/// Provides support for System.Transaction integration
/// </summary>
private class Db4oEnlist : IEnlistmentNotification
{
private IObjectContainer container;
private object oldItem;

/// <summary>
/// Initializes a new instance of the <see cref="db4oEnlist"/> class.
/// </summary>
/// <param name="database">The database.</param>
/// <param name="item">The item.</param>
public Db4oEnlist(IObjectContainer container, object item)
{
this.container = container;
oldItem = item;
}

#region IEnlistmentNotification

/// <summary>
/// Commits the specified enlistment.
/// </summary>
/// <param name="enlistment">The enlistment.</param>
public void Commit(Enlistment enlistment)
{
container.Commit();
oldItem = null;
}

/// <summary>
/// Ins the doubt.
/// </summary>
/// <param name="enlistment">The enlistment.</param>
public void InDoubt(Enlistment enlistment)
{
//throw new Exception("The method or operation is not implemented.");
}

/// <summary>
/// Prepares the specified preparing enlistment.
/// </summary>
/// <param name="preparingEnlistment">The preparing enlistment.</param>
public void Prepare(PreparingEnlistment preparingEnlistment)
{
preparingEnlistment.Prepared();
}

/// <summary>
/// Rollbacks the specified enlistment.
/// </summary>
/// <param name="enlistment">The enlistment.</param>
public void Rollback(Enlistment enlistment)
{
container.Rollback();
container.Ext().Refresh(oldItem, int.MaxValue);
}

#endregion
}
}

Comments

Magento theme
I found so many interesting stuff in your blog especially its discussion. So i must appreciate your efforts on posting these information.
German Viscuso
Hi!

You’ve been nominated as db4o dVP. Please see this page
I don’t have your contact info!

Best!

German
German Viscuso
Great stuff!
See:

http://developer.db4o.com/blogs/community/archive/2008/12/11/db4o-with-system-transactions-transactionscope.aspx

Best regards.

German Viscuso
db4objects community manager

WCF - Silverlight - Default constructor not called??

Can anyone explain why creating a default constructor (defined in a partial class) of an auto-generated Service References class for an object. Does not get executed when the object is created by a WCF service call?

I'll go through some of the basic steps I did to reproduce this, and I'll attach the project I created to do so. I would love if anyone had some insight into this... SilverlightWcfConstructorTest.zip

1. Create a web service that returns some complex type. (Class1)

2. Create a Silverlight app that can consume the service above. (Use the Add Service Reference so it will auto-generate a service reference file).

3. (in Silverlight) Create a partial class to extend the Class1 created by the service reference

4. Add a default constructor to this partial class.

5. Do something in this constructor to hint that it is called.

6. Run it and see that the default constructor is never called when making a WCF Silverlight service call.


WHY?


I have a full project put together that you should be able to unzip and run to see this behavior…

SilverlightWcfConstructorTest.zip


Update: I have a thread started at the silverlight forums on this topic...