PlatformNotSupportedException CE7 - compact-framework

I have a empty project (compact framework 3.5) for pda. I add a imagelist and i add a image in the list. When i deploy the project at a CE7 device (Motorola MC32N0) i get a PlatformNotSupportedException at the line
this.imageList1.Images.Add(((System.Drawing.Image)(resources.GetObject("resource"))));
The stacktrace is:
at System.Globalization.CompareInfo..ctor(Int32 culture)
at System.Globalization.CompareInfo.GetCompareInfo(Int32 culture)
at System.Globalization.CultureInfo.get_CompareInfo()
at System.Collections.Comparer..ctor(CultureInfo culture)
at System.Collections.Comparer..cctor()
at System.OrdinalComparer.EqualsStringImpl(String x, String y)
at System.StringComparerImpl.Equals(Object x, Object y)
at System.Collections.Hashtable.KeyEquals(Object item, Object key)
at System.Collections.Hashtable.get_Item(Object key)
at System.Globalization.CultureInfo.GetCultureInfoHelper(Int32 lcid, String name, String altName)
at System.Globalization.CultureInfo.GetCultureInfo(String name)
at System.Globalization.CompareInfo.GetSortingLCID(Int32 culture)
at System.Globalization.CompareInfo..ctor(Int32 culture)
at System.Globalization.CompareInfo.GetCompareInfo(Int32 culture)
at System.Globalization.CultureInfo.get_CompareInfo()
at System.Globalization.CultureInfo.GetHashCode()
at System.Collections.Hashtable.GetHash(Object key)
at System.Collections.Hashtable.InitHash(Object key, Int32 hashsize, UInt32& seed, UInt32& incr)
at System.Collections.Hashtable.get_Item(Object key)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture)
at System.Resources.ResourceManager.GetObject(String name)
at SmartDeviceProject5.Form1.InitializeComponent()
at SmartDeviceProject5.Form1..ctor()
at SmartDeviceProject5.Program.Main()
I only get this exception in CE7. Any ideas?

I think MC32xx has only a "core" CE7. I had a similar problem. Have you got installed Compact Framework 3.5 properly. What does the windows\wceload.exe show you? Maybe you have to install this seperately.

Related

NHibernate create criteria, add Restrictions on related table with nullable foreign key

