I added a table in my project which is along these lines:
Table table1 = new Table();
table1.RowGroups.Add(new TableRowGroup());
table1.RowGroups[1].Rows.Add(new TableRow());
TableRow currentRow = table1.RowGroups[1].Rows[1];
When I added the table, to reference it, i added a reference presentationFramework.dll to start using the namespace "System.Windows.Documents". Then it started giving me 3 errors
The type 'System.Windows.Markup.IAddChild' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
The type 'System.Windows.IInputElement' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
The type 'System.Windows.ContentElement' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
I don't understand this. What should I do to correct this error?
Please help me
Add a reference to PresentationCore DLL, which is also in the GAC and is required.
Brian
Related
We are getting eventually an IndexOutOfRange exception when running code like this:
result.Data = dbOptima.Database.ExecuteStoredProcedure(
task,
StoredProcedureValues.PROC_GET_TASKS).ToList();
,where ExecuteStoredProcedure does the following:
public static IEnumerable<TResult> ExecuteStoredProcedure<TResult>(this Database database, IStoredProcedure<TResult> procedure, string procedureName)
{
var parameters = CreateSqlParametersFromProperties(procedure);
var format = CreateSPCommand<TResult>(parameters, procedureName);
return database.SqlQuery<TResult>(format, parameters.Cast<object>).ToArray());
}
We cannot reproduce the problem locally, but using Application Insights the exception is registered quite often. The following is a call stack extract:
System.IndexOutOfRangeException:
at System.Data.ProviderBase.FieldNameLookup.GetOrdinal (System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.SqlClient.SqlDataReader.GetOrdinal (System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.TryGetColumnOrdinalFromReader (EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.CreateColumnMapFromReaderAndClrType (EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.Entity.Core.Objects.ObjectContext.InternalTranslate (EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryInternal (EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.Entity.Core.Objects.ObjectContext+<>c__DisplayClass65`1.<ExecuteStoreQueryReliably>b__64 (EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction (EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.Entity.Core.Objects.ObjectContext+<>c__DisplayClass65`1.<ExecuteStoreQueryReliably>b__63 (EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute (EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryReliably (EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQuery (EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext (EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Collections.Generic.List`1..ctor (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at System.Linq.Enumerable.ToList (System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
We've tried to reproduce the problem locally by:
making the stored procedure fail.
making the stored procedure return 0 results.
causing a mapping problem by renaming some model property.
with no success.
Typically, this error happens due to a mapping error in the datareader when you use ADO.NET, but this is not the case since we use EF 6 and it does not happen always, so we cannot really find where the problem is.
The problem is related to binding the result of the stored procedure with the model declared to be bound with the output of the stored procedure.
If the stored procedure retrieves more columns than the properties that the model has, even though the model is satisfied (because all the properties can be matched with columns of the stored procedure output), internally an exception is raised cause the model doesn't have properties to store some of the store procedure output values.
So, this can be fixed in two ways: either
adding properties in the model to contain the columns of the stored
procedure, or
removing the unnecessary columns of the stored procedure output.
The second approach is normally better, since this issue is making evident that some data returned by the stored procedure is no longer required, so it would be cleaner and more performant to remove the unneeded code in the stored procedure.
I am working on an old WebForms project.
Occasionally it won't build
The type 'HttpRequestMessage' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The exception above is thrown on Request on this line
public class MyController : ApiController
{
[System.Web.Http.HttpPost]
public string Test()
{
string data = Request.Content.ReadAsStringAsync().Result;
}
}
To be able to run the website, I simply have to Rebuild Solution (without changing anything at all).
Any idea what may be causing it?
Add below code in you web.config
<configuration>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</compilation>
</system.web>
</configuration>
I have an IEnumerable<Dictionary<string,string>> and I want to map it to an IEnumerable<Entity>. I was wondering what's the best way to do so?
E.g.
IEnumerable<Dictionary<string,string>> dictionary
where dictionary.Select(x=>x.Values.ToList()) which will give me the values I want to store/map to my entity object but the keys in the dictionary will tell it which entity to map to.
So I want to do something like if key == entityPropertyName, then insert value and I want to do that for the entire collection.
EDIT:
I tried this:
var serializer = new JavaScriptSerializer();
var csvToSave = serializer.Deserialize<entitiy>(serializer.Serialize(rows.ToDictionary(kvp=>kvp.Keys, kvp=>kvp.Values)));
But I get this issue:
Message :Type 'System.Collections.Generic.Dictionary`2[[System.Collections.Generic.Dictionary`2+KeyCollection[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.Dictionary`2+ValueCollection[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' is not supported for serialization/deserialization of a dictionary, keys must be strings or objects.
Source :System.Web.Extensions
I have the follow lines:
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
private global::AjaxControlToolkit.ToolkitScriptManager #__BuildControlToolkitScriptManager1() {
global::AjaxControlToolkit.ToolkitScriptManager #__ctrl;
and I got this error:
The type 'System.Web.UI.ScriptManager' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
I choose Add Reference>.Net>system.web.extension version 4.0 in visual web developer and still get same error .
What can I do?
I've written a custom grid view and I want to save grid DataSource in ViewState but I got this exception
Type '<>f__AnonymousType0`7[[System.Int32, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[System.Boolean, mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'
in Assembly 'ExtAspNet.Examples, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' is not marked as serializable.
Now, I want to know how can I keep the grid DataSource?
Anything that you attempt to put in the viewstate must be decorated with the [Serializable] attribute, but because you have an anonymous type, you can't do it.
But besides that, don't do what you are trying to do, it will increase your page size considerably and unnecessarily. If anything, put your data source in Session and rebind it on postback but don't put it on viewstate.
Note, though, that putting a huge amount of data in session is not scalable or a good practice either, you have to base your decission depending on the size of your data and how much time it takes to get the data from the backend store. Have you measured how expensive it is to get the data, could you use Cache instead of Session, for example?
if you are binding your gridview datasource with a datatable you can do like this....
Declare the datatable as follows and everything will work as expected
private string _theDataTable="theDataTable";
private DataTable theDataTable
{
get
{
if(ViewState[_theDataTable]==null)
return new DataTable();
return (DataTable)ViewState[_theDataTable];
}
set
{
ViewState[_theDataTable] = value;
}
}
cheers!