Welcome to MSDN Blogs Sign in | Join | Help

Visual Studio 2010 and .Net 4 Release Candidate

Yesterday the release candidate for Visual Studio 2010 and .Net 4 was released to MSDN subscribers. By tomorrow the release should be broadly available to anyone that wants to download it. When trying out the release candidate you should first uninstall any previous beta versions.

The major focus of the release candidate is Visual Studio performance. Jason Zander has a Channel 9 video covering the release candidate changes. However, you'll also be able to try out all of the bug fixes in the framework that didn't make it into the last beta release.

After trying out the release candidate there's another survey to collect feedback about some of the changes.

Posted by Nicholas Allen | 0 Comments
Filed under: , ,

ASP.NET MVC 2 Release Candidate 2

The ASP.NET MVC team has released a potentially final release candidate for ASP.NET MVC 2. MVC is a model-view-controller framework on top of the existing ASP.NET runtime that separates display and application logic as well as makes test-driven development of ASP.NET applications easier. MVC could be used with a variety of types of web applications but is frequently associated with REST applications.

The significant change in the second release candidate deals with the behavior of property validation to expand the number of conditions under which validation is performed. The release notes describe this change along with the other improvements and bug fixes in the release candidate.

Posted by Nicholas Allen | 0 Comments
Filed under: ,

Moonlight 3 Preview

Moonlight, the Linux version of Silverlight, has produced its first preview release of Moonlight 3. You may recall that in the recent Moonlight 2 release they shipped both their equivalent of Silverlight 2 as well as a number of features from Silverlight 3 (such as out of browser support). This preview of Moonlight 3 focuses on supporting a greater array of Silverlight 3 features.

You can get the Moonlight 3 preview as either binaries or source code.

Posted by Nicholas Allen | 2 Comments
Filed under: ,

Fix to Allow an Encoder Fallback with UTF8

This week I'll be running a series covering fixes for WCF that may be hard to find and explaining the details behind each problem.

Encoding is the process of transforming a set of characters into a sequence of bytes. An encoder fallback is an error-handling mechanism invoked when a character can't be fully converted or represented. Similarly, decoding is the process of transforming a sequence of bytes into a set of characters and a decoder fallback is an error-handling mechanism invoked during that process.

Two standard encoder fallback implementations are to throw an exception when an input character cannot be encoded, called an exception fallback, and to substitute a sequence of characters in place of an input character that cannot be encoded, called a replacement fallback. You can write your own fallback implementation and configure these fallbacks as part of defining the character encoding.

The original code for the WCF text encoder didn't preserve the configured fallback when the character set was UTF8. The UTF8 encoding web name was special cased as part of an optimization. Since the default encoder fallback implementation was an exception fallback, an exception would always be thrown for unconvertible characters regardless of the fallback implementation configured.

After installing this fix you're able to customize the fallback implementation even when using the UTF8 character set with the text encoding.

This fix is available for download from KB article 967090.

Posted by Nicholas Allen | 0 Comments
Filed under: ,

Fix for Partially Trusted Clients using Windows Authentication

This week I'll be running a series covering fixes for WCF that may be hard to find and explaining the details behind each problem.

Connection sharing is a performance optimization to pool HTTP connections between multiple calls. Ordinarily, connections are not allowed to be shared if they use Windows authentication to identify the caller. WCF uses an option on HttpWebRequest called UnsafeAuthenticatedConnectionSharing to override this restriction. Instead, connection groups are established using the credential as part of the identifier of the group so that callers with the same credentials can share a connection.

A client with restricted permissions may not be allowed to set the UnsafeAuthenticatedConnectionSharing setting. This causes a security exception to be thrown when the setting is accessed, preventing the request from being made. You're encountering this problem if you see the following exception.

System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission' failed.
System.Net.HttpWebRequest.set_UnsafeAuthenticatedConnectionSharing(Boolean value)
System.ServiceModel.Channels.HttpChannelFactory.GetConnectionGroupName(HttpWebRequest httpWebRequest, NetworkCredential credential, AuthenticationLevel authenticationLevel, TokenImpersonationLevel impersonationLevel, SecurityTokenContainer clientCertificateToken)
System.ServiceModel.Channels.HttpChannelFactory.GetWebRequest(EndpointAddress to, Uri via, NetworkCredential credential, TokenImpersonationLevel impersonationLevel, AuthenticationLevel authenticationLevel, SecurityTokenProviderContainer proxyTokenProvider, SecurityTokenContainer clientCertificateToken, TimeSpan timeout)