I work on a Api project in .NET core 2.2 with NHibernate (5.2.5)
Table A has nullable foreign key from table B
I need to create a criteria to filter Table A, using a nullable foreign key (which is not null) that points to Table B, where the Status in Table B is 3
This is something what I have tried:
var criteria = _session.CreateCriteria<AgencyAgreement>();criteria.Add(Restrictions.Eq("BookingCartItem.Status", (int)BookingCartStatus.Cancelled));
also with and operator
criteria.Add(Restrictions.And(Restrictions.IsNotNull("BookingCartItem"), Restrictions.Eq("BookingCartItem.Status", (int)BookingCartStatus.Cancelled)));
but this is what I get as Error
at NHibernate.Persister.Entity.AbstractPropertyMapping.GetColumns(String propertyName)\r\n at NHibernate.Persister.Entity.AbstractPropertyMapping.ToColumns(String alias, String propertyName)\r\n at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetColumnsUsingProjection(ICriteria subcriteria, String propertyName)\r\n at NHibernate.Criterion.CriterionUtil.GetColumnNamesUsingPropertyName(ICriteriaQuery criteriaQuery, ICriteria criteria, String propertyName, Object value, ICriterion critertion)\r\n at NHibernate.Criterion.SimpleExpression.ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)\r\n at NHibernate.Criterion.LogicalExpression.ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)\r\n at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetWhereCondition()\r\n at NHibernate.Loader.Criteria.CriteriaJoinWalker..ctor(IOuterJoinLoadable persister, CriteriaQueryTranslator translator, ISessionFactoryImplementor factory, ICriteria criteria, String rootEntityName, IDictionary2 enabledFilters)\r\n at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, String rootEntityName, IDictionary2 enabledFilters)\r\n at NHibernate.Impl.SessionImpl.ListAsync(CriteriaImpl criteria, IList results, CancellationToken cancellationToken)\r\n at NHibernate.Impl.CriteriaImpl.ListAsync(IList results, CancellationToken cancellationToken)\r\n at NHibernate.Impl.CriteriaImpl.ListAsync[T](CancellationToken cancellationToken)\r\n at HASELT.merakzy.Services.Features.Documents.QueryTravelAgreements.Handler.Handle(Request request, CancellationToken cancellationToken) in C:\Users\Asus\Desktop\merakzy-sourcecode\merakzy-master\src\HASELT.merakzy.Services\Features\AgencyDocuments\QueryTravelAgreements.cs:line 115\r\n at MediatR.Pipeline.RequestPostProcessorBehavior2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate1 next)\r\n at MediatR.Pipeline.RequestPreProcessorBehavior2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate1 next)\r\n at lambda_method(Closure , Object )\r\n at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()\r\n at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n at System.Threading.Tasks.ValueTask`1.get_Result()\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()
var criteria = _session.CreateCriteria<AgencyAgreement>();
criteria.CreateCriteria(nameof(AgencyAgreement.BookingCartItem))
.Add(Restrictions.Eq("Status", (int)BookingCartStatus.Cancelled));
or using linq if the properties are known at compile time
var query = _session.Query<AgencyAgreement>();
query = query.Where(a => a.BookingCartItem.Status == (int)BookingCartStatus.Cancelled);

Failed insert or update when add type column long text using NHibernate in VB.NET

I'm using Nhibernate 4 and FluentNhibernate 2.0.3 with db Microsoft Access 2000. I can't save the entry on the DB because i'm getting an error when I go to insert the Note field sending a request HTTP POST for example:
{
"Note": "bla bla bla"
}
NOTE: In the database table, the column "Note" is setted as "LONG TEXT" (Not Required)
Could It be a problem of conversion of data Types?
Here's the stack trace:
NHibernate.Exceptions.GenericADOException: could not insert: [Domain.Destinatari#1773][SQL: INSERT INTO `Destinatari` (Note, IDDestinatario) VALUES (?, ?)] ---> System.Data.OleDb.OleDbException: Errore di sintassi nell'istruzione INSERT INTO.
in System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
in System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
in System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
in System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
in System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
in System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
in NHibernate.JetDriver.JetDbCommand.ExecuteNonQuery()
in NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
in NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
in NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
--- Fine della traccia dello stack dell'eccezione interna ---
in NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
in NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session)
in NHibernate.Action.EntityInsertAction.Execute()
in NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
in NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
in NHibernate.Engine.ActionQueue.ExecuteActions()
in NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
Below my mapping code:
Public Class DestinatariMap
Inherits ClassMap(Of Destinatari)
Public Sub New()
MyBase.New
LazyLoad()
Id(Function(x) x.IDDestinatario).GeneratedBy().Increment()
Map(Function(x) x.Note)
End Sub
End Class
Here's my Domain code:
Public Class Destinatari
Private _ID_Destinatario As Integer
Private _Note As String
Public Overridable Property IDDestinatario() As Integer
Get
Return Me._ID_Destinatario
End Get
Set
Me._ID_Destinatario = Value
End Set
End Property
Public Overridable Property Note() As String
Get
Return Me._Note
End Get
Set
Me._Note = Value
End Set
End Property
End Class
Thanks

SQLite CASE/WHEN isnumeric query

I have the following code that works in SQL:
"(CASE WHEN isnumeric(Installation) > 0 THEN cast(Installation as bigint) ELSE null END) "
I am trying to convert it to work in SQLite, but having trouble since I have very little experience in SQLite. Basically I want to cast/convert my stringcolumn (Installation) to a bigint, but need the validation to make sure it only contains numeric characters.
I have tried the following 3 variations, but not having luck. Just getting errors saying could not execute query
("(CASE WHEN Installation GLOB '*[^0-9]*' THEN cast(Installation as bigint) ELSE null END)");
("(SELECT Installation from ShortCycleWorkOrderCompletions WHERE Installation = REGEXP '*[^0-9]*'");
("(CASE WHEN REGEXP(Installation, '*[^0-9]*') THEN cast(Installation as bigint) ELSE null END");
Don't need all 3 to work, just one, and these were what I have tried.
NHibernate.Exceptions.GenericADOException: could not load an entity: [MapCall.Common.Model.Entities.ShortCycleWorkOrderCompletion#666][SQL: SELECT shortcycle0_.Id as Id510_0_, shortcycle0_.SAPCommunicationError as SAPCommu2_510_0_, shortcycle0_.SAPErrorCode as SAPError3_510_0_, shortcycle0_.ActiveMQStatus as ActiveMQ4_510_0_, shortcycle0_.WorkOrderNumber as WorkOrde5_510_0_, shortcycle0_.MiscInvoice as MiscInvo6_510_0_, shortcycle0_.BackOfficeReview as BackOffi7_510_0_, shortcycle0_.CompletionStatus as Completi8_510_0_, shortcycle0_.Notes as Notes510_0_, shortcycle0_.AdditionalWorkNeeded as Additio10_510_0_, shortcycle0_.Purpose as Purpose510_0_, shortcycle0_.TechnicalInspectedOn as Technic12_510_0_, shortcycle0_.TechnicalInspectedBy as Technic13_510_0_, shortcycle0_.ServiceFound as Service14_510_0_, shortcycle0_.ServiceLeft as Service15_510_0_, shortcycle0_.OperatedPointOfControl as Operate16_510_0_, shortcycle0_.AdditionalInformation as Additio17_510_0_, shortcycle0_.CurbBoxMeasurementDescription as CurbBox18_510_0_, shortcycle0_.Safety as Safety510_0_, shortcycle0_.HeatType as HeatType510_0_, shortcycle0_.MeterPositionLocation as MeterPo21_510_0_, shortcycle0_.MeterDirectionalLocation as MeterDi22_510_0_, shortcycle0_.MeterSupplementalLocation as MeterSu23_510_0_, shortcycle0_.ReadingDevicePositionalLocation as Reading24_510_0_, shortcycle0_.ReadingDeviceSupplementalLocation as Reading25_510_0_, shortcycle0_.ReadingDeviceDirectionalLocation as Reading26_510_0_, shortcycle0_.FSRId as FSRId510_0_, shortcycle0_.SerialNumber as SerialN28_510_0_, shortcycle0_.ManufacturerSerialNumber as Manufac29_510_0_, shortcycle0_.MeterSerialNumber as MeterSe30_510_0_, shortcycle0_.DeviceCategory as DeviceC31_510_0_, shortcycle0_.ActionFlag as ActionFlag510_0_, shortcycle0_.Installation as Install33_510_0_, shortcycle0_.ActivityReason as Activit34_510_0_, shortcycle0_.OldMeterSerialNumber as OldMete35_510_0_, shortcycle0_.QualityIssue as Quality36_510_0_, shortcycle0_.ReceivedAt as ReceivedAt510_0_, shortcycle0_.ShortCycleWorkOrderId as ShortCy38_510_0_, cast(shortcycle0_.WorkOrderNumber as varchar(12)) as formula90_0_, (CASE WHEN (CHARINDEX('SUCCESS', UPPER(cast(shortcycle0_.SAPErrorCode as varchar(8000)))) > 0) THEN 0 ELSE 1 END) as formula91_0_, (CASE WHEN (CHARINDEX('SUCCESS', UPPER(cast(shortcycle0_.ActiveMQStatus as varchar(8000)))) > 0) THEN 0 ELSE 1 END) as formula92_0_, (CASE WHEN (NOT TRIM(shortcycle0_.Installation) GLOB '*[^0-9]*') AND TRIM(shortcycle0_.Installation) like '_%' THEN CAST(TRIM(shortcycle0_.Installation) AS shortcycle0_.BIGINT) ELSE null END) as formula93_0_ FROM ShortCycleWorkOrderCompletions shortcycle0_ WHERE shortcycle0_.Id=?] ---> System.Data.SQLite.SQLiteException: SQL logic error or missing database
near ".": syntax error
at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister)
--- End of inner exception stack trace ---
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister)
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(Object id, Object optionalObject, ISessionImplementor session)
at NHibernate.Event.Default.DefaultLoadEventListener.LoadFromDatasource(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType)
at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType)
at NHibernate.Impl.SessionImpl.Get(String entityName, Object id)
at NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id)
at NHibernate.Impl.SessionImpl.Get[T](Object id)
at MMSINC.Data.NHibernate.SessionWrapper.Get[T](Object id) in C:\Solutions\mmsinc\MMSINC.Core\Data\NHibernate\SessionWrapper.cs:line 511
at MMSINC.Data.NHibernate.RepositoryBase`1.Find(Int32 id) in C:\Solutions\mmsinc\MMSINC.Core\Data\NHibernate\RepositoryBase.cs:line 104
at MMSINC.Utilities.ActionHelper`4.DoEditWithArgs[TModel](Int32 id, ActionHelperDoEditArgs args, Action`1 onModelFound) in C:\Solutions\mmsinc\MMSINC.Core.Mvc\Utilities\ActionHelper.cs:line 560
at MapCallMVC.Areas.ShortCycle.Controllers.ShortCycleWorkOrderCompletionController.Edit(Int32 id) in C:\Solutions\mapcall_mvc\MapCallMVC\Areas\ShortCycle\Controllers\ShortCycleWorkOrderCompletionController.cs:line 107
at MapCallMVC.Tests.Controllers.ShortCycleWorkOrderCompletionControllerTest.TestEdit404sIfShortCycleWorkOrderCompletionNotFound() in C:\Solutions\mapcall_mvc\MapCallMVC.Tests\Areas\ShortCycle\Controllers\ShortCycleWorkOrderCompletionControllerTest.cs:line 165
Almost the same answer :
CASE
WHEN
(NOT TRIM(Installation) GLOB '*[^0-9]*') AND TRIM(Installation) like '_%'
THEN CAST(TRIM(Installation) AS BIGINT)
END AS intInstallation
Explanation :
[^0-9] = every character that's not a number
With the NOT you get all the installation who doesn't have a character that's not a number
'_%' wildcard : _ any character once and % 0 or more of any character.
Since your edit, I look at the query :
THEN CAST(TRIM(shortcycle0_.Installation) AS shortcycle0_.BIGINT)
Replace it with :
THEN CAST(TRIM(shortcycle0_.Installation) AS BIGINT)
Use the below condition, which checks the existence of non numerical characters and the length of the trimmed value of Installation:
CASE
WHEN
(NOT TRIM(Installation) GLOB '*[^0-9]*') AND (LENGTH(TRIM(Installation)) > 0)
THEN CAST(TRIM(Installation) AS BIGINT)
END
Note that the data type BIGINT in SQLite, is actually INTEGER (1-8 bytes signed integer).

