<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Danny Thorpe &#187; Programming</title>
	<atom:link href="http://dannythorpe.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://dannythorpe.com</link>
	<description>Dream &#38; Deliver</description>
	<lastBuildDate>Wed, 18 Jan 2012 00:24:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Java WS-Policy UsingAddressing Warning When Calling .NET WCF Web Service</title>
		<link>http://dannythorpe.com/2012/01/04/java-wcf-usingaddressing-warning/</link>
		<comments>http://dannythorpe.com/2012/01/04/java-wcf-usingaddressing-warning/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 21:19:30 +0000</pubDate>
		<dc:creator>Danny Thorpe</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jax-ws]]></category>
		<category><![CDATA[metro]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsdl]]></category>

		<guid isPermaLink="false">http://dannythorpe.com/?p=374</guid>
		<description><![CDATA[Create a Web Service with .NET WCF. Plink, plink, done. Create a simple Java client to call that web service. Using the default Java SE 7u2 SDK + runtime downloadable from Oracle, you run wsimport to import the service WSDL and generate proxy classes. You write a little code to instantiate the service class and <a href='http://dannythorpe.com/2012/01/04/java-wcf-usingaddressing-warning/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Create a Web Service with .NET WCF. Plink, plink, done.</p>
<p>Create a simple Java client to call that web service. Using the default Java SE 7u2 SDK + runtime downloadable from Oracle, you run wsimport to import the service WSDL and generate proxy classes. You write a little code to instantiate the service class and call the service, run the app, and see the output from the successful web service call. Done! Well, not exactly.</p>
<p>When you run the Java client console app, the calls to the web service work but are accompanied by rather nasty sounding warnings about unknown policy requirements.</p>
<pre>Jan 04, 2012 12:10:46 PM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives
WARNING: WSP0075: Policy assertion "{http://www.w3.org/2006/05/addressing/wsdl}UsingAddressing" was evaluated as "UNKNOWN".
Jan 04, 2012 12:10:46 PM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives
WARNING: WSP0019: Suboptimal policy alternative selected on the client side with fitness "UNKNOWN"</pre>
<p>How do we get rid of those warnings? There are certainly ways to suppress warning reports, but that&#8217;s not the right solution. The better question is how do we resolve the issue reported in the warning?</p>
<p>After a great deal of digging around, here&#8217;s what I&#8217;ve found:</p>
<ol>
<li>WCF defaults to placing a <strong>wsaw:UsingAddressing</strong> WS-Policy assertion in your web service WSDL.<strong></strong></li>
<li><strong>wsaw:UsingAddressing</strong> is not actually part of any SOAP standard, it&#8217;s some sort of WSDL extension to cover the gap until an official SOAP WS-Policy standard could be defined later.</li>
<li>Microsoft WCF supports <strong>wsaw:UsingAddressing</strong>.</li>
<li>Java&#8217;s JAX-WS reference implementation web service core framework (JAX-WS RI 2.2.4-b01) bundled with the JDK does <strong>not</strong> support <strong>wsaw:UsingAddressing</strong>. The rationalization seems to be that wsaw:UsingAddressing isn&#8217;t part of the WS-Policy spec, so &#8220;not our problem&#8221;. JAX-WS RI supports <strong>wsam:Addressing</strong> from the official WS-Policy spec<strong></strong>.</li>
<li>This isn&#8217;t just Java folks thumbing their noses at Microsoft. This also <a href="http://java.net/jira/browse/JAX_WS-852">causes interop problems with Java web service frameworks</a> that support and use <strong>wsaw:UsingAddressing</strong>.</li>
<li><a href="http://metro.java.net/">Java Metro</a> is another web service framework, and one which does support <strong>wsaw:UsingAddressing</strong>. Metro is the result of Sun and Microsoft working together to resolve cross-platform web service interop issues.</li>
<li>Metro is easy enough to download, but how do you use it? Documentation is all about how to install Metro into an application server environment. Many app developers have asked &#8220;<a href="http://metro.1045641.n5.nabble.com/Client-generated-by-wsimport-not-using-WS-Addressing-when-connecting-to-WCF-td1065818.html">How do I use Metro in my Java client?&#8221;</a></li>
</ol>
<p>As it turns out, Metro appears to do all of its magic at runtime. There is no IDE integration at all. All you need to do is reference the Metro .jar files in your Java project and the WS-Policy warnings will go away.</p>
<p>In the NetBeans IDE, this means adding each of the .jar files from the Metro/lib directory to the Libraries node in your Java project. Make sure they appear before the JDK reference. Make sure you select the actual .jar files, not just the Metro/lib directory.</p>
<p>In the IntelliJ IDE, this means:</p>
<ol>
<li>Right click on the JDK node under &#8220;External Libraries&#8221; in the project tree</li>
<li>Click &#8220;Open Library Settings&#8221;</li>
<li>Click &#8220;Libraries&#8221; under &#8220;Project Settings&#8221;</li>
<li>Click the New Project Library tool button</li>
<li>Click &#8220;Java&#8221;</li>
<li>Select the Metro/lib subdir in the &#8220;Select Library Files&#8221; path selector dialog.</li>
</ol>
<p>Note that in NetBeans, you have to select the actual .jar files; selecting only the Metro/lib directory won&#8217;t work in NetBeans.  Selecting only the Metro/lib directory works fine in IntelliJ.</p>
<p>To solve this UsingAddressing policy issue from the Java client end, use the Metro libraries. Period.</p>
<p>Another way to solve this interop issue would be to address the service end: Add <strong>wsam:Addresssing</strong> as an acceptable alternative to <strong>wsaw:UsingAddressing</strong> in the web service&#8217;s WSDL. With both addressing policies as siblings under an <strong>&lt;ExactlyOne&gt;</strong> element, clients that support <strong>wsaw:UsingAddressing</strong> will be happy and clients that support only <strong>wsam:Addressing</strong> will be happy. In theory, anyway.</p>
<p>However, I have yet to figure out how to add <strong>wsam:Addressing</strong> to the WSDL generated by a WCF service. Since I have a client-side solution I won&#8217;t be pursuing this further, but if anyone can provide a link to how to do this on the WCF WSDL side, I&#8217;d love to see that solution as well.</p>
<div style="text-align:center;width:100%;"><div style="margin:0px 0px 0px 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-0861479594738165";
/* End of Post */
google_ad_slot = "6510912161";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></div><p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fdannythorpe.com%2F2012%2F01%2F04%2Fjava-wcf-usingaddressing-warning%2F&amp;counturl=http%3A%2F%2Fdannythorpe.com%2F2012%2F01%2F04%2Fjava-wcf-usingaddressing-warning%2F&amp;count=none&amp;text=Java%20WS-Policy%20UsingAddressing%20Warning%20When%20Calling%20.NET%20WCF%20Web%20Service" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fdannythorpe.com%2F2012%2F01%2F04%2Fjava-wcf-usingaddressing-warning%2F&amp;counturl=http%3A%2F%2Fdannythorpe.com%2F2012%2F01%2F04%2Fjava-wcf-usingaddressing-warning%2F&amp;count=none&amp;text=Java%20WS-Policy%20UsingAddressing%20Warning%20When%20Calling%20.NET%20WCF%20Web%20Service" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fdannythorpe.com%2F2012%2F01%2F04%2Fjava-wcf-usingaddressing-warning%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fdannythorpe.com%2F2012%2F01%2F04%2Fjava-wcf-usingaddressing-warning%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdannythorpe.com%2F2012%2F01%2F04%2Fjava-wcf-usingaddressing-warning%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdannythorpe.com%2F2012%2F01%2F04%2Fjava-wcf-usingaddressing-warning%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdannythorpe.com%2F2012%2F01%2F04%2Fjava-wcf-usingaddressing-warning%2F&amp;title=Java%20WS-Policy%20UsingAddressing%20Warning%20When%20Calling%20.NET%20WCF%20Web%20Service" id="wpa2a_4">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://dannythorpe.com/2012/01/04/java-wcf-usingaddressing-warning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Databinding Collection Properties</title>
		<link>http://dannythorpe.com/2011/06/09/databinding-collection-properties/</link>
		<comments>http://dannythorpe.com/2011/06/09/databinding-collection-properties/#comments</comments>
		<pubDate>Thu, 09 Jun 2011 19:22:06 +0000</pubDate>
		<dc:creator>Danny Thorpe</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[databinding]]></category>
		<category><![CDATA[IList]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://dannythorpe.com/?p=324</guid>
		<description><![CDATA[Ah, WPF.  You&#8217;ve dotted your tees and crossed your eyes and your data bound control is still not showing any data from your collection.  You set a breakpoint in the property getter that is providing the collection data, the breakpoint gets hit and returns your data, but the data doesn&#8217;t appear at the other end <a href='http://dannythorpe.com/2011/06/09/databinding-collection-properties/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Ah, WPF.  You&#8217;ve dotted your tees and crossed your eyes and your data bound control is still not showing any data from your collection.  You set a breakpoint in the property getter that is providing the collection data, the breakpoint gets hit and returns your data, but the data doesn&#8217;t appear at the other end of the binding pipeline, in the databound control.  You check the Output debug window in VS to see what data binding error messages might be found there, but there are none.  What&#8217;s going on?</p>
<p>The problem is that the data collection you&#8217;re returning doesn&#8217;t meet WPF&#8217;s data binding requirements, so WPF ignores the binding expression and goes on its merry way. I can understand why WPF doesn&#8217;t throw an exception for this situation, but could we at least get an error message logged to the Output window like other data binding errors?</p>
<p>For collection properties to work on WPF controls in XAML markup, XAML requires that the collection object instance implement the IList interface.  That means the data collection you&#8217;re binding to that property needs to implement IList also.</p>
<p>If your data collection is an <strong>IEnumerable</strong>, such as data returned by a <strong>yield return</strong> iterator, your control will display no data at runtime and you&#8217;ll see no error messages.</p>
<p>If your data collection implements <strong>IList&lt;T&gt;</strong>, your control will display no data at runtime and you&#8217;ll see no error messages.  A class that implements <strong>IList&lt;T&gt;</strong> does not automatically support <strong>IList</strong>.</p>
<p>If your data collection is a <strong>Dictionary&lt;K,V&gt;</strong>, you can data bind to the dictionary&#8217;s <strong>Values</strong> collection property, which implements <strong>IList&lt;T&gt;</strong>.  You can probably guess where this is going&#8230;  The dictionary&#8217;s values collection type implements <strong>IList&lt;T&gt;</strong>, but not <strong>IList</strong>.  Your control will display no data at runtime and you&#8217;ll see no error messages.</p>
<p>Note that the type of the property that is providing the data collection is more or less immaterial.  What matters is whether the object that property returns implements <strong>IList</strong>.  WPF/XAML will query at runtime for the <strong>IList</strong> interface on whatever object is returned by the data bound source property.</p>
<p><strong>List&lt;T&gt;</strong>, <strong>Collection&lt;T&gt;</strong>, and <strong>ObservableCollection&lt;T&gt;</strong> all implement <strong>IList</strong>, so if you&#8217;re using these as your underlying storage class you&#8217;re good to go.  If your underlying storage is anything else, you probably have some work to do.</p>
<p>In the <strong>Dictionary&lt;K,V&gt;.Values</strong> case, one simple solution is to return <strong>Values.ToList().</strong> The List object returned implements <strong>IList</strong> so you&#8217;re good to go.</p>
<p>Before putting that code to bed, though, give some thought to the performance implications: <strong>ToList()</strong> will create a new list of references to all the data in the dictionary Values collection, and it will do that every time anything fetches the property value. The memory consumption is proportional to the number of items in the dictionary, but not to the size of those objects.  The objects in the dictionary are not copied, the list just contains references to the objects (as does the dictionary).</p>
<p>For a small collection of a few hundred entries or less, this is probably no big deal.  For a large collection with tens of thousands of items or more, creating a new list of N object references every time the property is fetched is probably not a good idea.</p>
<p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F06%2F09%2Fdatabinding-collection-properties%2F&amp;counturl=http%3A%2F%2Fdannythorpe.com%2F2011%2F06%2F09%2Fdatabinding-collection-properties%2F&amp;count=none&amp;text=Databinding%20Collection%20Properties" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F06%2F09%2Fdatabinding-collection-properties%2F&amp;counturl=http%3A%2F%2Fdannythorpe.com%2F2011%2F06%2F09%2Fdatabinding-collection-properties%2F&amp;count=none&amp;text=Databinding%20Collection%20Properties" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F06%2F09%2Fdatabinding-collection-properties%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F06%2F09%2Fdatabinding-collection-properties%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdannythorpe.com%2F2011%2F06%2F09%2Fdatabinding-collection-properties%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdannythorpe.com%2F2011%2F06%2F09%2Fdatabinding-collection-properties%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdannythorpe.com%2F2011%2F06%2F09%2Fdatabinding-collection-properties%2F&amp;title=Databinding%20Collection%20Properties" id="wpa2a_8">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://dannythorpe.com/2011/06/09/databinding-collection-properties/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Weird Errors With EF4 CTP5 Code First? Close All Database Connections</title>
		<link>http://dannythorpe.com/2011/02/18/weird-errors-with-ef4-ctp5-code-first-close-all-database-connections/</link>
		<comments>http://dannythorpe.com/2011/02/18/weird-errors-with-ef4-ctp5-code-first-close-all-database-connections/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 04:51:26 +0000</pubDate>
		<dc:creator>Danny Thorpe</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code First]]></category>
		<category><![CDATA[CTP5]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false">http://dannythorpe.com/?p=307</guid>
		<description><![CDATA[I&#8217;ve been exploring the recent CTP5 release of .NET Entity Frameworks 4.0.  I find the advancements in the &#8220;Code First&#8221; model of entity modeling encouraging, though I am a little concerned about discoverability.  If things just magically happen when you name your properties just the right way, how will you know how to diagnose and <a href='http://dannythorpe.com/2011/02/18/weird-errors-with-ef4-ctp5-code-first-close-all-database-connections/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been exploring the recent CTP5 release of .NET Entity Frameworks 4.0.  I find the advancements in the &#8220;Code First&#8221; model of entity modeling encouraging, though I am a little concerned about discoverability.  If things just magically happen when you name your properties just the right way, how will you know how to diagnose and fix it when the magic smoke leaks out?</p>
<p>(You do know that computers run on smoke, right?  &#8216;Cause if you let the smoke out, the computer don&#8217;t work no more!)</p>
<p>My experiments with Code First took a turn for the worse today as my test app deteriorated from working nicely to failing with murky error messages that seemed to have little to do with the source code changes I just made. How am I supposed to figure this stuff out if they keep rearranging the maze?</p>
<p>I had configured my domain service to always drop the database tables and reset the tables with test data (using DropCreateDatabaseAlways)  whenever the entity model changed. I knew I would be making lots of changes to the model/schema, so might as well just wipe the slate clean every time.</p>
<p>As the strange failures began to mount, I noticed that sometimes after modifying my POCO entity classes (and therefore changing the entity model) running the test app did not hit my breakpoints in the context&#8217;s OnModelCreating or the initializer&#8217;s Seed methods.</p>
<p>To figure out what I had changed to cause all this pain, I started commenting out non-essential parts of the POCO classes, eliminating associations and composite keys and so forth.  The weird failures continued.  The failures weren&#8217;t even consistent &#8211; sometimes the client app would run once just fine and create all the tables it needed, then fail mysteriously with an invalid metadata error on the second run or when the page was refreshed.  Sometimes the first run didn&#8217;t even survive the first web request data query.</p>
<p>By the time I had whittled the POCO classes down to a single class with no inheritance and no associations and still had the client fail, I decided it was time to take a lunch break.  It didn&#8217;t matter what time it was, I needed to put it aside, leave it alone for awhile so I could make a fresh start later.</p>
<p>When I came back from my lunch break there was an error message box on the screen that I hadn&#8217;t seen before.  It said the database could not be dropped because it was in use by another client.  I had left the debugger paused at a breakpoint in the test app and it had trapped this exception some time after I had left my desk.</p>
<p>After a moment of head scratching, I realized the other database client was the Server View in Visual Studio that I was using to inspect the tables created by EF to see how my changes to the POCO entities affected the SQL schema.  Close the database connection in VS, restart the app and poof! Everything worked as it should.  It even worked twice in a row, which at that point was a new record for the day.</p>
<p>What was happening was the domain service in my test app was actually attempting to drop the tables from the database and build everything anew, but Visual Studio&#8217;s open connection to the SQLExpress service was blocking the drop action. Apparently, dropping the tables is a asynchronous action with a very long timeout interval.  The client would make its first request for data, the domain service would receive the request and fire up the DbContext, realize that the model and database needed to be regenerated, and issue the database drop and create operation.</p>
<p>The drop and create didn&#8217;t complete immediately, but apparently other activities proceeded asynchronously and began to fail because the schema found in the database didn&#8217;t match the expected schema.  I would see these bizarre failure error messages while stepping through the domain service code as part of the initial data request.  What I didn&#8217;t see was the root cause &#8211; the drop tables failure &#8211; because it didn&#8217;t fail until long after I had killed the test app and gone back to wondering what I was doing wrong in my source code.</p>
<p>So, simple solution: Always close any open connections in the Server Explorer before running an app that will drop tables.</p>
<h4>This is not the error you&#8217;re looking for</h4>
<p>Another tip for working with Code First Entities:  if you get a compile error about &#8220;You can&#8217;t use this entity in a method of your domain service class because it has not been exposed in your DbContext&#8221;, but you look at your DbContext class and you can see you most certainly have exposed that entity as a DbSet&lt;class&gt; property, here&#8217;s what you do:  Ignore the error message.  It&#8217;s a red herring. Instead, go check that your entity class explicitly designates a property as the primary key, using the [Key] attribute.  Fluid API calls to define a key in OnModelCreate won&#8217;t do &#8211; VS will only be satisfied by a Key attribute.</p>
<p>I don&#8217;t claim to know why, but after a day of permutations and combinations, this is what I found cleared the problem for me.</p>
<p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F02%2F18%2Fweird-errors-with-ef4-ctp5-code-first-close-all-database-connections%2F&amp;counturl=http%3A%2F%2Fdannythorpe.com%2F2011%2F02%2F18%2Fweird-errors-with-ef4-ctp5-code-first-close-all-database-connections%2F&amp;count=none&amp;text=Weird%20Errors%20With%20EF4%20CTP5%20Code%20First%3F%20Close%20All%20Database%20Connections" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F02%2F18%2Fweird-errors-with-ef4-ctp5-code-first-close-all-database-connections%2F&amp;counturl=http%3A%2F%2Fdannythorpe.com%2F2011%2F02%2F18%2Fweird-errors-with-ef4-ctp5-code-first-close-all-database-connections%2F&amp;count=none&amp;text=Weird%20Errors%20With%20EF4%20CTP5%20Code%20First%3F%20Close%20All%20Database%20Connections" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F02%2F18%2Fweird-errors-with-ef4-ctp5-code-first-close-all-database-connections%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F02%2F18%2Fweird-errors-with-ef4-ctp5-code-first-close-all-database-connections%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdannythorpe.com%2F2011%2F02%2F18%2Fweird-errors-with-ef4-ctp5-code-first-close-all-database-connections%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdannythorpe.com%2F2011%2F02%2F18%2Fweird-errors-with-ef4-ctp5-code-first-close-all-database-connections%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdannythorpe.com%2F2011%2F02%2F18%2Fweird-errors-with-ef4-ctp5-code-first-close-all-database-connections%2F&amp;title=Weird%20Errors%20With%20EF4%20CTP5%20Code%20First%3F%20Close%20All%20Database%20Connections" id="wpa2a_12">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://dannythorpe.com/2011/02/18/weird-errors-with-ef4-ctp5-code-first-close-all-database-connections/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Error Using Visual Studio XSD.EXE Utility</title>
		<link>http://dannythorpe.com/2011/01/13/visual-studio-xsd-error/</link>
		<comments>http://dannythorpe.com/2011/01/13/visual-studio-xsd-error/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 22:04:13 +0000</pubDate>
		<dc:creator>Danny Thorpe</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bonehead maneuvers]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[xsd]]></category>

		<guid isPermaLink="false">http://dannythorpe.com/?p=181</guid>
		<description><![CDATA[If you&#8217;re trying to generate classes or a dataset from an XSD schema file using the Visual Studio XSD.EXE command line utility and the only thing you&#8217;re getting out of XSD.EXE is an error message of  Error: There was an error processing 'xyz-schema.xml'.   - DataSet cannot instantiate an abstract ComplexType for the node . <a href='http://dannythorpe.com/2011/01/13/visual-studio-xsd-error/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re trying to generate classes or a dataset from an XSD schema file using the Visual Studio XSD.EXE command line utility and the only thing you&#8217;re getting out of XSD.EXE is an error message of </p>
<pre>Error: There was an error processing 'xyz-schema.xml'.
  - DataSet cannot instantiate an abstract ComplexType for the node .</pre>
<p>Here&#8217;s your solution:  <strong>Rename your schema file from *.xml to *.xsd</strong>.</p>
<p>When you give XSD an input file with a .xml extension, it assumes you want to infer schema from data found in the xml file.  If what you really want is for XSD to read the schema from the input file, the input file has to have a file extension of .xsd.</p>
<p>Since XSD schema is formatted as an XML document, its not uncommon to find XSD schema in files with a .XML extension, especially when downloading from the web.  Just remember to rename them to .xsd before generating classes from them.</p>
<p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F01%2F13%2Fvisual-studio-xsd-error%2F&amp;counturl=http%3A%2F%2Fdannythorpe.com%2F2011%2F01%2F13%2Fvisual-studio-xsd-error%2F&amp;count=none&amp;text=Error%20Using%20Visual%20Studio%20XSD.EXE%20Utility" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F01%2F13%2Fvisual-studio-xsd-error%2F&amp;counturl=http%3A%2F%2Fdannythorpe.com%2F2011%2F01%2F13%2Fvisual-studio-xsd-error%2F&amp;count=none&amp;text=Error%20Using%20Visual%20Studio%20XSD.EXE%20Utility" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F01%2F13%2Fvisual-studio-xsd-error%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fdannythorpe.com%2F2011%2F01%2F13%2Fvisual-studio-xsd-error%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdannythorpe.com%2F2011%2F01%2F13%2Fvisual-studio-xsd-error%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdannythorpe.com%2F2011%2F01%2F13%2Fvisual-studio-xsd-error%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdannythorpe.com%2F2011%2F01%2F13%2Fvisual-studio-xsd-error%2F&amp;title=Error%20Using%20Visual%20Studio%20XSD.EXE%20Utility" id="wpa2a_16">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://dannythorpe.com/2011/01/13/visual-studio-xsd-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Namespaces with LINQ XPathSelectElement</title>
		<link>http://dannythorpe.com/2010/11/12/using-namespaces-with-linq-xpathselectelement/</link>
		<comments>http://dannythorpe.com/2010/11/12/using-namespaces-with-linq-xpathselectelement/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 21:48:17 +0000</pubDate>
		<dc:creator>Danny Thorpe</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XPath]]></category>

		<guid isPermaLink="false">http://dannythorpe.com/?p=166</guid>
		<description><![CDATA[If you do a web search for how to use the LINQ XPathSelectElement function, the example code you will find falls into two categories:  Those that don&#8217;t use namespaces at all, and those that use the same namespace prefix in the query as in the original document. Using no XML namespace at all when querying <a href='http://dannythorpe.com/2010/11/12/using-namespaces-with-linq-xpathselectelement/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>If you do a web search for how to use the LINQ XPathSelectElement function, the example code you will find falls into two categories:  Those that don&#8217;t use namespaces at all, and those that use the same namespace prefix in the query as in the original document.</p>
<p>Using no XML namespace at all when querying XML just doesn&#8217;t fly in the real world.  If you&#8217;re using any XML spec that isn&#8217;t your own, you will need to use namespaces to make sure the XYZ element you get back from the query is the brand or flavor of XYZ that you intended.  If you&#8217;re writing your own XML document schema, it&#8217;s critical to declare your namespaces!</p>
<p>The most nonintuitive aspect of working with XML is realizing that default namespaces are namespaces too, and apply to everything in the document or subtree that doesn&#8217;t have an explicit namespace.  Even though your XML document uses nice clean simple XYZ elements everywhere, if you try to query for XYZ using XPath you&#8217;ll get nothing but nulls back.  Your XYZ elements are under a default namespace in the document, so XPath will only return matches if you specify namespaces in your query as well.</p>
<p>What really kills me is when the sample code for making an XPath query using namespaces uses the same namespace prefix in the query as in the original XML document.  This gives the reader the impression that the namespace prefix strings in their queries have to match the original document.  That&#8217;s completely false.  The text of the prefix string is completely irrelevant &#8211; all that matters is what URI the prefix string represents, and that the URI of the namespace used in your query matches the URI of the namespace used in the XML document.</p>
<p>Take this C# example code offered up on none other than the <a href="http://msdn.microsoft.com/en-us/library/bb351355.aspx">MSDN documentation for XPathSelectElement</a>:</p>
<pre class="brush: csharp; highlight: [2,3,4,5,10,11]; title: ; notranslate">
string markup = @&quot;
&lt;aw:Root xmlns:aw='http://www.adventure-works.com'&gt;
    &lt;aw:Child1&gt;child one data&lt;/aw:Child1&gt;
    &lt;aw:Child2&gt;child two data&lt;/aw:Child2&gt;
&lt;/aw:Root&gt;&quot;;
XmlReader reader = XmlReader.Create(new StringReader(markup));
XElement root = XElement.Load(reader);
XmlNameTable nameTable = reader.NameTable;
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(nameTable);
namespaceManager.AddNamespace(&quot;aw&quot;, &quot;http://www.adventure-works.com&quot;);
XElement child1 = root.XPathSelectElement(&quot;./aw:Child1&quot;, namespaceManager);
Console.WriteLine(child1);
</pre>
<p>The &#8220;aw&#8221; namespace prefix used in the calls to AddNamespace and XPathSelectElement doesn&#8217;t need to match the &#8220;aw&#8221; prefix used in the original document.  The URI that the prefixes are associated with need to match, but that is all.</p>
<p>Here&#8217;s the sample again using different prefix strings:</p>
<pre class="brush: csharp; highlight: [10,11]; title: ; notranslate">
string markup = @&quot;
&lt;aw:Root xmlns:aw='http://www.adventure-works.com'&gt;
    &lt;aw:Child1&gt;child one data&lt;/aw:Child1&gt;
    &lt;aw:Child2&gt;child two data&lt;/aw:Child2&gt;
&lt;/aw:Root&gt;&quot;;
XmlReader reader = XmlReader.Create(new StringReader(markup));
XElement root = XElement.Load(reader);
XmlNameTable nameTable = reader.NameTable;
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(nameTable);
namespaceManager.AddNamespace(&quot;ns&quot;, &quot;http://www.adventure-works.com&quot;);
XElement child1 = root.XPathSelectElement(&quot;./ns:Child1&quot;, namespaceManager);
Console.WriteLine(child1);
</pre>
<p>This second code snippet executes exactly the same as the first, but in my opnion is much clearer as to what&#8217;s going on because it doesn&#8217;t imply that the prefix strings must match in order for the query to work.</p>
<p>Why is this important?  Because when you&#8217;re processing an XML document, you usually know at compile time what namespace(s) you&#8217;re interested in working with elements of.  Just bind the URI of the namespace you care about to whatever prefix string you want and use that prefix string in your queries.  XPathSelectElement will figure out the mapping between your prefix string in the scope of your query and the equivalent prefix string in the scope of the XML document.</p>
<p>You don&#8217;t have to care what namespace prefix the document creator used to write the XML document, and you really don&#8217;t want to have to parse the XML document just to figure out what prefix string is bound to the namespace URI you care about.</p>
<p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fdannythorpe.com%2F2010%2F11%2F12%2Fusing-namespaces-with-linq-xpathselectelement%2F&amp;counturl=http%3A%2F%2Fdannythorpe.com%2F2010%2F11%2F12%2Fusing-namespaces-with-linq-xpathselectelement%2F&amp;count=none&amp;text=Using%20Namespaces%20with%20LINQ%20XPathSelectElement" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fdannythorpe.com%2F2010%2F11%2F12%2Fusing-namespaces-with-linq-xpathselectelement%2F&amp;counturl=http%3A%2F%2Fdannythorpe.com%2F2010%2F11%2F12%2Fusing-namespaces-with-linq-xpathselectelement%2F&amp;count=none&amp;text=Using%20Namespaces%20with%20LINQ%20XPathSelectElement" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fdannythorpe.com%2F2010%2F11%2F12%2Fusing-namespaces-with-linq-xpathselectelement%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fdannythorpe.com%2F2010%2F11%2F12%2Fusing-namespaces-with-linq-xpathselectelement%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdannythorpe.com%2F2010%2F11%2F12%2Fusing-namespaces-with-linq-xpathselectelement%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdannythorpe.com%2F2010%2F11%2F12%2Fusing-namespaces-with-linq-xpathselectelement%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdannythorpe.com%2F2010%2F11%2F12%2Fusing-namespaces-with-linq-xpathselectelement%2F&amp;title=Using%20Namespaces%20with%20LINQ%20XPathSelectElement" id="wpa2a_20">Share/Bookmark</a></p>]]></content:encoded>
			<wfw:commentRss>http://dannythorpe.com/2010/11/12/using-namespaces-with-linq-xpathselectelement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  dannythorpe.com/category/programming/feed/ ) in 0.40424 seconds, on Feb 4th, 2012 at 7:08 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 4th, 2012 at 8:08 am UTC -->