The fix catches the security exception so that the call can continue without the optimization to share connections. If an attempt to set UnsafeAuthenticatedConnectionSharing fails, then the channel factory will never try to set this setting again for later requests as well.

This fix is available for download from KB article 959546.

Posted by Nicholas Allen | 0 Comments
Filed under: , ,

Fix to Allow Customizing the Status Code when Validation Fails

This week I'll be running a series covering fixes for WCF that may be hard to find and explaining the details behind each problem.

This next fix is actually to add a new feature when writing a UserNamePasswordValidator.

A UserNamePasswordValidator gives you a callback method called Validate that takes user name and password parameters supplied by the client. If you decide that the user name and password don't pass validation, then you can throw an exception out of the Validate method to reject the client's message. When using the HTTP transport, the error message sent back after the UserNamePasswordValidator has a status code 403 Forbidden.

After installing this fix you're able to customize the status code that is sent back. To do so, add an object to the exception's data collection with the key HttpStatusCode. The value has to be an instance of the HttpStatusCode class or else it will be ignored. The type of the exception doesn't matter.

For example, to set the status code to 401 Unauthorized, here is the code you would write before throwing the exception.

exception.Data["HttpStatusCode"] = HttpStatusCode.Unauthorized;

This fix is available for download from KB article 957911.

Fix for Exception Reading Typed Headers

This week I'll be running a series covering fixes for WCF that may be hard to find and explaining the details behind each problem.

The dispatch operation formatter is the component that deserializes a message into objects. When building the objects out of the message headers in the message, the implementation of the operation formatters for XmlSerializer and DataContractSerializer uses an internal class called TypedHeaderManager. A TypedHeaderManager is created for each seen content type and then cached to make the object creation process faster in the future.

The cache for TypedHeaderManager objects uses a reader-writer lock to improve concurrency. After the first few messages it should be increasingly rare to need to add items to the cache, making most accesses be reads rather than writes. The cache is first tested under the reader lock for an instance of TypedHeaderManager. The writer lock is acquired if an instance didn't exist for the seen content type to add the entry.

The original code didn't check whether some other thread created a TypedHeaderManager instance for the same type while the writer lock was being acquired. This can happen if multiple messages using a particular header type for the first time arrive at nearly the same time. You're encountering this problem if you see the following exception.

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at System.ServiceModel.TypedHeaderManager.GetTypedHeaderManager(Type t)

This is an example where double-checked locking was intended but implemented incorrectly.

A fix for this problem was in the Application Compatibility Update for .Net 3.5 Service Pack 1.

Full and Partial Profiles

What is the difference between the client and full framework profiles? Which one should I target?

The use of profiles has changed considerably from .Net 3.5 to .Net 4. In .Net 3.5 a client profile was introduced for Windows XP to be able to have a small web download that could run many applications that depended on new framework features. The full download of .Net 3.5 was very large. In .Net 4 the client profile is a more deliberate factoring of the framework into two pieces.

The client profile component is sufficient to run most applications. The features not included in the client profile are for programming ASP.NET applications, development tools, and libraries that have been deprecated. ASP.NET application development includes the IIS hosting and some of the REST components of WCF.

The extended component contains the remainder of the framework features. The full profile corresponds to having both the client profile component and extended component installed. Since the client profile component contains most of the features in the framework, the client profile is only marginally smaller than the full framework. However, both profiles are much smaller than .Net 3.5.

The client profile will be more broadly deployed so you should target that if possible. Client applications should have no problems with the client profile while a portion of service applications will need to require the full profile.

Posted by Nicholas Allen | 2 Comments
Filed under: , , ,

Data Services Update Re-Released

The December update to .Net Framework 3.5 SP1 data services has been re-released after addressing some issues with the original version. Data Services are REST-based web services that expose a data model that can be consumed by web clients. Data Services use URIs to address data from a storage system and supports a variety of formats for representing that data, such as JSON or ATOM. The update adds a number of new features, all of which will also be available in WCF Data Services for .Net 4.

Posted by Nicholas Allen | 0 Comments
Filed under: ,

Warming a Cold Pool

The thread pool for asynchronous IO threads attempts to automatically regulate the number of idle threads to balance the resource consumption of threads with the responsiveness of servicing tasks. When there is not much work to be done, idle threads are spun down. When a surge of work comes in, new threads are spun up. There are limits on the minimum number of threads, maximum number of threads, the rate at which threads are created, and so on to smooth out this behavior.

The minimum number of threads exists to allow the system to carry some idle capacity. Tasks ordinarily run on the CPU for only a short time after the IO operation completes so the near-term capacity of the system is roughly the number of truly idle threads plus the number of currently-working threads. However, if the system goes idle except for a few very long running tasks, then those long running tasks may occupy the minimum number of threads without actually providing any idle capacity. For example, WCF has a timer system that runs on an IO thread for a long period of time.

