When debugging WCF you can see this exception. Some people advice to just disable stop on exception But it's useful feature.
The better is to go into details of this dialog and disable just this specific exception. The only small problem is that it's not in the list. But it's really a small problem. You can add it.
Just press "Add..." button, choose "Common Language Runtime Exceptions" from the drop down list and type the exception type, which is System.Configuration.ConfigurationErrorsException. Now you can disable stopping on just this exception and not all of them.
Discovering .NET
Here I will post problems I and my colleagues met and solutions we found.
Wednesday, June 24, 2009
This element is not currently associated with any context
Friday, June 05, 2009
Getting output parameters when executing reader in ADO.NET
Interestingly, the values of output parameters are not available after ExcecuteReader() is called, even after all records were fetched.
To get these values it is required to either close reader (call reader.Close()) or at least call NextResult() method.
Wednesday, June 03, 2009
WCF - nullable values are not working in generics
Today I spent couple of hours figuring out why I suddenly got an error "Referenced type 'x`1, ... with data contract name 'xIF_Ph6aZR' in namespace 'x cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types."
It was working and what I did just little bit of re-factoring. What I found is that there is a combination of conditions that does not work, while every one of them works separately:
- Generic class is used as DataContract.
- This class has nullable DataMember property
- You want to reference your class in your client instead of creating in through wsdl.
[DataContract]and then you use it like this:
public class DummnyContract<T> where T: IBusinessObject
{
[DataMember]
public DateTime? LastModified{get;set;}
}
[ServiceContract]
public interface IService
{
[OperationContract]
DummyContract<int> Get(int id);
}
This just does not work when you reference your assembly with declaration of this class. You can have it without class being generic. Or, you can have generic without nullable property. But not together.
Saturday, May 02, 2009
WSE and Visual Studio 2008
If you got here from search engine you already know that WSE is integrated into Visual Studio 2005, but not 2008. You also know that if add reference to the web service that implements WSE you would get proper class in Visual Studio 2005 but not in 2008. The common advise is use VS 2005 to do the import, or use svcutil.exe.
The easiest solution though is just to open Reference.cs file and replace System.Web.Services.Protocols.SoapHttpClientProtocol with Microsoft.Web.Services3.WebServicesClientProtocol manually.
Also, here you can find how to make plug-in available in VS 2008 UI.
Friday, April 24, 2009
WCF under IIS access problems
Today I spent few hours trying to resolve problem with our WCF server for one of our clients. Somehow everything went wrong. Our configuration is WCF server that utilize .NET 3.5, and I set it up to work under IIS6.
The errors I got were different, but in result it was all about setting permissions for IIS. Many of them were trivial, but the last one I found tricky. HTTP result code was 500, internal server error, the error in EventViewer said: Could not load file or assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=xxx or one of its dependencies. Access denied.
Logically, something was wrong with access to \WINDOWS\Microsoft.NET\Framework\v2.0.0.527 folder. However, it was not so. What helped me was adding NT permissions to the folder with my WCF server to the group IIS_WPG. And this is after I tried to add permissions to user ASP_NET… and IUSR_… without success.
Wednesday, March 04, 2009
Fill WrapPanel from the list (WPF)
Sometime, when it is necessary to make a choice from the list, and the list is not that big, it makes sense to use buttons with some actions instead of lists. I found useful technique to do it when the list of actions is dynamic.
The idea is somehow populate WrapPanel with buttons dynamically. We can do it by replacing template for ItemsController.
I lave a collection of elements (it will be assigned to the ItemsSource property in runtime) with Key and Value properties.
<ItemsControl x:Name="activitiesControl" Margin="10">
<ItemsControl.Template>
<ControlTemplate>
<WrapPanel Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"
FlowDirection="LeftToRight" IsItemsHost="true">
</WrapPanel>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Style="{DynamicResource ActionButton}" HorizontalAlignment="Right" Margin="5"
Content="{Binding Value}" Width="200"
Command="{Binding Path=ViewModel.ActionTypeCommand,
RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType=local:CustomerEditView}}" CommandParameter="{Binding Key}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Note that I am using Commands. Finally, we have it. Not in Silverlight yet though.
Sunday, March 01, 2009
Application Architecture Guide 2.0
I am currently reading Application Architecture Guide 2.0 I wouldn't say that this is a revolutionary document, but I enjoy reading. I find it very aligned with the way I see the subject, and as it is often the case, it helps me organize my thoughts by putting everything into it's place.
One of the things I would recommend this paper for is it's not just theory or collection of "design patterns". With all my respect for the latter, many authors just abuse the term and sound very far from real world of day-to-day developers. Here I find some practical advices, key points that should not be missed when creating application architecture and common mistakes. There is also understanding of the real world by acknowledgment that development became "agile". And again, the term is not abused.
The volume is quite big, and there are many repetitions, so I just somewhere in the first quarter of the document. Hopefully the last three quarters will be as good as first one.
Binding to nullable values (WPF)
I don't usually use nullable types, since my approach is to use them only when there is real difference between zero and null values, and it's not often when such difference exists. However, sometimes you may not really know how the value is going to be used. And then having it nullable may be preferable.
That was the case in one of our custom projects. Naturally, you would want to display empty edit box for null value, which was defined as nullable integer. The problem is that by default binding would not handle empty string as null value. Fortunately, with .NET 3.5 SP1 there is a way. You should use TargetNullValue attribute. The binding would look like this then:
{Binding Path=Customer.ClientYear, TargetNullValue={x:Static sys:String.Empty}}
This, and other attributes for the binding collected in one document here