Windows AppFabric Server (win2k8) not working with distributed cache client on win2k3

We have windows appfabric cache server on win2k8 server and have installed “Windows Server 2003 Distributed Cache Client” on win2k3 web server from this link .
We are getting below exception while getting the cache object from cache factory.Can anybody help us to understand the cause of exception and its solution? Please note that below exception is not thrown while adding or getting cache data.
Our main purpose is to get & put cache data to windows appfabric server(win2k8) from win2k3 webserver client.
Exception:-
System.Runtime.Serialization.SerializationException: There was an error deserializing the object . Input string was not in a correct format. ---> System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
at System.Convert.ToInt32(Object value, IFormatProvider provider)
at System.Runtime.Serialization.FormatterConverter.ToInt32(Object value)
at System.Runtime.Serialization.SerializationInfo.GetInt32(String name)
at Microsoft.ApplicationServer.Caching.EvictionConfig..ctor(SerializationInfo info, StreamingContext context)
at ReadEvictionConfigFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, Int32 declaredTypeID, Type declaredType, String name, String ns)
at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, String name, String ns)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadSerializationInfo(XmlReaderDelegator xmlReader, Type type)
at ReadPolicyConfigFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, Int32 declaredTypeID, Type declaredType, String name, String ns)
at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, String name, String ns)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadSerializationInfo(XmlReaderDelegator xmlReader, Type type)
at ReadNamedCacheConfigurationFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, Int32 declaredTypeID, Type declaredType, String name, String ns)
at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, String name, String ns)
at System.Runtime.Serialization.NetDataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
--- End of inner exception stack trace ---
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader)
at Microsoft.ApplicationServer.Caching.Utility.Deserialize(Byte[][] buffers, Boolean checkTypeToLoad)
at Microsoft.ApplicationServer.Caching.RoutingClient.GetCacheProperties()
at Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCache(String cacheName)
Here is the code snippet :-
DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(1);
servers.Add(new DataCacheServerEndpoint("localhost", 22233));
configuration.Servers = servers;
DataCacheSecurity security = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None);
configuration.SecurityProperties = security;
DataCacheFactory factory = new DataCacheFactory(configuration);
DataCache cache = factory.GetCache("default"); // above exception is thrown here

