MVC 5 Razor System.Security.SecurityException - razor

Just created a new application and put the trust level Medium in web.config
<trust level="Medium" />
I need to test the application in Medium trust level because I have to host on shared server.
Now run the application and get error on this line
#Html.ActionLink("XYZ", "Index", "Home", new {area=""}, new {#class="link" })
Here is the complete error:
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
<span class="icon-bar"></span>
</button>
#Html.ActionLink("xyz", "Index", "Home",
new { area = "" }, new { #class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
Stack Trace:
[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) +34
System.Security.CodeAccessPermission.Demand() +46
System.Web.HttpContext.System.IServiceProvider.GetService(Type service) +54
System.Web.HttpContextWrapper.GetService(Type serviceType) +13
System.Web.WebPages.UrlRewriterHelper.IsUrlRewriterTurnedOn(HttpContextBase httpContext) +157
System.Web.WebPages.UrlRewriterHelper.WasRequestRewritten(HttpContextBase httpContext) +37
System.Web.WebPages.UrlUtil.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath) +229
System.Web.WebPages.UrlUtil.GenerateClientUrl(HttpContextBase httpContext, String contentPath) +120
System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues) +324
System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, String protocol, String hostName, String fragment, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues) +100
System.Web.Mvc.HtmlHelper.GenerateLinkInternal(RequestContext requestContext, RouteCollection routeCollection, String linkText, String routeName, String actionName, String controllerName, String protocol, String hostName, String fragment, RouteValueDictionary routeValues, IDictionary`2 htmlAttributes, Boolean includeImplicitMvcValues) +96
System.Web.Mvc.HtmlHelper.GenerateLink(RequestContext requestContext, RouteCollection routeCollection, String linkText, String routeName, String actionName, String controllerName, String protocol, String hostName, String fragment, RouteValueDictionary routeValues, IDictionary`2 htmlAttributes) +71
System.Web.Mvc.HtmlHelper.GenerateLink(RequestContext requestContext, RouteCollection routeCollection, String linkText, String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, IDictionary`2 htmlAttributes) +66
System.Web.Mvc.Html.LinkExtensions.ActionLink(HtmlHelper htmlHelper, String linkText, String actionName, String controllerName, RouteValueDictionary routeValues, IDictionary`2 htmlAttributes) +187
System.Web.Mvc.Html.LinkExtensions.ActionLink(HtmlHelper htmlHelper, String linkText, String actionName, String controllerName, Object routeValues, Object htmlAttributes) +115
ASP._Page_Views_Shared__Layout_cshtml.Execute() in d:\TestProjects\Medium\Medium\Views\Shared\_Layout.cshtml:19
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +270
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +121
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +145
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer) +41
System.Web.WebPages.<>c__DisplayClass3.<RenderPageCore>b__2(TextWriter writer) +335
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +42
System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, HelperResult content) +45
System.Web.WebPages.WebPageBase.Write(HelperResult result) +53
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +178
System.Web.WebPages.WebPageBase.PopContext() +229
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +154
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +695
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +321
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9742689
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

I had the same problem a few weeks ago. My problem with the trust medium level was that my cshtml had a "~" at the javascript tag, like:
<script src="~/Scripts/foo.js"></script>
Removing the "~" simply resolved my problem.
It's a weird error because it points to a Razor declaration instead of the "~" line. Although the "~" is a special Razor symbol in this case.
Hope this might help.

Related

I am getting an exception error when running the my ASP.NET web application,