If there are no excess threads and it's unlikely for a long running task to complete at the right moment for a thread to be reused, then this causes the same performance problems as a cold start. Running a dummy task is a way to keep the thread pool warm in excess of the minimum number of threads by generating currently-working threads that are available for reuse essentially immediately.

Overlapped o = new Overlapped();
NativeOverlapped* po = null;
IOCompletionCallback c = (x, y, z) =>
{
Overlapped.Unpack(po);
Overlapped.Free(po);
};
po = o.Pack(c, null);
ThreadPool.UnsafeQueueNativeOverlapped(po);

The use of a dummy task is an example of altering a heuristic behavior when you've got better predictive knowledge than available to the heuristic. This can be dangerous though if you don't review what's been done when the heuristic changes or your prediction stops being accurate.

Posted by Nicholas Allen | 0 Comments
Filed under: ,

Domain Services with WCF RIA Services Introduction

Early documentation is available of a walkthrough for building a domain service using WCF RIA services. A domain service uses application logic running on the server to provide data validation and access control in a way that integrates the service with clients such as Silverlight. This walkthrough demonstrates building a service using ASP.NET data sources to expose content in a database along with page markup for a client to interact with the data.

You can also download the source code used for the walkthrough.

Posted by Nicholas Allen | 0 Comments
Filed under: ,

Debugging References with Graph Visualizations

Chris Lovett has a nice video demonstrating how to debug managed memory leaks by visualizing the runtime object reference graph produced by the gcroot debugger command. The graph visualization may help you spot cycles or other unexpected references that are causing the memory leak faster than reading through the gcroot output. I've seen other suggestions to do this visualization using graphviz, but this is a nice presentations of the approach using the DGML feature of Visual Studio 2010 for describing graphs.

Posted by Nicholas Allen | 0 Comments
Filed under: ,

Fix for HTTP Startup Hang

WCF uses the http.sys kernel-mode http driver on most platforms to receive HTTP messages. The kernel-mode driver allows different services to share the same port for HTTP communication and, when running in IIS, allows messages to be received while the service is dormant.

The http.sys driver is configured to automatically start so that it can begin handling requests. On some systems the http.sys driver can get into a configuration that deadlocks on startup. This causes all of the dependent services using the driver to fail to start.

You might be experiencing this problem if all of the services dependent on the http.sys driver fail to start and running the sc querylock command indicates that the SCM database lock is being held by the NT Service Control Manager forever after starting up the system.

Since one of the other parties in the deadlock appears to be the cryptographic services, adding this dependency explicitly may provide a workaround for the problem. You can do this by running the following command:

sc config http depend= cryptsvc

You need to be an administrator to change the system configuration and the exact spacing in the command is important.

Posted by Nicholas Allen | 1 Comments
Filed under: ,

Fix for Gradual Debugger Slowdown

Visual Studio 2008 added a feature to automatically attach to a service in your solution when the code you're debugging makes a request to that service. By automatically attaching to the service you're able to stop on breakpoints in the service code without having to explicitly step into the other project.

This debugger integration requires tracking the call stacks of running processes. In some cases the debugger fails to clean up these call stacks causing the client to run increasingly slowly over time. You may be encountering this problem if you have a solution containing both the client and service projects, if running in Visual Studio is much slower than running outside of Visual Studio, and if the difference in performance grows continuously worse during a debugging session.

If you're not using the debugger integration feature to automatically attach to the service, you can work around the slowdown for debugging. Visual Studio includes a tool for configuring the debugger integration in %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE called vsdiag_regwcf.

To disable the debugger integration run vsdiag_regwcf -u from the command line. You can restore the debugger integration by running vsdiag_regwcf -i.

This problem is fixed in Visual Studio 2010.

Posted by Nicholas Allen | 0 Comments
Filed under: , ,

Transaction Not Available

Can I run code under a flowed-in transaction from within a message inspector?

The setup work for the service transaction is done shortly before the actual call to the implementation of the service operation. The service transaction is not guaranteed to be available for any of these extensibility points (although for certain kinds of transacted service operations the transaction will be available because it's created much earlier, such as a transacted queue receive):

  • ServiceAuthenticationManager.Authenticate
  • ServiceAuthorizationManager.CheckAccess
  • IDispatchMessageInspector.AfterReceiveRequest

The actual creation of the transaction scope that will be used comes even further after IInstanceProvider.GetInstance.

More Posts Next page »
 
Page view tracker