LINQ to SQL delete producing "Specified cast is not valid" error

I've got a painfully simple table that is giving me a "Specified cast is not valid" error when I try to delete one or more rows. The table has two columns, an "id" as the primary key (INT), and a "name" (VARCHAR(20)), which maps to a String in the LINQ to SQL dbml file. Both of these statements produce the error:
dc.DeleteOnSubmit(dc.MyTables.Where(Function(x) x.id = 1).SingleOrDefault)
dc.DeleteAllOnSubmit(dc.MyTables)
I iterated through "MyTable" just to make sure there was no weird data, and there are only two rows:
id = 1, name = "first"
id = 2, name = "second"
The exception is happening on SubmitChanges. Here is the stack trace:
[InvalidCastException: Specified cast is not valid.]
System.Data.Linq.SingleKeyManager`2.TryCreateKeyFromValues(Object[] values, V& v) +59
System.Data.Linq.IdentityCache`2.Find(Object[] keyValues) +28
System.Data.Linq.StandardIdentityManager.Find(MetaType type, Object[] keyValues) +23
System.Data.Linq.CommonDataServices.GetCachedObject(MetaType type, Object[] keyValues) +48
System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation assoc, Object instance) +142
System.Data.Linq.ChangeProcessor.BuildEdgeMaps() +233
System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode) +59
System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) +331
System.Data.Linq.DataContext.SubmitChanges() +19
InpatientCensus.MaintenanceController.DeleteSoleCommunity(Int32 id) in C:\Documents and Settings\gregf\My Documents\Projects\InpatientCensus\InpatientCensus\Controllers\MaintenanceController.vb:14
lambda_method(ExecutionScope , ControllerBase , Object[] ) +128
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7() +52
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254
System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +192
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +399
System.Web.Mvc.Controller.ExecuteCore() +126
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +27
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +151
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Removing the association added to the DBML file allows rows to be deleted. Why would the association be causing the error? The associated columns are both VARCHAR(20) in the database and resolve to Strings in the DBML file.
What could possibly be causing a casting error?
Okay, upon seeing the update, the issue is the association between your two tables. This is a known bug in .NET 3.5 SP1 and will be fixed in .NET 4.0. Try your code on a .NET 4.0 Beta if you can.
We had a similar problem, caused by using non-integer keys. Details and hotfix number are here: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351358
Try:
dc.MyTables.DeleteOnSubmit(dc.MyTables.SingleOrDefault(x=>x.id==1));
dc.MyTables.DeleteAllOnSubmit(dc.MyTables);