I am getting an exception error when running the my ASP.NET web application. I think it has to due my an enum by I am not sure. I have done some research on "Value cannot be null" and "Parameter name: source" exceptions, just don't understand some of the solutions presented and not sure if they directly apply to my issue.
Server Error in '/' Application.
________________________________________
Value cannot be null.
Parameter name: source
Description: 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.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: source
Source Error:
Line 8: <h1>ASP.NET</h1>
Line 9: <div>
Line 10: There are #Model.Count() restaurants in the db.
Line 11: </div>
Line 12:
Source File: C:\Users\cef19\source\repos\OdeToFood\OdeToFood.Web\Views\Home\Index.cshtml Line: 10
Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: source]
System.Linq.Enumerable.Count(IEnumerable`1 source) +4960432
ASP._Page_Views_Home_Index_cshtml.Execute() in C:\Users\cef19\source\repos\OdeToFood\OdeToFood.Web\Views\Home\Index.cshtml:10
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
System.Web.WebPages.StartPage.RunPage() +17
System.Web.WebPages.StartPage.ExecutePageHierarchy() +73
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +235
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__4() +198
System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +11
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45
System.Web.Mvc.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult, Controller controller) +13
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9847873
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163
________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4210.0
Hi this is additional information to help address my issue. Thanks Chris
**********************************************************************
Here is my Controller:
using OdeToFood.Data.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace OdeToFood.Web.Controllers
{
public class HomeController : Controller
{
IRestaurantData db;
public HomeController()
{
db = new InMemoryRestaurantData();
}
public ActionResult Index()
{
var model = db.GetAll();
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
}
****************************************************************
Here are my Models:
CuisineType.cs Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OdeToFood.Data.Models
{
public enum CuisineType
{
None,
Italian,
Indian,
French
}
}
****************************************************
Here is my Restaurant.cs Model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OdeToFood.Data.Models
{
public class Restaurant
{
public int ID { get; set; }
public string Name { get; set; }
public CuisineType Cuisine { get; set; }
}
}
****************************************************
Here is my Class from my Services folder named InMemoryRestaurantData.cs
using OdeToFood.Data.Models;
using System;
using System.Collections.Generic;
using System.Linq;
namespace OdeToFood.Data.Services
{
public class InMemoryRestaurantData : IRestaurantData
{
List<Restaurant> restaurants;
public InMemoryRestaurantData()
{
restaurants = new List<Restaurant>()
{
new Restaurant { ID = 1, Name="Scott's Pizza", Cuisine= CuisineType.Italian},
new Restaurant { ID = 2, Name="Tersiguels", Cuisine= CuisineType.French},
new Restaurant { ID = 3, Name="Mango Grove", Cuisine= CuisineType.Indian},
};
}
public IEnumerable<Restaurant> GetAll()
{
return restaurants.OrderBy(r => r.Name);
}
}
}
********************************************
Here is my class from my Services Folder named IRestaurantData.cs
using OdeToFood.Data.Models;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OdeToFood.Data.Services
{
public interface IRestaurantData
{
IEnumerable<Restaurant> GetAll();
}
}
***************************************
Here is my Index View
#{
ViewBag.Title = "Home Page";
}
<div class="jumbotron">
<h1>ASP.NET</h1>
<div>
There are #Enumerable.Count(Model) restaurants in the db.
</div>
</div>
*********************************************************
Hi I figured out the issue. I needed to have the model inside of my parentheses. See code public ActionResult Index()
{
var model = db.GetAll();
return View(model);
}

An item with the same key has already been added on form submit MVC 4

An item with the same key has already been added
Stack Trace:
[ArgumentException: An item with the same key has already been added.]
System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52
System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +10695474
System.Linq.Enumerable.ToDictionary(IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) +247
System.Linq.Enumerable.ToDictionary(IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer) +90
System.Web.Mvc.ModelBindingContext.get_PropertyMetadata() +157
System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +213
System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) +88
System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Object model) +53
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +1314
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +416
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +317
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +117
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__1e(AsyncCallback asyncCallback, Object asyncState) +446
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +302
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__17(AsyncCallback asyncCallback, Object asyncState) +30
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +382
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +317
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +15
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__2(AsyncCallback asyncCallback, Object asyncState) +71
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +249
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Why JSON DeSerialization fails in C#?

I am trying to De-serialize the string using Newtonsoft.Json dll of
RunTime Version
v2.0.50727
Version
4.5.0.0.
Target FrameWork
.Net Framework 2.0
To String:
jsonString ="{\"RelatedExceptions\":[{\"ClassName\":\"System.Web.Services.Protocols.SoapException\",\"Message\":\"Exception of type Microsoft.SharePoint.SoapServer.SoapServerException was thrown.\",\"Data\":{\"code\":{\"Namespace\":\"http://schemas.xmlsoap.org/soap/envelope/\",\"Name\":\"Server\",\"IsEmpty\":false},\"actor\":\"\",\"role\":\"\",\"subCode\":null,\"lang\":\"\"},\"InnerException\":null,\"HelpURL\":null,\"StackTraceString\":\" at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)\\r\\n at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)\\r\\n at abc.Common.SPWebServicesHelper.SPS2003ListsWs.Lists.GetListItems(String listName, String viewName, XmlNode query, XmlNode viewFields, String rowLimit, XmlNode queryOptions) in d:\\\\DeployerWorkingCopy\\\\TzDE2 .net2\\\\abc.Common.SPWebServicesHelper\\\\Web References\\\\SPS2003ListsWs\\\\Reference.cs:line 484\\r\\n at abc.Common.SPHandlerBase.WSWrappers.SPS2003ListsWsWrapper.GetListItems(String serviceUrl, String listName, String viewName, XmlNode query, XmlNode viewFields, String rowLimit, XmlNode queryOptions) in d:\\\\DeployerWorkingCopy\\\\TzDE2 .net2\\\\abc.Common.SPHandlerBase\\\\WebServicesWrappers\\\\SPS2003ListsWsWrapper.cs:line 215\\r\\n at abc.Common.SPS2003Handler.SPS2003ContentsManager.GetListItems(Site site, String listName, String strViewName, XmlNode ndQuery, XmlNode ndViewFields, String strRowLimit, XmlNode ndQueryOptions, String strWebId) in d:\\\\DeployerWorkingCopy\\\\TzDE2 .net2\\\\abc.Common.SPS2003Handler\\\\SPS2003ContentsManager.cs:line 5447\\r\\n at abc.Common.SPS2003Handler.SPSContentsManager.GetListItemCollectionPositionNext(SPList list, Folder folder, Int32 itemCountStartPosition, String orderBy) in d:\\\\DeployerWorkingCopy\\\\TzDE2 .net2\\\\abc.Common.SPS2003Handler\\\\SPSContentsManager.cs:line 8460\\r\\n at abc.Common.SPS2003Handler.SPSContentsManager.GetItemsAndProperties(SPList list, Folder folder, PropertyCollection props, Boolean readVersions, Boolean readOnlyFolders, Boolean readSecurity, Boolean readDiscussionItems) in d:\\\\DeployerWorkingCopy\\\\TzDE2 .net2\\\\abc.Common.SPS2003Handler\\\\SPSContentsManager.cs:line 8569\",\"RemoteStackTraceString\":null,\"RemoteStackIndex\":0,\"ExceptionMethod\":\"8\\nReadResponse\\nSystem.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\\nSystem.Web.Services.Protocols.SoapHttpClientProtocol\\nSystem.Object[] ReadResponse(System.Web.Services.Protocols.SoapClientMessage, System.Net.WebResponse, System.IO.Stream, Boolean)\",\"HResult\":-2146233087,\"Source\":\"System.Web.Services\",\"WatsonBuckets\":null}],\"Resolution\":\"\",\"EntryType\":1,\"Description\":\"Failed to read items of list: http://spportal:33333/_layouts/1033/lstman.aspx\\r\\n\\n \\n\\tList does not exist\\n\\n\\tThe page you selected contains a list that does not exist. It may have been deleted by another user. Click \\\"Home\\\" at the top of the page to return to your Web site.\\n\\t\\n 0x82000006\\n \",\"TimeStamp\":\"2013-05-08T11:45:54.299965+05:45\"}"
Deserialization Method call
JsonConvert.DeserializeObject<ExecutionReportEntry>(jsonString);
Result :-
StackTrace:
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 256
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract, JsonConverter converter) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 230
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IWrappedDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, String id) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 728
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateDictionary(JsonReader reader, JsonDictionaryContract contract, String id) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 679
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 462
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 245
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract, JsonConverter converter) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 230
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 126
at Newtonsoft.Json.Serialization.JsonSerializerProxy.DeserializeInternal(JsonReader reader, Type objectType) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerProxy.cs:line 174
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:line 461
at Newtonsoft.Json.Serialization.JsonFormatterConverter.Convert(Object value, Type type) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonFormatterConverter.cs:line 62
at System.Runtime.Serialization.SerializationInfo.GetValueNoThrow(String name, Type type)
at System.Exception..ctor(SerializationInfo info, StreamingContext context)
at Void .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)(Object , Object[] )
at Newtonsoft.Json.Serialization.DefaultContractResolver.<>c__DisplayClass9.<CreateISerializableContract>b__8(Object[] args) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:line 634
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializable(JsonReader reader, JsonISerializableContract contract, String id) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 865
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 473
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 245
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract, JsonConverter converter) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 230
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IWrappedCollection wrappedList, JsonReader reader, String reference, JsonArrayContract contract) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 816
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.<>c__DisplayClass1.<CreateAndPopulateList>b__0(IList l, Boolean isTemporaryListReference) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 759
at Newtonsoft.Json.Utilities.CollectionUtils.CreateAndPopulateList(Type listType, Action`2 populateList) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Utilities\CollectionUtils.cs:line 242
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateList(JsonReader reader, String reference, JsonArrayContract contract) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 747
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String reference) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 510
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 247
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueProperty(JsonReader reader, JsonProperty property, JsonConverter propertyConverter, Object target, Boolean gottenCurrentValue, Object currentValue) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 222
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndConstructorValues(JsonObjectContract contract, JsonReader reader, Type objectType) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 1101
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectFromNonDefaultConstructor(JsonReader reader, JsonObjectContract contract, ConstructorInfo constructorInfo, String id) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 999
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, String id) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 968
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 444
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 245
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract, JsonConverter converter) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 230
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 126
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:line 483
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:line 461
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonConvert.cs:line 925
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonConvert.cs:line 885
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonConvert.cs:line 842
at abc.Common.Collection.EsentErEntries`1.GetByKey(Double key) in d:\DeployerWorkingCopy\TzDE2 .net2\abc.Common\Collection\EsentDbWrapper.cs:line 748
Json in a more readable format:
{
"RelatedExceptions": [
{
"ClassName": "System.Web.Services.Protocols.SoapException",
"Message": "Exception of type Microsoft.SharePoint.SoapServer.SoapServerException was thrown.",
"Data": {
"code": {
"Namespace": "http://schemas.xmlsoap.org/soap/envelope/",
"Name": "Server",
"IsEmpty": false
},
"actor": "",
"role": "",
"subCode": null,
"lang": ""
},
"InnerException": null,
"HelpURL": null,
"StackTraceString": " at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)\r\n at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)\r\n at abc.Common.SPWebServicesHelper.SPS2003ListsWs.Lists.GetListItems(String listName, String viewName, XmlNode query, XmlNode viewFields, String rowLimit, XmlNode queryOptions) in d:\\DeployerWorkingCopy\\TzDE2 .net2\\abc.Common.SPWebServicesHelper\\Web References\\SPS2003ListsWs\\Reference.cs:line 484\r\n at abc.Common.SPHandlerBase.WSWrappers.SPS2003ListsWsWrapper.GetListItems(String serviceUrl, String listName, String viewName, XmlNode query, XmlNode viewFields, String rowLimit, XmlNode queryOptions) in d:\\DeployerWorkingCopy\\TzDE2 .net2\\abc.Common.SPHandlerBase\\WebServicesWrappers\\SPS2003ListsWsWrapper.cs:line 215\r\n at abc.Common.SPS2003Handler.SPS2003ContentsManager.GetListItems(Site site, String listName, String strViewName, XmlNode ndQuery, XmlNode ndViewFields, String strRowLimit, XmlNode ndQueryOptions, String strWebId) in d:\\DeployerWorkingCopy\\TzDE2 .net2\\abc.Common.SPS2003Handler\\SPS2003ContentsManager.cs:line 5447\r\n at abc.Common.SPS2003Handler.SPSContentsManager.GetListItemCollectionPositionNext(SPList list, Folder folder, Int32 itemCountStartPosition, String orderBy) in d:\\DeployerWorkingCopy\\TzDE2 .net2\\abc.Common.SPS2003Handler\\SPSContentsManager.cs:line 8460\r\n at abc.Common.SPS2003Handler.SPSContentsManager.GetItemsAndProperties(SPList list, Folder folder, PropertyCollection props, Boolean readVersions, Boolean readOnlyFolders, Boolean readSecurity, Boolean readDiscussionItems) in d:\\DeployerWorkingCopy\\TzDE2 .net2\\abc.Common.SPS2003Handler\\SPSContentsManager.cs:line 8569",
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"ExceptionMethod": "8\nReadResponse\nSystem.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\nSystem.Web.Services.Protocols.SoapHttpClientProtocol\nSystem.Object[] ReadResponse(System.Web.Services.Protocols.SoapClientMessage, System.Net.WebResponse, System.IO.Stream, Boolean)",
"HResult": -2146233087,
"Source": "System.Web.Services",
"WatsonBuckets": null
}
],
"Resolution": "",
"EntryType": 1,
"Description": "Failed to read items of list: http://spportal:33333/_layouts/1033/lstman.aspx\r\n\n \n\tList does not exist\n\n\tThe page you selected contains a list that does not exist. It may have been deleted by another user. Click \"Home\" at the top of the page to return to your Web site.\n\t\n 0x82000006\n ",
"TimeStamp": "2013-05-08T11:45:54.299965+05:45"
}
Class
public enum ExecutionReportEntryType
{
Fatal,
Error,
Warning,
Info,
Success
}
public interface IExecutionReportEntry
{
string Description { get; }
ExecutionReportEntryType EntryType { get; }
IList<Exception> RelatedExceptions { get; }
string Resolution { get; set; }
DateTime TimeStamp { get; }
}
public class ExecutionReportEntry : IExecutionReportEntry
{
private readonly List<Exception> _relatedExceptions = new List<Exception>();
public IList<Exception> RelatedExceptions
{
get
{
// Removing the readonly mode as this causes problem during Deserializing process(which is used to store the data into the ESENT database)
return _relatedExceptions;
}
}
public virtual string Resolution
{
get { return string.Empty; }
set { }
}
public ExecutionReportEntryType EntryType { get; private set; }
public string Description { get; private set; }
public DateTime TimeStamp { get; private set; }
public ExecutionReportEntry(ExecutionReportEntryType entryType, string description)
: this(DateTime.Now, entryType, description, null)
{ }
public ExecutionReportEntry(ExecutionReportEntryType entryType, string description, Exception ex)
: this(DateTime.Now, entryType, description, ex)
{ }
[JsonConstructor]
public ExecutionReportEntry(DateTime timeStamp, ExecutionReportEntryType entryType, string description, Exception ex)
{
EntryType = entryType;
Description = description;
TimeStamp = timeStamp;
if (ex != null)
_relatedExceptions.Add(ex);
}
}
The RelatedExceptions property is 'readonly' for the (de)serializer.
Add a set to the property as well.
The same goes for the other private setters.
They need to be public for the serializer to set them.

Sql Server CE 4 and EF 4.1 CF Win 64 bit deployment

Hi I have a following problem. I've created a project in 32 bit operating system. There I have installed EF 4.1 and SQL CE 4 for 32 bit. I've created a test table and launched it. Everything works, i.e. there is a connection to db and CRUD operations happen.
In the reference pane I've set the copy local property for binaries EntityFramework.dll, System.Data.SqlServerCe.dll and System.Data.SqlServerCe.Entity.dll to true.
Then I copy pasted the project into machine with x64 OS.
It gives me the following error:
Could not load file or assembly 'System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. Access is denied.
Stack trace is
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName)
at System.Data.Common.DbProviderFactories.GetFactory(DataRow providerRow)
at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)
at System.Data.Entity.Infrastructure.SqlCeConnectionFactory.CreateConnection(String nameOrConnectionString)
at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
at System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel()
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
at System.Data.Entity.DbSet`1.Add(TEntity entity)
at CeEfCf3.MainWindow.Button_Click(Object sender, RoutedEventArgs e) in C:\Isis\CeEfCf3\CeEfCf3\MainWindow.xaml.cs:line 28
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at CeEfCf3.App.Main() in C:\Isis\CeEfCf3\CeEfCf3\obj\x86\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
I just want to make my application work on both x86 and x64 platforms.
You must include the required x64 and x86 binaries with your app, or install the SQL Server Compact 4.0 MSI on the machine - http://erikej.blogspot.com/2011/02/using-sql-server-compact-40-with.html
As per above, include both the x64 and x86 binaries OR set the processor type of your application to x86 (not all), then you do NOT have to distribute the x64 binares.

