tag:blogger.com,1999:blog-65416367831750307622024-03-18T23:08:46.880-04:00Coding CrampProgramming the Smart WayAnonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.comBlogger41125tag:blogger.com,1999:blog-6541636783175030762.post-22935930868182405772014-10-11T18:15:00.004-04:002014-10-11T18:15:37.648-04:00Collection was modified; enumeration operation might not execute.<div class="MsoNormal">
<b>Problem:</b></div>
<div style="border: 1pt solid windowtext; padding: 1pt 4pt;">
<div class="MsoNormal" style="border: none; padding: 0in;">
Iterating through a loop of DataTable.Rows and you try and delete a row and get:<br />
<blockquote class="tr_bq">
<span style="font-family: 'Courier New', Courier, monospace;">Collection was modified; enumeration operation might not execute.</span></blockquote>
</div>
<div class="code">
<span class="Statement">foreach</span> (DataRow dr <span class="Statement">in</span> dt.Rows)<br />
{<br />
<span class="Statement">if</span> ((<span class="ValueType">int</span>)dr[<span class="String">"ID"</span>] > 5)<br />
dr.Delete();<br />
}
</div>
</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><br /></b>
<b>Simplest Solution:</b></div>
<div style="border: 1pt solid windowtext; orphans: auto; padding: 1pt 4pt; text-align: start; text-indent: 0px; widows: auto;">
<div class="MsoNormal" style="border: none; padding: 0in;">
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
Don't loop on the original collection of Rows, but instead do a Select("") and pull those DataRows into an Array and loop on that. Now you can Delete() to your heart's content.<br />
<br />
<div class="code">
<span class="Statement">foreach</span> (DataRow dr <span class="Statement">in</span> dt.Select(<span class="String">""</span>))<br />
{<br />
<span class="Statement">if</span> ((<span class="ValueType">int</span>)dr[<span class="String">"ID"</span>] > 5)<br />
dr.Delete();<br />
}
</div>
</div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-transform: none; white-space: normal; word-spacing: 0px;">
<br /></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com3tag:blogger.com,1999:blog-6541636783175030762.post-16096476676616919912014-09-25T17:00:00.000-04:002014-09-25T17:00:00.490-04:00Designing Your Application to be Unit TestableThe easiest way to structure any application so that it is unit testable is to break up the main sections of the work being down into some basic pieces. These are:<br />
<div>
<br />
<ol>
<li>Get your data</li>
<li>Do work with your data</li>
<li>Commit changes to your data</li>
</ol>
</div>
<div>
With this basic application structure you can now separate the pulling and processing of the data. You are in complete control of that data being used by the processing code and can manipulated it as you see fit. It is the ideal structure for unit testable code. </div>
<div>
<br /></div>
<div class="code">
<span class="Modifier">public</span> <span class="ReferenceType">class</span> MyMainWorker<br />
{<br />
<span class="Modifier">public</span> <span class="ValueType">void</span> RunWorker()<br />
{<br />
<span class="InlineComment">// Optional begin your transaction here</span><br />
DataSet ds = GetData();<br />
<span class="ReferenceType">object</span> o = Execute(ds);<br />
<span class="InlineComment">// Begin your transaction</span><br />
SaveData(ds);<br />
<span class="InlineComment">// Commit your transaction</span><br />
}<br />
<br />
<span class="Modifier">private</span> <span class="ValueType">void</span> SaveData(DataSet ds)<br />
{<br />
<span class="Statement">throw</span> <span class="Keyword">new</span> NotImplementedException();<br />
}<br />
<br />
<span class="Modifier">private</span> <span class="ReferenceType">object</span> Execute(DataSet ds)<br />
{<br />
<span class="Statement">throw</span> <span class="Keyword">new</span> NotImplementedException();<br />
}<br />
<br />
<span class="Modifier">private</span> DataSet GetData()<br />
{<br />
<span class="Statement">throw</span> <span class="Keyword">new</span> NotImplementedException();<br />
}<br />
}
</div>
Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com1tag:blogger.com,1999:blog-6541636783175030762.post-26493641470075319492014-09-24T17:00:00.000-04:002014-09-24T17:00:00.431-04:00?? Operator is great for defaulting objects<div>
If you need to default an object, an easy way to do this is with the null-coalescing operator. In this example I need to default MyTempClass if I cannot pull it from another location.<br />
<br /></div>
<div class="code">
<span class="Namespace">using</span> System;<br />
<br />
<span class="Namespace">namespace</span> Tips<br />
{<br />
<span class="Modifier">public</span> <span class="ReferenceType">class</span> NullCoalescingOperator<br />
{<br />
<span class="Modifier">public</span> <span class="ValueType">void</span> RunTip()<br />
{<br />
MyTempClass myTempClass = <span class="Keyword">null</span>;<br />
MyTempClass myOtherTempClass = <span class="Keyword">new</span> MyTempClass()<br />
{<br />
MyProperty = 1<br />
};<br />
MyTempClass x = myTempClass ?? myOtherTempClass;<br />
Console.WriteLine(<span class="String">"{0}"</span>, x.MyProperty);<br />
}<br />
}<br />
<br />
<span class="Modifier">public</span> <span class="ReferenceType">class</span> MyTempClass<br />
{<br />
<span class="Modifier">public</span> <span class="ValueType">int</span> MyProperty { get; set; }<br />
}<br />
}
</div>
Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-15601841104440322132014-09-23T17:00:00.000-04:002014-09-23T17:00:02.523-04:00Building File and Directory PathsI see directory and file concatenation done with string append all too often. There are built in .Net libraries that help you do this so much easier. When you are working with file and directory paths, use System.IO.Path.Combine().
<br />
<div class="code">
<span class="Namespace">using</span> System.IO;<br />
<br />
<span class="Namespace">namespace</span> Tips<br />
{<br />
<span class="ReferenceType">class</span> Program<br />
{<br />
<span class="Modifier">static</span> <span class="ValueType">void</span> Main(<span class="ReferenceType">string</span>[] args)<br />
{<br />
Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonPictures),<br />
<span class="String">"First SubDir"</span>,<br />
<span class="String">"Second Subdir"</span>,<br />
<span class="String">"MyFile.jpg"</span>);<br />
}<br />
}<br />
}
</div>
Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-92009375569638303462014-09-18T17:00:00.000-04:002014-09-18T17:48:06.705-04:00The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.<div class="MsoNormal">
<b>Problem:</b></div>
<div style="border: 1pt solid windowtext; padding: 1pt 4pt;">
<div class="MsoNormal" style="border: none; padding: 0in;">
Upon launching a .Net application, the error:<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.</span></blockquote>
is received.</div>
</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Solution:<o:p></o:p></b></div>
<br />
<div class="MsoNormal">
</div>
<br />
<div style="border: 1pt solid windowtext; orphans: auto; padding: 1pt 4pt; text-align: start; text-indent: 0px; widows: auto;">
<div class="MsoNormal" style="border: none; padding: 0in;">
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
The config file ended up having a ? character before the end of the element tag, like so:</div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<br /></div>
<startup><br />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" ?/><br />
</startup><br />
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<br /></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
Removed that ? character and I was back up and running again.</div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<br /></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
Thankfully, in Visual Studio when building we get this error:</div>
Error<span class="Apple-tab-span" style="white-space: pre;"> </span>1<span class="Apple-tab-span" style="white-space: pre;"> </span>Character '?', hexadecimal value 0x3f is illegal in an XML name.<span class="Apple-tab-span" style="white-space: pre;"> </span>C:\Users\dprischak\Documents\Visual Studio 2012\Projects\IPCamFileSorterConsole\IPCamFileSorterConsole\App.config<span class="Apple-tab-span" style="white-space: pre;"> </span>4<span class="Apple-tab-span" style="white-space: pre;"> </span>75<span class="Apple-tab-span" style="white-space: pre;"> </span>IPCamFileSorterConsole<br />
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-transform: none; white-space: normal; word-spacing: 0px;">
<br /></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com1tag:blogger.com,1999:blog-6541636783175030762.post-59991276187024631562011-07-27T17:01:00.000-04:002011-07-27T17:01:00.424-04:00C# Esri Shapefile ReaderI've been trying to populate a Sql Server database with shapefile information from the National Weather Service in an automated fashion, I finally found a tool that helps me do just that. It's called <a href="http://shapefile.codeplex.com/">ESRI Shapefile Reader</a> from <a href="http://www.codeplex.com/">CodePlex</a>.<br />
<br />
I had first tried <a href="http://www.sharpgis.net/page/shape2sql.aspx">Shape2Sql</a>, but it is closed source and for some reason would not import when I had Create Spatial Index checked. It would run through all the rows in the Shapefile, but no table or rows would be created. So I pre-created the table, still no rows were created. That was with the GUI, so when I tried it as a command line tool, again, it would not import the shape file because there is no command line option to disable creating the spatial index. I don't know where the problem lies, and Shape2Sql appears to be a good tool. For me, it works great for doing the import by hand, which is fine for data that doesn't change often, but I need automation and if the command line doesn't work, I'm not about to try and manipulate mouse clicks on a GUI from a windows service....<br />
<br />
I found various other tools, but they require subscription $, and I am trying to do this with a minimal budget since this is being used for a hobby.<br />
<br />
Anyways, I needed to load this data into <a href="http://www.microsoft.com/sqlserver/en/us/editions/express.aspx">SqlServer Express</a>. Using Shape2Sql, it took about 14 minutes for my particular datafile. I hate waiting and I need to automate this thing, so I decided to use ESRI Shapefile Reader to import a National Weather Service Precipitation file (which can be found at <a href="http://water.weather.gov/precip/download.php">http://water.weather.gov/precip/download.php</a>) and only grab the columns I'm interested in. Doing this, and threading the import, it now only takes 45 seconds to import the data. Best of all, I met my goal of doing this in an automated fashion. Here's my code snippet that shows you how I did this, if you have any questions, just post it.<br />
<br />
<br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New", Courier, Monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><br />
<pre class="csharpcode"> <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> CreateWorkForThreads()
{
DataSet ds = CreateNewDataSet();
DataTable dtNWS = ds.Tables[0];
<span class="rem">// Parse the shapefile into a DataTable, grabbing the columns we are interested in</span>
<span class="kwrd">using</span> (Shapefile shapefile = <span class="kwrd">new</span> Shapefile(Path.Combine(weatherFileDir, <span class="str">"nws_precip_1day_observed_"</span> + dateToLoad.ToString(<span class="str">"yyyyMMdd"</span>) + <span class="str">".shp"</span>)))
{
<span class="kwrd">foreach</span> (Shape shape <span class="kwrd">in</span> shapefile)
{
<span class="kwrd">string</span>[] metadataNames = shape.GetMetadataNames();
<span class="kwrd">decimal</span> lat = 0m;
<span class="kwrd">decimal</span> lon = 0m;
<span class="kwrd">decimal</span> globvalue = 0m;
<span class="kwrd">if</span> (metadataNames != <span class="kwrd">null</span>)
{
<span class="kwrd">foreach</span> (<span class="kwrd">string</span> metadataName <span class="kwrd">in</span> metadataNames)
{
<span class="kwrd">if</span> (metadataName == <span class="str">"lat"</span>)
lat = <span class="kwrd">decimal</span>.Parse(shape.GetMetadata(metadataName));
<span class="kwrd">else</span> <span class="kwrd">if</span> (metadataName == <span class="str">"lon"</span>)
lon = <span class="kwrd">decimal</span>.Parse(shape.GetMetadata(metadataName));
<span class="kwrd">else</span> <span class="kwrd">if</span> (metadataName == <span class="str">"globvalue"</span>)
globvalue = <span class="kwrd">decimal</span>.Parse(shape.GetMetadata(metadataName));
}
}
DataRow drNWS = dtNWS.NewRow();
drNWS[<span class="str">"lat"</span>] = lat;
drNWS[<span class="str">"lon"</span>] = lon;
drNWS[<span class="str">"globalvalue"</span>] = globvalue;
drNWS[<span class="str">"precipDate"</span>] = dateToLoad;
drNWS[<span class="str">"XAxis"</span>] = Math.Cos(ConvertDegreesToRadians((<span class="kwrd">double</span>)lat)) * Math.Cos(ConvertDegreesToRadians((<span class="kwrd">double</span>)lon));
drNWS[<span class="str">"YAxis"</span>] = Math.Cos(ConvertDegreesToRadians((<span class="kwrd">double</span>)lat)) * Math.Sin(ConvertDegreesToRadians((<span class="kwrd">double</span>)lon));;
drNWS[<span class="str">"ZAxis"</span>] = Math.Sin(ConvertDegreesToRadians((<span class="kwrd">double</span>)lat));
dtNWS.Rows.Add(drNWS);
}
}
List<dataset>; listOfDataSetsForThreads = <span class="kwrd">new</span> List<dataset>();
DataSet dsCur = CreateNewDataSet();
<span class="rem">// Create a list of datasets, each containing the rows the thread will import</span>
<span class="kwrd">foreach</span> (DataRow dr <span class="kwrd">in</span> dtNWS.Rows)
{
<span class="kwrd">if</span> (dsCur.Tables[0].Rows.Count % 3000 == 0)
{
listOfDataSetsForThreads.Add(dsCur);
dsCur = CreateNewDataSet();
}
dsCur.Tables[0].ImportRow(dr);
}
<span class="kwrd">if</span> (dsCur.Tables[0].Rows.Count > 0)
listOfDataSetsForThreads.Add(dsCur);
<span class="rem">// Spawn off the threads to import our datasets in parallel</span>
<span class="kwrd">foreach</span> (DataSet dsThreadWork <span class="kwrd">in</span> listOfDataSetsForThreads)
{
WaitCallback wcb = <span class="kwrd">new</span> WaitCallback(ImportDataSet);
ThreadPool.QueueUserWorkItem(wcb, dsThreadWork);
}
}
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> ImportDataSet(<span class="kwrd">object</span> o)
{
DataSet ds = (DataSet)o;
<span class="kwrd">using</span> (SqlConnection con = <span class="kwrd">new</span> SqlConnection(ConfigurationManager.AppSettings[<span class="str">"myDb"</span>]))
{
con.Open();
<span class="kwrd">try</span>
{
SqlDataAdapter da = <span class="kwrd">new</span> SqlDataAdapter(<span class="str">"select top 1 * from nws_precip_history"</span>, con);
SqlCommandBuilder bldr = <span class="kwrd">new</span> SqlCommandBuilder(da);
da.InsertCommand = bldr.GetInsertCommand();
da.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
da.UpdateBatchSize = 500;
da.Update(ds, <span class="str">"nws_precip_history"</span>);
}
<span class="kwrd">finally</span>
{
<span class="kwrd">if</span> (con.State == ConnectionState.Open)
con.Close();
}
}
}
<span class="kwrd">public</span> <span class="kwrd">static</span> DataSet CreateNewDataSet()
{
DataSet dsTemp = <span class="kwrd">new</span> DataSet();
DataTable dtNWSTemp = <span class="kwrd">new</span> DataTable(<span class="str">"nws_precip_history"</span>);
dtNWSTemp.Columns.Add(<span class="str">"lat"</span>, <span class="kwrd">typeof</span>(<span class="kwrd">decimal</span>));
dtNWSTemp.Columns.Add(<span class="str">"lon"</span>, <span class="kwrd">typeof</span>(<span class="kwrd">decimal</span>));
dtNWSTemp.Columns.Add(<span class="str">"globalvalue"</span>, <span class="kwrd">typeof</span>(<span class="kwrd">decimal</span>));
dtNWSTemp.Columns.Add(<span class="str">"precipDate"</span>, <span class="kwrd">typeof</span>(DateTime));
dtNWSTemp.Columns.Add(<span class="str">"XAxis"</span>, <span class="kwrd">typeof</span>(<span class="kwrd">float</span>));
dtNWSTemp.Columns.Add(<span class="str">"YAxis"</span>, <span class="kwrd">typeof</span>(<span class="kwrd">float</span>));
dtNWSTemp.Columns.Add(<span class="str">"ZAxis"</span>, <span class="kwrd">typeof</span>(<span class="kwrd">float</span>));
dsTemp.Tables.Add(dtNWSTemp);
<span class="kwrd">return</span> dsTemp;
}
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">double</span> ConvertDegreesToRadians(<span class="kwrd">double</span> degrees)
{
<span class="kwrd">double</span> radians = (Math.PI / 180) * degrees;
<span class="kwrd">return</span> (radians);
}
</dataset></dataset></pre>
<br />
<br />Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com4tag:blogger.com,1999:blog-6541636783175030762.post-24202238663251290552011-07-06T08:30:00.000-04:002011-07-06T08:30:01.986-04:00Failed to access IIS metabase<br />
<div class="MsoNormal">
Failed to access IIS metabase</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Problem:<o:p></o:p></b></div>
<div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
Running an IIS web
application, and you get the Failed to access IIS metabase error.</div>
</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Solution:<o:p></o:p></b></div>
<div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
First thing to try:</div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
Bring up a command prompt
to your .net framework directory under C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727</div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
Run: aspnet_regiis –i</div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
If that doesn’t work,
run: aspnet_regiis -ga aspnet</div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
That should solve it. If it doesn’t, here’s some reading: <a href="http://support.microsoft.com/?kbid=267904">The MetaAcl tool for modifying
metabase permissions on the IIS Admin Objects is available</a></div>
</div>
<div class="MsoNormal">
<br /></div>
Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-41984194820614555522011-07-06T08:00:00.001-04:002011-06-24T16:04:21.618-04:00The entry 'AspNetSqlMembershipProvider' has already been added<br />
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Problem:<o:p></o:p></b></div>
<div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<h1 style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
Server Error in '/MyApp' Application. </h1>
<h1 align="center" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-align: center;">
<hr align="center" color="silver" noshade="" size="1" width="100%" />
</h1>
<h2 style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<i>Configuration Error</i> </h2>
<div class="MsoNormal" style="border: none; margin-bottom: 12.0pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Description: </span></b><span style="color: black; font-family: Arial; font-size: 8.5pt;">An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. <br />
<br />
</span><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Parser Error Message: </span></b><span style="color: black; font-family: Arial; font-size: 8.5pt;">The entry 'AspNetSqlMembershipProvider' has already been added.<br />
<br />
</span><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Source Error:</span></b><span style="color: black; font-family: Arial; font-size: 8.5pt;"> <o:p></o:p></span></div>
</div>
<table border="0" cellpadding="0" class="MsoNormalTable" style="background: #FFFFCC; mso-cellspacing: 1.5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; width: 100.0%;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"> <td style="padding: .75pt .75pt .75pt .75pt;"><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span class="Apple-style-span" style="font-size: 12px;">
</span></pre>
<pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span class="Apple-style-span" style="font-size: 12px;">Line 42: <membership></membership></span></pre>
<pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span class="Apple-style-span" style="font-size: 12px;">Line 43: <providers></providers></span></pre>
<pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span class="Apple-style-span" style="font-size: 12px;">Line 44: <span class="Apple-style-span" style="color: red;"><add <="" connectionstringname="SomeServer" font="" name="AspNetSqlMembershipProvider"></add></span></span></pre>
<pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span class="Apple-style-span" style="font-size: 12px;"><span class="Apple-style-span" style="font-size: 12px;">Line 45: enablePasswordRetrieval="false"></span></span></pre>
</div>
</td></tr>
</tbody></table>
<br />
<div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="border: none; margin-bottom: 12.0pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Source File: </span></b><span style="color: black; font-family: Arial; font-size: 8.5pt;">C:\Program Files\MyApp\web.config</span><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;"> Line: </span></b><span style="color: black; font-family: Arial; font-size: 8.5pt;">44 <o:p></o:p></span></div>
</div>
<div align="center" class="MsoNormal" style="text-align: center;">
<span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span><br />
<hr align="center" color="silver" noshade="" size="1" width="100%" />
<span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span></div>
<div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Version Information:</span></b><span style="color: black; font-family: Arial; font-size: 8.5pt;"> Microsoft .NET Framework Version:2.0.50727.3620; ASP.NET Version:2.0.50727.3618</span></div>
</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Solution:<o:p></o:p></b></div>
<div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
In the web.config file, you need to add a "remove provider" tag before the add provider tag:<br />
<remove name="AspNetSqlMembershipProvider"></remove></div>
</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-85810066539727753242011-06-30T08:00:00.000-04:002011-06-30T08:00:14.860-04:00Login failed for user xxxx. The user is not associated with a trusted SQL Server connection.<br />
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Problem:<o:p></o:p></b></div>
<div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
Connecting to SQL Server
with a query in SQL Server Management Studio, you get “Login failed for user
xxxx.<span style="mso-spacerun: yes;"> </span>The user is not associated with a
trusted SQL Server connection.”</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgETM8DymVcO6PhEjkXnJZ9hH85K437Q6gySq3qXhS3nbgkSw6ZQJ-OhkzTvcIusFyFOUCKHjOkyz-pnH24p7qY1x3DaIIVcjxqTQc2bISaPPCNyJnjcOnwGSO6dCIdojbjpbcE1gNdEWM/s1600/login+failed+1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgETM8DymVcO6PhEjkXnJZ9hH85K437Q6gySq3qXhS3nbgkSw6ZQJ-OhkzTvcIusFyFOUCKHjOkyz-pnH24p7qY1x3DaIIVcjxqTQc2bISaPPCNyJnjcOnwGSO6dCIdojbjpbcE1gNdEWM/s1600/login+failed+1.png" /></a></div>
<br />
<br />
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<o:p><br /></o:p></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<o:p><br /></o:p></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<o:p><br /></o:p></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<o:p><br /></o:p></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<o:p><br /></o:p></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<o:p><br /></o:p></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<br /><!--[endif]--></div>
</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Solution:<o:p></o:p></b></div>
<div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
Open Microsoft SQL Server
Management Studio.</div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
Connect to your sql
instance.<span style="mso-spacerun: yes;"> </span>Right click the instance name
in the Object Explorer window and select properties.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaQB4xEWlgDzE9-H1jxBTJ9HRg3KxBCfFEeZSwophf6IP8tkSlKH-mjS0Ccx3lSuGBoLCzS5EogBy7XCIsReaNrUkO2A2dHF_bZ6OhyphenhyphenRur0oo7BrFWErHmr2Uvky2ZWazNkdrfRvpM0YA/s1600/login+failed+2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaQB4xEWlgDzE9-H1jxBTJ9HRg3KxBCfFEeZSwophf6IP8tkSlKH-mjS0Ccx3lSuGBoLCzS5EogBy7XCIsReaNrUkO2A2dHF_bZ6OhyphenhyphenRur0oo7BrFWErHmr2Uvky2ZWazNkdrfRvpM0YA/s1600/login+failed+2.png" /></a></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<br /><!--[endif]--></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvSAnXVXk555djHvGWoPCgZ5z57POHHoFhcqs7wqCSCFELpSUH5xarZMSE5qIoa55CSWtCcLYVvsxdfm5ZMdJSasSrsGuzE9Me5ygouebpq_mBW-tuZS5vBSdVVTIYmU5t9BmVH0nhgmM/s1600/login+failed+3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvSAnXVXk555djHvGWoPCgZ5z57POHHoFhcqs7wqCSCFELpSUH5xarZMSE5qIoa55CSWtCcLYVvsxdfm5ZMdJSasSrsGuzE9Me5ygouebpq_mBW-tuZS5vBSdVVTIYmU5t9BmVH0nhgmM/s1600/login+failed+3.png" /></a></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<br /><!--[endif]--></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
Select SQL Server and
Windows Authentication mode and click OK.</div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<br /></div>
<div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">
<span style="color: red;">!Very
Important!</span><span style="mso-spacerun: yes;"> </span>Restart SQL Server for
this setting to take effect.</div>
</div>
<div class="MsoNormal">
<br /></div>
Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-56844920618144886962011-04-02T10:27:00.000-04:002011-04-02T10:27:57.940-04:00Problem in mapping fragments starting at line nnn:All the key properties (xxxx.column) of the EntitySet xxxx must be mapped to all the key properties<div class="MsoNormal"></div><div class="MsoNormal"><span style="color: black;">Problem:<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;">Error 3003: Problem in mapping fragments starting at line 257:All the key properties (table.column) of the EntitySet table must be mapped to all the key properties (table.column, table.column) of table table.<o:p></o:p></span></div></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="color: black;">Solution:<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;">Select the column giving you problems, hit F4 for properties, and change Nullable from (None) to False.<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_IwJ2NhktPzKFVDiwWqORFKin21vsIGxbywD-8Nh-dpqy91MCBInkZ6OHsNYIuVAbA985oTIydcLGvc1vkVhg5c9GTr2j25LWFuMZWA5rdTB1w-MH8UHFXeLx_8fV_sYKVg318LVRpKk/s1600/modelproperty.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_IwJ2NhktPzKFVDiwWqORFKin21vsIGxbywD-8Nh-dpqy91MCBInkZ6OHsNYIuVAbA985oTIydcLGvc1vkVhg5c9GTr2j25LWFuMZWA5rdTB1w-MH8UHFXeLx_8fV_sYKVg318LVRpKk/s1600/modelproperty.png" /></a></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black;"><br />
</span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><br />
</div></div><br />
<div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com3tag:blogger.com,1999:blog-6541636783175030762.post-37709253422862839772011-03-30T01:32:00.000-04:002011-03-30T01:32:33.709-04:00Index (zero based) must be greater than or equal to zero and less than the size of the argument list<div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Problem:<o:p></o:p></b></div><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">System.FormatException was unhandled by user code<o:p></o:p></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="mso-spacerun: yes;"> </span>Message=Index (zero based) must be greater than or equal to zero and less than the size of the argument list.<o:p></o:p></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="mso-spacerun: yes;"> </span>Source=mscorlib<o:p></o:p></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="mso-spacerun: yes;"> </span>StackTrace:<o:p></o:p></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="mso-spacerun: yes;"> </span>at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)<o:p></o:p></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="mso-spacerun: yes;"> </span>at System.String.Format(IFormatProvider provider, String format, Object[] args)<o:p></o:p></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="mso-spacerun: yes;"> </span>at System.String.Format(String format, Object arg0)<o:p></o:p></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>at MultiThreadedDbSeeder.Program.<<st1:place w:st="on">Main</st1:place>>b__0(Int32 i) in C:\xxxx\Program.cs:line 22<o:p></o:p></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="mso-spacerun: yes;"> </span>at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<forworker>b__c()<o:p></o:p></forworker></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="mso-spacerun: yes;"> </span>InnerException:</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><br />
</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">Offending Line:</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">SqlCommand</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> cmd = <span style="color: blue;">new</span> <span style="color: #2b91af;">SqlCommand</span>(<span style="color: blue;">string</span>.Format(<span style="color: #a31515;">@"insert into table_1 (vch_value) values('{1}')"</span>, <span style="color: #a31515;">"the value of i is "</span> + i));<o:p></o:p></span></div></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Solution:<o:p></o:p></b></div><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">Don’t forget that string.Format uses a zero based index.</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">Fixed Code:</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">SqlCommand</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> cmd = <span style="color: blue;">new</span> <span style="color: #2b91af;">SqlCommand</span>(<span style="color: blue;">string</span>.Format(<span style="color: #a31515;">@"insert into table_1 (vch_value) values('{0}')"</span>, <span style="color: #a31515;">"the value of i is "</span> + i));<o:p></o:p></span></div></div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-50008830627903972802011-03-29T17:15:00.001-04:002011-03-29T17:15:00.481-04:00The project file has been moved, renamed or is not on your computer<b>Solution:</b><br />
1) Close the solution you have open.<br />
2) In the project folder which is giving you problems, find the .suo file and delete it.<br />
3) Reopen your solution and add the project back.Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com5tag:blogger.com,1999:blog-6541636783175030762.post-69198285799934742632011-03-26T11:42:00.000-04:002011-03-26T11:42:30.911-04:00Quartz.ObjectAlreadyExistsException: Unable to store Job with name: '' and group: 'DEFAULT', because one already exists with this identification.<div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Problem:<o:p></o:p></b></div><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">Exception Caught: Quartz.ObjectAlreadyExistsException: Unable to store Job with name: 'updateMyStuff' and group: 'DEFAULT', because one already exists with this identification.</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><br />
</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><br />
</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">Code:</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span><span style="mso-spacerun: yes;"> </span>// construct job info for every 10 seconds<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">JobDetail</span> = jobDetail = <span style="color: blue;">new</span> <span style="color: #2b91af;">JobDetail</span>(<span style="color: #a31515;">"updateMyStuff"</span>, <span style="color: blue;">null</span>, <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">UpdateMyOneMethod</span>));<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>trig = <span style="color: blue;">new</span> <span style="color: #2b91af;">CronTrigger</span>();<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>trig.CronExpression = <span style="color: blue;">new</span> <span style="color: #2b91af;">CronExpression</span>(<span style="color: #a31515;">"0/10 * * * * ?"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>trig.Name = <span style="color: #a31515;">" updateStuff "</span>;<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>sched.ScheduleJob(jobDetail, trig);<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><br />
</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">// job for every day 12:00 am</span><o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>jobDetail = <span style="color: blue;">new</span> <span style="color: #2b91af;">JobDetail</span>(<span style="color: #a31515;">"updateMyStuff"</span>, <span style="color: blue;">null</span>, <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">UpdateMyOtherMethod</span>));<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>trig = <span style="color: blue;">new</span> <span style="color: #2b91af;">CronTrigger</span>();<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>trig.CronExpression = <span style="color: blue;">new</span> <span style="color: #2b91af;">CronExpression</span>(<span style="color: #a31515;">"0 0 0 * * ?"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>trig.Name = <span style="color: #a31515;">"updateStuff"</span>;<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>sched.ScheduleJob(jobDetail, trig);<o:p></o:p></span></div></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Solution:<o:p></o:p></b></div><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">I was clearly very tired and not paying attention and made a miserable copy/paste error.<span style="mso-spacerun: yes;"> </span>Make sure the JobDetail has a unique name and same with the trigger!<span style="mso-spacerun: yes;"> </span>Fixed Code, changes bolded:</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><br />
</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span><span style="mso-spacerun: yes;"> </span>// construct job info for every 10 seconds<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">JobDetail</span> = jobDetail = <span style="color: blue;">new</span> <span style="color: #2b91af;">JobDetail</span>(<span style="color: #a31515;">"updateMyStuff"</span>, <span style="color: blue;">null</span>, <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">UpdateMyOneMethod</span>));<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>trig = <span style="color: blue;">new</span> <span style="color: #2b91af;">CronTrigger</span>();<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>trig.CronExpression = <span style="color: blue;">new</span> <span style="color: #2b91af;">CronExpression</span>(<span style="color: #a31515;">"0/10 * * * * ?"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>trig.Name = <span style="color: #a31515;">" updateStuff "</span>;<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>sched.ScheduleJob(jobDetail, trig);<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><br />
</div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">// job for every day 12:00 am</span><o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>jobDetail = <span style="color: blue;">new</span> <span style="color: #2b91af;">JobDetail</span>(<span style="color: #a31515;">"<b style="mso-bidi-font-weight: normal;">updateMyOtherStuff</b>"</span>, <span style="color: blue;">null</span>, <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">UpdateMyOtherMethod</span>));<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>trig = <span style="color: blue;">new</span> <span style="color: #2b91af;">CronTrigger</span>();<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>trig.CronExpression = <span style="color: blue;">new</span> <span style="color: #2b91af;">CronExpression</span>(<span style="color: #a31515;">"0 0 0 * * ?"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>trig.Name = <span style="color: #a31515;">"<b style="mso-bidi-font-weight: normal;">updateOtherStuff</b>"</span>;<o:p></o:p></span></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>sched.ScheduleJob(jobDetail, trig);<o:p></o:p></span></div></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-10545140757501010842011-03-20T13:26:00.000-04:002011-03-20T13:26:20.251-04:00Should I Create a Business Logic Layer?<div class="MsoNormal">The <a href="http://en.wikipedia.org/wiki/Business_layer">Business Logic Layer</a> (BLL) is located between the <a href="http://en.wikipedia.org/wiki/Data_access_layer">Data Access Layer</a> and the <a href="http://en.wikipedia.org/wiki/User_interface">User Interface</a>.<span style="mso-spacerun: yes;"> </span>This is where your data is traslated from Database objects, like DataTables and DataRows into Classes and Objects.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Sometimes I use them, and other times I don’t.<span style="mso-spacerun: yes;"> </span>This should become obvious in your design phase, when you learn whether or not your application is manipulating data after retrieving it from a database.<span style="mso-spacerun: yes;"> </span>If your application is CRUD (Create Retrieve Update Delete), then most likely you don’t need a BLL.<span style="mso-spacerun: yes;"> </span>It would be a waste of your time to add an unnecessary layer just because it is a “Proper Model”.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">I find that with the <a href="http://msdn.microsoft.com/en-us/data/aa937723">Entity Framework</a> the need for a business layer is further diminished.<span style="mso-spacerun: yes;"> </span>The reason is that the auto generated code, that is the Model, takes out the need to translate DataRow to an Object.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Now, the only reason left to have a business layer is for business logic.<span style="mso-spacerun: yes;"> </span>This is were much of your common code may go, like generation of reports, charts, and calculations.<span style="mso-spacerun: yes;"> </span>The last few projects I have done only had partial business logic layers.<span style="mso-spacerun: yes;"> </span>I only created them when necessary.</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com1tag:blogger.com,1999:blog-6541636783175030762.post-61125878357805785992011-03-19T01:04:00.000-04:002011-03-19T01:04:28.093-04:00The type or namespace name 'xxxx' does not exist in the namespace 'yyyy' (are you missing an assembly reference?)<div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Problem:<o:p></o:p></b></div><div class="MsoNormal">Error<span style="mso-tab-count: 1;"> </span>1<span style="mso-tab-count: 1;"> </span>The type or namespace name 'xxxx' does not exist in the namespace 'yyyy' (are you missing an assembly reference?)</div><div class="MsoNormal"><o:p>Screenshot:</o:p></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ4aHUxiZQgPOnbRaFzNhJPX-5wNSDqs9DsEnMnrNFOjebMxN4_js3QV7LAdmWjVueXrN068Lx3B5peYKEmUm-8GtrTlMUICfshvDocSw0iiYGMHv-L02pN6UFqkeD2VRmcjink2ePnAo/s1600/clientprofile-builderror.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="69" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ4aHUxiZQgPOnbRaFzNhJPX-5wNSDqs9DsEnMnrNFOjebMxN4_js3QV7LAdmWjVueXrN068Lx3B5peYKEmUm-8GtrTlMUICfshvDocSw0iiYGMHv-L02pN6UFqkeD2VRmcjink2ePnAo/s320/clientprofile-builderror.png" width="320" /></a></div><div class="MsoNormal"><o:p><br />
</o:p></div><div class="MsoNormal">My environment: Visual Studio 2010, .Net 4.0.<span style="mso-spacerun: yes;"> </span>Two projects involved, 1 is a dll, other is a console app.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">You know your reference is correct, but you still get that reference error.<span style="mso-spacerun: yes;"> </span>Your using clause fails, too.</div><div class="MsoNormal"><o:p>Screenshot:</o:p></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQMeyVPnyKnA59fqVbKd7_xjXB07l0AwrfcQVpbe5BRiR3pGeBqLQ4kZEH0em0y8wV6fKSu9OuO5qYU5G6R2WqYYANWRfcL_te96tBAO4RQ7flW6UilXObxRL3fxQuJwDDeI7l6o7E1BE/s1600/clientprofile-references.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQMeyVPnyKnA59fqVbKd7_xjXB07l0AwrfcQVpbe5BRiR3pGeBqLQ4kZEH0em0y8wV6fKSu9OuO5qYU5G6R2WqYYANWRfcL_te96tBAO4RQ7flW6UilXObxRL3fxQuJwDDeI7l6o7E1BE/s1600/clientprofile-references.png" /></a> </div><div class="MsoNormal"><o:p><br />
</o:p></div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Solution:<o:p></o:p></b></div><div class="MsoNormal">In this case, my console app had the Target Framework in the project properties set to .NET Framework 4 Client Profile, the dll project had it set to .NET Framework 4.<span style="mso-spacerun: yes;"> </span>I changed the console app to use .NET Framework 4, and everything built fine.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Console App Project properties before:</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXX4DZr0VlQ21ozm94CdFhyphenhyphenwrqPAnLp8w4WV5oEHZcz85WEjXJ5W61fVrSdj5WS2_H1KrcB4eDe3PinqyIw38s4TcLFrQXsH5hxdqni44Wwks4f3Y1EBznUE5qpksP2q3sT5QSXVab15M/s1600/clientprofile-clientprofile.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXX4DZr0VlQ21ozm94CdFhyphenhyphenwrqPAnLp8w4WV5oEHZcz85WEjXJ5W61fVrSdj5WS2_H1KrcB4eDe3PinqyIw38s4TcLFrQXsH5hxdqni44Wwks4f3Y1EBznUE5qpksP2q3sT5QSXVab15M/s1600/clientprofile-clientprofile.png" /></a></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Console App Project properties after:</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTobJB7uSQz8th1nrIrgFw3V50mymnqxoFWKokxkLbnkzWW7p1cH19mBEp8VIF1u6qXSBnsdk_guk3Le6CoeLbOu6iwPBP-iv_JFEFRBSq7tpZr110xTEZxdvtnijbIMXlrcZyFodFhgo/s1600/clientprofile-regularframework.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTobJB7uSQz8th1nrIrgFw3V50mymnqxoFWKokxkLbnkzWW7p1cH19mBEp8VIF1u6qXSBnsdk_guk3Le6CoeLbOu6iwPBP-iv_JFEFRBSq7tpZr110xTEZxdvtnijbIMXlrcZyFodFhgo/s1600/clientprofile-regularframework.png" /></a></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com7tag:blogger.com,1999:blog-6541636783175030762.post-53310304722405551742011-03-17T01:50:00.000-04:002011-03-17T01:50:08.022-04:00Building Visual Studio Solutions Out of the Box<div class="MsoNormal">It is terrible when you are a developer at a new place and you open Visual Studio the first time, connect to your favorite source control like TFS or SVN, and open the desired solution, click build only to see many compile errors like invalid references.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Avoid creating this situation now by organizing your solutions so that they can easily be opened and built by new people.<span style="mso-spacerun: yes;"> </span><b>You need to take into consideration how your solution is layed out, where external dependencies are, and how you present external tools.</b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">First thing you need to do is make sure you solution file is at the root of all your projects.<span style="mso-spacerun: yes;"> </span>If your all your projects are under c:/source, like in c:/source/MovieApp, then your solution should reside in c:/source.<span style="mso-spacerun: yes;"> </span>You want to do this because it is not good practice to have a project reach up to a parent directory of the solution file into another branch for a referenced file or project.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Your structure should look like this:</div><div class="MsoNormal"><span style="color: blue;">C:/source<o:p></o:p></span></div><div class="MsoNormal"><span style="color: navy;"><span style="mso-tab-count: 1;"> </span>MyMovieSolution.sln<o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue;">C:/source/MovieApp<o:p></o:p></span></div><div class="MsoNormal"><span style="color: navy;"><span style="mso-tab-count: 1;"> </span>MovieApp.csproj<o:p></o:p></span></div><div class="MsoNormal"><span style="color: blue;">C:/source/MvcMovie<o:p></o:p></span></div><div class="MsoNormal"><span style="color: navy;"><span style="mso-tab-count: 1;"> </span>MvcMovie.csproj<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Your next consideration needs to be references to external dependencies.<span style="mso-spacerun: yes;"> </span>It is best if you have one location for this, right off the solution folder.<span style="mso-spacerun: yes;"> </span>I usually call mine “External Dependencies”.<span style="mso-spacerun: yes;"> </span>Then what you need to do is create an External Dependencies folder in the Visual Studio Solution and add your files from your “External Dependences” folder.<span style="mso-spacerun: yes;"> </span>Now, whenever you reference a dll that is external, you use those files, and it will be gotten when you have a new developer get latest!<span style="mso-spacerun: yes;"> </span>Easy enough.</div><div class="MsoNormal"><br />
</div><br />
<div class="separator" style="clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjay9pchZ8eOisqvVClDCtz_gw7sM2_xgLrPjZ08fTAbeYuhraepRiVySkbFam0h12EsGNIIQMpbDnacceweMTLbEw2kM11Ugz-Ixw2UmRy2DWNxpJggirVghc79DvLFo294z1lzjb9Ngc/s1600/build-externaldependencies.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjay9pchZ8eOisqvVClDCtz_gw7sM2_xgLrPjZ08fTAbeYuhraepRiVySkbFam0h12EsGNIIQMpbDnacceweMTLbEw2kM11Ugz-Ixw2UmRy2DWNxpJggirVghc79DvLFo294z1lzjb9Ngc/s1600/build-externaldependencies.png" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBAzUDT61X5Q8X5pxUGLxU_WpnRScmY6XGKk3mkESE66i63tEzoFULrzDyJ7IcrRS_pWB8wI4nWm2YUi1nWB9pExcu-x_Zr3DaZVp6JEv4cBPrRgToKpid1x1dH8P8ofkfK5dYYUQKwOo/s1600/build-references.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="270" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBAzUDT61X5Q8X5pxUGLxU_WpnRScmY6XGKk3mkESE66i63tEzoFULrzDyJ7IcrRS_pWB8wI4nWm2YUi1nWB9pExcu-x_Zr3DaZVp6JEv4cBPrRgToKpid1x1dH8P8ofkfK5dYYUQKwOo/s320/build-references.png" width="320" /></a></div><div class="MsoNormal"><br />
<!--[endif]--></div><div class="MsoNormal"><br />
<!--[endif]--></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Next thing is to provide all your external tools in your solution.<span style="mso-spacerun: yes;"> </span>I cannot tell you the number of times I had to go find an exact version of a tool because of some quirk that version had but no others did.<span style="mso-spacerun: yes;"> </span>Check it in with your source, don’t store it on a shared network drive.<span style="mso-spacerun: yes;"> </span>Update it?<span style="mso-spacerun: yes;"> </span>Great, update it in your source control.</div><div class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtu2RPTPu8pIbiXEo4TJn9VY7CqHm664DrjsiQWSAdvqWppUd1LCbedycBLli6xqfUyFonzmehX15puH8XvguKIbOMV3eGjKMpjyj9F1-eZxGft6dtYZPg3rT1hyphenhyphenMNBq7pR7byoDjGEXI/s1600/build-developmenttools.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: left;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtu2RPTPu8pIbiXEo4TJn9VY7CqHm664DrjsiQWSAdvqWppUd1LCbedycBLli6xqfUyFonzmehX15puH8XvguKIbOMV3eGjKMpjyj9F1-eZxGft6dtYZPg3rT1hyphenhyphenMNBq7pR7byoDjGEXI/s1600/build-developmenttools.png" /></a><o:p> </o:p></div><div class="MsoNormal"><br />
<!--[endif]--></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Last tip is do not set your output directories to the same folder! Never do this, please. Ever. Leave them in bin. If you are doing this, you most likely have an external dependency problem in one of your projects. Fix that.</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-19743940540996166082011-03-05T14:46:00.001-05:002011-03-30T01:00:20.390-04:00The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.<div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Problem:<o:p></o:p></b></div><div class="MsoNormal"><br />
</div><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><h1 style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: red; font-family: Verdana; font-size: 18pt; font-weight: normal;">Server Error in '/' Application.<o:p></o:p></span></h1><h1 align="center" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-align: center;"><span style="color: red; font-family: Verdana; font-size: 18pt; font-weight: normal;"> <hr align="center" color="silver" noshade="" size="1" width="100%" /></span></h1><h2 style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><i><span style="color: maroon; font-family: Verdana; font-size: 14pt; font-weight: normal;">The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.</span></i><span style="color: maroon; font-family: Verdana; font-size: 14pt; font-weight: normal;"><o:p></o:p></span></h2><div class="MsoNormal" style="border: none; margin-bottom: 12.0pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Description:</span></b></span><span class="apple-converted-space"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;"> </span></b></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;">An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</span></span><span class="apple-converted-space"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span></span><span style="color: black; font-family: Arial; font-size: 8.5pt;"><br />
<br />
</span><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Exception Details:</span></b></span><span class="apple-converted-space"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;"> </span></b></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;">System.ArgumentException: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.</span></span><span style="color: black; font-family: Arial; font-size: 8.5pt;"><br />
<br />
</span><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Source Error:</span></b></span><span class="apple-converted-space"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;"><o:p></o:p></span></span></div></div><table border="0" cellpadding="0" class="MsoNormalTable" style="background: #FFFFCC; mso-cellspacing: 1.5pt; width: 100.0%;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"> <td style="padding: .75pt .75pt .75pt .75pt;"><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"><o:p> </o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">Line 32: /// Initializes a new xxxxEntities object using the connection string found in the 'xxxxEntities' section of the application configuration file.<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">Line 33: /// <o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: red; font-family: 'Lucida Console'; font-size: 9pt;">Line 34: public xxxxEntities() : base("name=xxxxEntities", "xxxxEntities")<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">Line 35: {<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">Line 36: this.ContextOptions.LazyLoadingEnabled = true;<o:p></o:p></span></pre></div></td> </tr>
</tbody></table><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><div class="MsoNormal" style="border: none; margin-bottom: 12.0pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: black; font-family: Arial; font-size: 8.5pt;"><br />
</span><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Source File:</span></b></span><span class="apple-converted-space"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;"> </span></b></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;">C:\Users\xxxx\Documents\Visual Studio 2010\Projects\xxxx.Designer.cs</span></span><span class="apple-converted-space"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;"> </span></b></span><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;"> Line:</span></b></span><span class="apple-converted-space"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;"> </span></b></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;">34</span></span><span class="apple-converted-space"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span></span><span style="color: black; font-family: Arial; font-size: 8.5pt;"><br />
<br />
</span><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Stack Trace:</span></b></span><span class="apple-converted-space"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;"><o:p></o:p></span></span></div></div><table border="0" cellpadding="0" class="MsoNormalTable" style="background: #FFFFCC; mso-cellspacing: 1.5pt; width: 100.0%;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"> <td style="padding: .75pt .75pt .75pt .75pt;"><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"><o:p> </o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">[ArgumentException: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.]<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +8080056<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Data.EntityClient.EntityConnection..ctor(String connectionString) +81<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString) +42<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) +16<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> xxxx..ctor() in C:\Users\xxxxx.cs:34<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> xxxx(Int32 id) in C:\Users\xxx.cs:25<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> xxxx() in C:\Users\xxxx\Documents\Visual Studio 2010\Projects\xxxxDal.cs:36<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> xxxx() in C:\Users\xxxx\Documents\Visual Studio 2010\Projects\xxxx.cs:13<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> xxxx(Object sender, EventArgs e) in C:\Users\xxxxaspx.cs:145<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36<o:p></o:p></span></pre><pre style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563<o:p></o:p></span></pre></div></td> </tr>
</tbody></table><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><br />
</div><div align="center" class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-align: center;"><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span></span><br />
<hr align="center" color="silver" noshade="" size="1" width="100%" /></div><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Version Information:</span></b></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1</span></span></div></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Solution:<o:p></o:p></b></div><div class="MsoNormal">Add the entity connection string to the web.config file in the appropriate project.</div><div class="MsoNormal"><br />
</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com1tag:blogger.com,1999:blog-6541636783175030762.post-68987573005554556992011-03-05T14:04:00.000-05:002011-03-05T14:04:09.930-05:00Ambiguous reference - The type or namespace name 'Quartz' could not be found (are you missing a using directive or an assembly reference?)<div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Problem:<o:p></o:p></b></div><div class="MsoNormal">Environment: VS 2010 .Net 4.0 Console app using Quartz.Net <a href="http://quartznet.sourceforge.net/">http://quartznet.sourceforge.net/</a> as a Project Reference.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">I would get an Ambiguous reference listing Quartz.IJob twice.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">I had only 1 reference to Quarts in the list of References for my Project, that showed up as Quartz.2008.</div><div class="MsoNormal"><!--[if gte vml 1]><v:shape id="_x0000_i1026" type="#_x0000_t75"
style='width:78pt;height:38.25pt'> <v:imagedata src="" o:title=""/> </v:shape><![endif]--><o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Compile errors:<o:p></o:p></div><div class="MsoNormal">Error<span style="mso-tab-count: 1;"> </span>1<span style="mso-tab-count: 1;"> </span>The type or namespace name 'Quartz' could not be found (are you missing a using directive or an assembly reference?)<o:p></o:p></div><div class="MsoNormal">Error<span style="mso-tab-count: 1;"> </span>5<span style="mso-tab-count: 1;"> </span>The type or namespace name 'JobExecutionContext' could not be found (are you missing a using directive or an assembly reference?)<span style="mso-tab-count: 1;"> </span><o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Quartz Project properties had the target framework set to .NET Framework 3.5.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Solution:<o:p></o:p></b></div><div class="MsoNormal">Change the Target framework on the Quartz.2008 project properties to .NET Framework 4.<span style="mso-spacerun: yes;"> </span>I ensured my project used .NET Framework 4, also.<o:p></o:p></div><div class="MsoNormal"><!--[if gte vml 1]><v:shape id="_x0000_i1028" type="#_x0000_t75"
style='width:209.25pt;height:105pt'> <v:imagedata src="" o:title=""/> </v:shape><![endif]--><o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">If you get the following error in Quartz, then you had set the Target framework to .NET Framework Client Profile instead of .NET Framework 4.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Error<span style="mso-tab-count: 1;"> </span>6<span style="mso-tab-count: 1;"> </span>The type or namespace name 'HttpContext' could not be found (are you missing a using directive or an assembly reference?)<span style="mso-tab-count: 1;"> </span>xxxx\Quartz.NET-1.0.3\src\Quartz\Util\LogicalThreadContext.cs<span style="mso-tab-count: 1;"> </span>41<span style="mso-tab-count: 1;"> </span>4<span style="mso-tab-count: 1;"> </span>Quartz.2008<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-22100957677981151422011-03-05T13:58:00.001-05:002011-03-30T01:01:36.914-04:00Failed to start monitoring changes to 'path' because access is denied.<div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Problem:<o:p></o:p></b></div><div class="MsoNormal">Brought up a web page and was presented with this error:</div><h1><span style="color: red; font-family: Verdana; font-size: 18pt; font-weight: normal;">Server Error in '/' Application.<o:p></o:p></span></h1><h1 align="center" style="text-align: center;"><span style="color: red; font-family: Verdana; font-size: 18pt; font-weight: normal;"> <hr align="center" color="silver" noshade="" size="1" width="100%" /></span></h1><h2><i><span style="color: maroon; font-family: Verdana; font-size: 14pt; font-weight: normal;">Failed to start monitoring changes to 'C:\Users\xxxx\AppData\Local\Temp\Temporary ASP.NET Files\root\b6230deb\7677a327\hash\hash.web' because access is denied.</span></i><span style="color: maroon; font-family: Verdana; font-size: 14pt; font-weight: normal;"><o:p></o:p></span></h2><div class="MsoNormal" style="margin-bottom: 12.0pt;"><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Description:</span></b></span><span class="apple-converted-space"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;"> </span></b></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;">An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</span></span><span class="apple-converted-space"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span></span><span style="color: black; font-family: Arial; font-size: 8.5pt;"><br />
<br />
</span><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Exception Details:</span></b></span><span class="apple-converted-space"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;"> </span></b></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;">System.Web.HttpException: Failed to start monitoring changes to 'C:\Users\xxxx\AppData\Local\Temp\Temporary ASP.NET Files\root\b6230deb\7677a327\hash\hash.web' because access is denied.</span></span><span style="color: black; font-family: Arial; font-size: 8.5pt;"><br />
<br />
</span><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Source Error:</span></b></span><span class="apple-converted-space"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable" style="background: #FFFFCC; mso-cellspacing: 1.5pt; width: 100.0%;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"> <td style="padding: .75pt .75pt .75pt .75pt;"><div class="MsoNormal"><code><span style="font-size: 10pt;">An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</span></code></div></td> </tr>
</tbody></table><div class="MsoNormal" style="margin-bottom: 12.0pt;"><span style="color: black; font-family: Arial; font-size: 8.5pt;"><br />
</span><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Stack Trace:</span></b></span><span class="apple-converted-space"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;"><o:p></o:p></span></span></div><table border="0" cellpadding="0" class="MsoNormalTable" style="background: #FFFFCC; mso-cellspacing: 1.5pt; width: 100.0%;"><tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"> <td style="padding: .75pt .75pt .75pt .75pt;"><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"><o:p> </o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;">[HttpException (0x80070005): Failed to start monitoring changes to 'C:\Users\xxxx\AppData\Local\Temp\Temporary ASP.NET Files\root\b6230deb\7677a327\hash\hash.web' because access is denied.]<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.DirectoryMonitor.AddFileMonitor(String file) +8805891<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.DirectoryMonitor.StartMonitoringFileWithAssert(String file, FileChangeEventHandler callback, String alias) +94<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.FileChangesMonitor.StartMonitoringFile(String alias, FileChangeEventHandler callback) +340<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDate2(StandardDiskBuildResultCache diskCache) +790<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDate(StandardDiskBuildResultCache diskCache) +55<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.Compilation.BuildManager.RegularAppRuntimeModeInitialize() +174<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.Compilation.BuildManager.Initialize() +261<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.Compilation.BuildManager.InitializeBuildManager() +246<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException) +350<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"><o:p> </o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;">[HttpException (0x80004005): Failed to start monitoring changes to 'C:\Users\xxxx\AppData\Local\Temp\Temporary ASP.NET Files\root\b6230deb\7677a327\hash\hash.web' because access is denied.]<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8950644<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97<o:p></o:p></span></pre><pre><span style="font-family: 'Lucida Console'; font-size: 9pt;"> System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258<o:p></o:p></span></pre></td> </tr>
</tbody></table><div class="MsoNormal"><br />
</div><div align="center" class="MsoNormal" style="text-align: center;"><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span></span><br />
<hr align="center" color="silver" noshade="" size="1" width="100%" /></div><div class="MsoNormal"><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt;">Version Information:</span></b></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1</span></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Solution:<o:p></o:p></b></div><div class="MsoNormal">First, I had to close Visual Studio 2010, then I deleted c:\Users\xxxx\AppData\ocal\Temp\Temporary ASP.NET Files.</div><div class="MsoNormal">Reopened Visual Studio and ran it again in debug mode, worked fine.</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com1tag:blogger.com,1999:blog-6541636783175030762.post-71722515918384803262011-02-28T17:42:00.000-05:002011-02-28T17:42:00.604-05:00MVC3 - Server Error in '/' Application. The resource cannot be found.<div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Problem:<o:p></o:p></b></div><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;">MVC3 – You added your HttpPost method in your Controller, and you get:</div><h1 style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span style="color: red; font-family: Verdana; font-size: 18.0pt; font-weight: normal;">Server Error in '/' Application.<o:p></o:p></span></h1><h1 align="center" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-align: center;"><span style="color: red; font-family: Verdana; font-size: 18.0pt; font-weight: normal;"> <hr align="center" color="silver" noshade="" size="1" width="100%" /> </span></h1><h2 style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><i><span style="color: maroon; font-family: Verdana; font-size: 14.0pt; font-weight: normal;">The resource cannot be found.</span></i><span style="color: maroon; font-family: Verdana; font-size: 14.0pt; font-weight: normal;"><o:p></o:p></span></h2><div class="MsoNormal" style="border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in;"><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt; mso-bidi-font-family: Arial;">Description:</span></b></span><span class="apple-converted-space"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt; mso-bidi-font-family: Arial;"> </span></b></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;">HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.</span></span><span class="apple-converted-space"><span style="color: black; font-family: Arial; font-size: 8.5pt;"> </span></span><span style="color: black; font-family: Arial; font-size: 8.5pt;"><br />
<br />
</span><span class="apple-style-span"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt; mso-bidi-font-family: Arial;">Requested URL:</span></b></span><span class="apple-converted-space"><b><span style="color: black; font-family: Verdana; font-size: 8.5pt; mso-bidi-font-family: Arial;"> </span></b></span><span class="apple-style-span"><span style="color: black; font-family: Arial; font-size: 8.5pt;">/Movies/Edit/1</span></span></div></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Code:</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>[<span style="color: #2b91af;">HttpPost</span>]<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> <span style="color: #2b91af;">ActionResult</span> Edit(<span style="color: #2b91af;">Movie</span> model)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span><span style="color: blue;">try</span><o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">var</span> movie = db.Movies.Find(model.ID);<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>UpdateModel(movie);<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>db.SaveChanges();<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">return</span> RedirectToAction(<span style="color: #a31515;">"Details"</span>, <span style="color: blue;">new</span> {id=model.ID});<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span>)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>ModelState.AddModelError(<span style="color: #a31515;">""</span>, <span style="color: #a31515;">"Edit Failure, see inner exception"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">return</span> View(model);<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b style="mso-bidi-font-weight: normal;">Solution:<o:p></o:p></b></div><div class="MsoNormal">You forgot to add the Get method to the Controller class:</div><div class="MsoNormal">Code:</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> <span style="color: #2b91af;">ActionResult</span> Edit(<span style="color: blue;">int</span> id)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">var</span> movie = db.Movies.Find(id);<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">if</span> (movie == <span style="color: blue;">null</span>)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>RedirectToAction(<span style="color: #a31515;">"Index"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">return</span> View(movie);<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal"><br />
</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com2tag:blogger.com,1999:blog-6541636783175030762.post-73689762142559395162011-02-28T00:14:00.001-05:002011-02-28T14:45:29.837-05:00SqlServer: Saving changes is not permitted. The changes you have made require the followign tables to be dropped and re-created<div class="MsoNormal"><b>Problem:</b></div><div class="MsoNormal">Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b>Solution:</b></div><div class="MsoNormal">This is different than the default in Sql Server 2005, where you can automatically drop and recreate a table in the designer. Solution is simple, and doesn't require you to lose your changes.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Screenshots:</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-Tsk7R4vrYcGL0KMeY9FN8h-ZhTe8cOO4m9HsD6ag1freuzTcPbV4bMnzL_XQT4Imy14B52BbXTi68ku4IZFGOLLBYWHJCfcDTPZ45nGR3HuJ7xxWMSLexg-7H9E1oN-bJCWpYLH0i3M/s1600/sqlsavechangesdialog.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="254" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-Tsk7R4vrYcGL0KMeY9FN8h-ZhTe8cOO4m9HsD6ag1freuzTcPbV4bMnzL_XQT4Imy14B52BbXTi68ku4IZFGOLLBYWHJCfcDTPZ45nGR3HuJ7xxWMSLexg-7H9E1oN-bJCWpYLH0i3M/s320/sqlsavechangesdialog.png" width="320" /></a></div><div class="separator" style="clear: both; text-align: left;">In Sql Server Management Studio 2008, go to tools <span style="font-family: Wingdings;">à</span> options, in the options window, left pane Designers, and on the right side uncheck Prevent saving changes that require table re-creation.</div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsa_qWZCSw_bIRN4kmqm26GKSCY-rUUPgpSAxu-2caTSpBpLavNog0FqM4qZqDSeGyMhhz8B-YN4o6PRVnMiy0ewvgiGrZTHZvzySRaLbrlzWauNuu_CK09OOXOLFGJY0EXXyI8cyrpEc/s1600/sqlOptionsDesignersTable.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="185" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsa_qWZCSw_bIRN4kmqm26GKSCY-rUUPgpSAxu-2caTSpBpLavNog0FqM4qZqDSeGyMhhz8B-YN4o6PRVnMiy0ewvgiGrZTHZvzySRaLbrlzWauNuu_CK09OOXOLFGJY0EXXyI8cyrpEc/s320/sqlOptionsDesignersTable.png" width="320" /></a></div><div class="MsoNormal"><span style="font-family: 'Times New Roman'; font-size: 12pt;"><br />
</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-35988923655654234042011-02-28T00:08:00.000-05:002011-02-28T00:08:05.630-05:00System.InvalidOperationException was unhandled by user code The model backing the 'SomeContext' context has changed since the database was created<b>Problem:</b><br />
Received the following exception when adding a field to an Entity class:<br />
<br />
<br />
<div class="MsoNormal">System.InvalidOperationException was unhandled by user code</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>Message=The model backing the 'MovieDBContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>Source=EntityFramework</div><div class="MsoNormal">Full Stack Trace at the end.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Code the exception occurred:</div><div class="MsoNormal"></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">MovieDBContext</span> db = <span style="color: blue;">new</span> <span style="color: #2b91af;">MovieDBContext</span>();<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> <span style="color: #2b91af;">ActionResult</span> Index()<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">var</span> movies = <span style="color: blue;">from</span> m <span style="color: blue;">in</span> db.Movies<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">where</span> m.ReleaseDate > <span style="color: blue;">new</span> <span style="color: #2b91af;">DateTime</span>(1984, 6, 1)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">select</span> m;<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><br />
</div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">return</span> View(movies.ToList());<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div><br />
<div class="MsoNormal"><br />
</div><div class="MsoNormal"><b>Solution:</b></div><div class="MsoNormal"></div><div class="MsoNormal">Update the table in Sql Server to have the additional column you added to your entitiy class.</div><div class="MsoNormal"><br />
</div><br />
<div class="MsoNormal"><br />
</div><div class="MsoNormal"><b>Full Stack Trace:</b></div><div class="MsoNormal"></div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>StackTrace:</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Data.Entity.Database.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Data.Entity.Database.DbDatabase.<>c__DisplayClass8.<initialize>b__5()</initialize></div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Data.Entity.Database.DbDatabase.Initialize(Boolean force)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Data.Entity.Internal.InternalContext.Initialize()</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Data.Entity.Internal.Linq.InternalSet`1.get_Provider()</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at MvcMovie.Controllers.MoviesController.Index() in xxxx\visual studio 2010\Projects\MovieApp\MvcMovie\Controllers\MoviesController.cs:line 16</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at lambda_method(Closure , ControllerBase , Object[] )</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<invokeactionmethodwithfilters>b__12()</invokeactionmethodwithfilters></div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)</div><br />
<div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-16696370664068180212011-02-26T16:06:00.001-05:002011-02-26T21:10:27.807-05:00System.ServiceModel.CommunicationException was unhandled Exception<b><span class="Apple-style-span" style="font-size: large;">Problem:</span></b><br />
<div class="MsoNormal">Message=The underlying connection was closed: The connection was closed unexpectedly.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"></div><div class="MsoNormal">I was making a WCF c<span class="Apple-style-span" style="font-family: inherit;">lient/ser</span>vice, I ran it for the first time and got that exception. So, my WCF service had an OperationContract to return a DataTable like so:</div><div class="MsoNormal"><br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New", Courier, Monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><br />
<pre class="csharpcode">[ServiceContract]
<span class="kwrd">public</span> <span class="kwrd">interface</span> IUserService
{
[OperationContract]
DataTable GetApprovedUser();
}
</pre></div><div class="MsoNormal"><o:p></o:p></div><div class="MsoNormal"><o:p></o:p></div><br />
<div class="MsoNormal">And it was implemented like this:<o:p></o:p></div><div class="MsoNormal"><br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New", Courier, Monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><br />
<pre class="csharpcode"><span class="kwrd">public</span> DataTable GetApprovedUser()
{
DataTable dt = <span class="kwrd">new</span> DataTable();
dt.Columns.Add(<span class="str">"UserId"</span>, <span class="kwrd">typeof</span> (Int64));
dt.Columns.Add(<span class="str">"IsApproved"</span>, <span class="kwrd">typeof</span> (<span class="kwrd">bool</span>));
DataRow newUser = dt.NewRow();
newUser[<span class="str">"UserId"</span>] = 1000;
newUser[<span class="str">"IsApproved"</span>] = <span class="kwrd">true</span>;
dt.Rows.Add(newUser);
newUser = dt.NewRow();
newUser[<span class="str">"UserId"</span>] = 1001;
newUser[<span class="str">"IsApproved"</span>] = <span class="kwrd">true</span>;
dt.Rows.Add(newUser);
newUser = dt.NewRow();
newUser[<span class="str">"UserId"</span>] = 1002;
newUser[<span class="str">"IsApproved"</span>] = <span class="kwrd">false</span>;
dt.Rows.Add(newUser);
newUser = dt.NewRow();
newUser[<span class="str">"UserId"</span>] = 1003;
newUser[<span class="str">"IsApproved"</span>] = <span class="kwrd">true</span>;
dt.Rows.Add(newUser);
<span class="kwrd">return</span> dt;
}
</pre></div><div class="MsoNormal"><br />
<br />
<div class="MsoNormal">And my Client:<o:p></o:p></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> ServiceReference1.<span style="color: #2b91af;">UserServiceClient</span> proxy = <span style="color: blue;">new</span> ServiceReference1.<span style="color: #2b91af;">UserServiceClient</span>();<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> User = proxy.Authenticate(<span style="color: #a31515;">"theuser"</span>, <span style="color: #a31515;">"somecrypt"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">foreach</span>(<span style="color: #2b91af;">DataRow</span> userRow <span style="color: blue;">in</span> proxy.GetApprovedUser().Tables[0].Rows)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: blue;">string</span>.Format(<span style="color: #a31515;">"User: {0}, IsApproved: "</span>, userRow[<span style="color: #a31515;">"UserId"</span>], userRow[<span style="color: #a31515;">"IsApproved"</span>]));<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"><br />
</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"><br />
</span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"><br />
</span></div><div class="MsoNormal"><span style="font-family: Consolas;"><b><span class="Apple-style-span" style="font-size: large;">Solution:</span></b></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;">Turns out that DataTables are not serializable, so I tried wrapping the DataTable in a DataSet like this:<o:p></o:p></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><br />
</div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;">Interface:<o:p></o:p></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> [<span style="color: #2b91af;">ServiceContract</span>]<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IUserService</span><o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> [<span style="color: #2b91af;">OperationContract</span>]<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">void</span> DoWork();<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><br />
</div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> [<span style="color: #2b91af;">OperationContract</span>]<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> Authenticate(<span style="color: blue;">string</span> userName, <span style="color: blue;">string</span> aCryptKey);<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><br />
</div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> [<span style="color: #2b91af;">OperationContract</span>]<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataSet</span> GetApprovedUser();<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><br />
</div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><br />
</div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><br />
</div><div class="MsoNormal"></div><div class="MsoNormal">Implementation:<span class="Apple-style-span" style="font-size: 9.5pt;"><o:p></o:p></span></div><br />
<div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><br />
</div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">DataSet</span> GetApprovedUser()<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataSet</span> ds = <span style="color: blue;">new</span> <span style="color: #2b91af;">DataSet</span>();<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataTable</span> dt = <span style="color: blue;">new</span> <span style="color: #2b91af;">DataTable</span>();<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> ds.Tables.Add(dt);<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> dt.Columns.Add(<span style="color: #a31515;">"UserId"</span>, <span style="color: blue;">typeof</span> (<span style="color: #2b91af;">Int64</span>));<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> dt.Columns.Add(<span style="color: #a31515;">"IsApproved"</span>, <span style="color: blue;">typeof</span> (<span style="color: blue;">bool</span>));<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><br />
</div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataRow</span> newUser = dt.NewRow();<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> newUser[<span style="color: #a31515;">"UserId"</span>] = 1000;<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> newUser[<span style="color: #a31515;">"IsApproved"</span>] = <span style="color: blue;">true</span>;<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> dt.Rows.Add(newUser);<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> newUser = dt.NewRow();<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> newUser[<span style="color: #a31515;">"UserId"</span>] = 1001;<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> newUser[<span style="color: #a31515;">"IsApproved"</span>] = <span style="color: blue;">true</span>;<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> dt.Rows.Add(newUser);<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> newUser = dt.NewRow();<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> newUser[<span style="color: #a31515;">"UserId"</span>] = 1002;<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> newUser[<span style="color: #a31515;">"IsApproved"</span>] = <span style="color: blue;">false</span>;<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> dt.Rows.Add(newUser);<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> newUser = dt.NewRow();<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> newUser[<span style="color: #a31515;">"UserId"</span>] = 1003;<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> newUser[<span style="color: #a31515;">"IsApproved"</span>] = <span style="color: blue;">true</span>;<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> dt.Rows.Add(newUser);<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><br />
</div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">return</span> ds;<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;"><br />
</div><div class="MsoNormal" style="font-family: Consolas; font-size: 9.5pt;">And that fixed it.<o:p></o:p></div><br />
<br />
<br />
For those interested, here was the full stack trace:<br />
<br />
<br />
<div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>Message=The underlying connection was closed: The connection was closed unexpectedly.</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>Source=mscorlib</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>StackTrace:</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>Server stack trace: </div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>Exception rethrown at [0]: </div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at WCRTestClient.ServiceReference1.IUserService.GetApprovedUser()</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at WCRTestClient.ServiceReference1.UserServiceClient.GetApprovedUser() in xxxx\visual studio 2010\Projects\Test WCF\WCRTestClient\Service References\ServiceReference1\Reference.cs:line 64</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at WCRTestClient.Program.Main(String[] args) in xxxx\visual studio 2010\Projects\Test WCF\WCRTestClient\Program.cs:line 15</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Threading.ThreadHelper.ThreadStart_Context(Object state)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Threading.ThreadHelper.ThreadStart()</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>InnerException: System.Net.WebException</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>Message=The underlying connection was closed: The connection was closed unexpectedly.</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>Source=System</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>StackTrace:</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.Net.HttpWebRequest.GetResponse()</div><div class="MsoNormal"><span style="mso-spacerun: yes;"> </span>at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)</div><br />
<br />
</div>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com0tag:blogger.com,1999:blog-6541636783175030762.post-48167573223498903852011-02-22T17:30:00.002-05:002011-02-22T17:30:00.836-05:00C#: Parallel ForEach AggregateExceptionWhen working with Parallel.ForEach, you'll at some point want to handle exceptions cleanly. I found that the AggregateException class to be very helpful. Check out the following example to see how it works:<br />
<br />
<br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New", Courier, Monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><br />
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> AggregateExceptionDemo()
{
<span class="kwrd">byte</span>[] myData = <span class="kwrd">new</span> <span class="kwrd">byte</span>[500];
Random r = <span class="kwrd">new</span> Random();
r.NextBytes(myData);
<span class="kwrd">try</span>
{
DoWorkInParallel(myData);
}
<span class="kwrd">catch</span> (AggregateException ae)
{
<span class="kwrd">foreach</span> (var ex <span class="kwrd">in</span> ae.InnerExceptions)
{
<span class="kwrd">if</span> (ex <span class="kwrd">is</span> ArgumentException)
Console.WriteLine(ex.Message);
<span class="kwrd">else</span>
<span class="kwrd">throw</span> ex;
}
}
}
<span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> DoWorkInParallel(<span class="kwrd">byte</span>[] myData)
{
<span class="rem">// Use ConcurrentQueue to enable safe enqueueing from multiple threads.</span>
var exceptions = <span class="kwrd">new</span> ConcurrentQueue<exception>();
<span class="rem">// Execute the complete loop and capture all exceptions.</span>
Parallel.ForEach(myData, d =>
{
<span class="kwrd">try</span>
{
<span class="rem">// Cause a few exceptions, but not too many.</span>
<span class="kwrd">if</span> (d < 0x3)
<span class="kwrd">throw</span> <span class="kwrd">new</span> ArgumentException(String.Format(<span class="str">"value is {0:x}. Elements must be greater than 0x3."</span>, d));
<span class="kwrd">else</span>
Console.Write(d + <span class="str">" "</span>);
}
<span class="rem">// Store the exception and continue with the loop. </span>
<span class="kwrd">catch</span> (Exception e) { exceptions.Enqueue(e); }
});
<span class="rem">// Throw the exceptions here after the loop completes.</span>
<span class="kwrd">if</span> (exceptions.Count < 0) <span class="kwrd">throw</span> <span class="kwrd">new</span> AggregateException(exceptions);
}
</exception></pre>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com2tag:blogger.com,1999:blog-6541636783175030762.post-90134144899368349242011-02-11T00:24:00.001-05:002011-02-11T00:25:51.191-05:00C#: Parallel.ForEach Simple Example<div class="MsoNormal">The Parallel ForEach feature of .Net 4.0 makes threading even easier. There is no reason to not try to take advantage of today’s multi-core hardware. Thread synchronization aside, here’s a very simple sample:</div><br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New", Courier, Monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><br />
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Text;
<span class="kwrd">using</span> System.Threading.Tasks;
<span class="kwrd">namespace</span> ThreadingSamples
{
<span class="kwrd">class</span> Program
{
<span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)
{
List<<span class="kwrd">int</span>> numbers = <span class="kwrd">new</span> List<<span class="kwrd">int</span>>();
<span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i < 100; i++)
numbers.Add(i);
Parallel.ForEach(numbers, number =>
{
Console.WriteLine(number);
}
);
}
}
}
</pre>Anonymoushttp://www.blogger.com/profile/09056136569752231442noreply@blogger.com6