Yavor Georgiev

Yavor is a PM at Snowflake working on developer experience. Previously at Docker, Auth0, Hulu, and Microsoft Azure.

Debugging SGEN LoaderExceptions errors

06 May 2011

Recently we were contacted by a customer who was building a Release version of their assembly in Visual Studio and encountered the following error:

SGEN error in Visual Studio

You could get the same error if you attempt to run the sgen.exe tool on the built assembly:

~~~ Microsoft ® Xml Serialization support utility [Microsoft ® .NET Framework, Version 4.0.30319.1] Copyright © Microsoft Corporation. All rights reserved. Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Read More

RIA Services T4 template to copy comments from server to client

05 April 2011

As you know one of the new features in RIA Services V1 SP1 is support for T4 templates. The T4 template is a design-time artifact that can modify the way RIA Services client-side code generation happens. For more information on T4 templates, check out Jeff Handley’s blog post on the subject.

Recently I was experimenting with RIA Services and I discovered that the IntelliSense comments for my entities were very sparse on the client. For example my Customer entity has a CompanyName property and the IntelliSense comment for that was:

Gets or sets the "CompanyName" value.

It was clear that this comment was being generated automatically, which was quite annoying because I had used my entity model on the server to carefully create useful comments for each property.

EF designer showing property documentation

I hear EF is actually smart enough that it supports defining these comments in the database itself, and they will get copied over when you create the model, but I haven’t tried it myself.

So I set out to write a T4 template to take those comments from the server types generated by EF and copy them over to my Silverlight project.

The first step was to tell Visual Studio to scrape all the types in my server project and generate a XML file containing their comments, by going to the Build tab of project properties and checking this box: 

Enabling XML comments in project properties

This file is usually used for IntelliSense, but you can open it up and the schema is pretty self-explanatory. Because code comments don’t get compiled into assemblies, this is the only way I know to tell VS to export the comments from my entities.

The next step was to write a simple T4 template using RIA Services extensibility. What this does is that as it is about to generate a type on the client (which happens when you build), it will look up that type name and all its properties in the above XML file, and copy the comments over to the generated file.

~~~ csharp [DomainServiceClientCodeGenerator(typeof(CommentsClientCodeGenerator), “C#”)] public class CommentsClientCodeGenerator : CSharpClientCodeGenerator { private XElement comments;

Read More

Презентацията ми за WCF и Silverlight от Дни на Microsoft '11

04 April 2011

Ето и презентацията ми за Silverlight и WCF услуги в Windows Azure. Очаквайте и демонстрациите скоро! Отдолу ще намерите презентацията и примерите които показах.

Примери

Read More

Презентацията ми за WCF RIA Servces от Дни на Microsoft '11

04 April 2011

Благодаря на всички които дойдоха на моята презентация за RIA Services миналата седмица по време на Дни на Microsoft ‘11. Отдолу ще намерите презентацията и примерите които показах.

Примери

Read More

Accessing SharePoint UserProfileService from Windows Phone 7

07 March 2011

UPDATE: … and it wasn’t long before Matthew McDermott went ahead and implemented ths as an actual sample, which you can get here.

A while back I blogged a workaroundfor accessing some ASMX services from Silverlight 4. The problem was that the guid and char types that those services return are not recognized by Silverlight and you end up with the exception below. One of the important services affected by this is SharePoint’s UserProfileService, which I realize is pretty important to a lot of developers.

System.ServiceModel.Dispatcher.NetDispatcherFaultException was unhandled by user code. The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:HelloWorldResponse. The InnerException message was 'Error in line 1 position 268. Element 'http://tempuri.org/:HelloWorldResult' contains data of the 'http://microsoft.com/wsdl/types/:guid' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'guid' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.

(Same goes for http://microsoft.com/wsdl/types/:char)

We have already fixed this issue and you will not need the workaround anymore in the next version of Silverlight.

In implementing the workaround, I used an IClientMessageInspector, which unfortunately is only available starting in Silverlight 4. So all of our developers using Silverlight 3 (and in particular folks writing apps for Windows Phone 7) cannot use the workaround.

Fortunately, there is a way to “fake” an IClientMessageInspector on older versions of Silverlight, and I wrote a sample for that back in the Silverlight 2 days. So combining these two samples together, you can be on your way:

  1. Create a “fake” IClientMessageInspector like in this sample
  2. Use the IClientMessageInspector implementation that treats the guid and char types emitted by ASMX from this sample.

Hopefully this will unblock folks out there, if there is significant interest here I can create a combined sample that shows the whole thing end-to-end.

Read More