Deserializing dictionary with derived types using NewtonSoft's Json library

Given the following class structure, which includes a dictionary of derived objects, how can I serialize and deserialize using NewtonSoft’s Json library? When I deserialize, I am getting an exception. It looks like it is having issues reconstituting the dictionary.
[JsonObject(MemberSerialization.OptIn)]
public class GameObject
{
[JsonProperty]
public string Id { get; set; }
[JsonProperty]
public string Name { get; set; }
[JsonProperty]
public ConcurrentDictionary<string, Component> Components;
public GameObject()
{
Components = new ConcurrentDictionary<string, Component>();
}
}
[JsonObject(MemberSerialization.OptIn)]
public class Component
{
[JsonIgnore] // Ignore circular reference
public GameObject GameObject { get; set; }
public Component()
{
}
}
[JsonObject(MemberSerialization.OptIn)]
public class TestComponent : Component
{
[JsonProperty]
public int MyProperty { get; set; }
public TestComponent()
{
}
}
var originalJson = JsonConvert.SerializeObject(srcObject, Formatting.None,
new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
});
var newObject = JsonConvert.DeserializeObject<GameObject>(originalJson,
new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.All,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
});
Exception on the DeserializeObject call:
System.Reflection.TargetInvocationException was unhandled by user code
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Newtonsoft.Json.Serialization.JsonContract.InvokeOnDeserialized(Object o, StreamingContext context) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonContract.cs:line 135
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IWrappedDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, String id) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 638
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateDictionary(JsonReader reader, JsonDictionaryContract contract, String id) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 593
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 387
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 223
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueProperty(JsonReader reader, JsonProperty property, Object target, Boolean gottenCurrentValue, Object currentValue) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 198
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectFromNonDefaultConstructor(JsonReader reader, JsonObjectContract contract, String id) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 876
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, String id) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 846
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 396
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 223
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 208
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 120
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonSerializer.cs:line 421
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonSerializer.cs:line 413
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonConvert.cs:line 721
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonConvert.cs:line 683
at MF.Tests.GameServer.ComponentSerializationTests.TestSerializationOfObjectWithComponent() in C: \ComponentSerializationTests.cs:line 119
InnerException: System.NullReferenceException
Message=Object reference not set to an instance of an object.
Source=mscorlib
StackTrace:
at System.Collections.Concurrent.ConcurrentDictionary`2.InitializeFromCollection(IEnumerable`1 collection)
at System.Collections.Concurrent.ConcurrentDictionary`2.OnDeserialized(StreamingContext context)
InnerException:
Update:
If change the ConcurrentDictionary to a List or a Dictionary, the code works as expected.
What am I doing wrong?