I've been using StructureMap to inject ObjectContext (entities) into my repositories along with lazy-loaded POCO classes. This is my Structuremap registration.
For<WebEntities>().LifecycleIs(new HybridLifecycle()).Use(()=>new WebEntities());
I have defined Partial classes against my POCO classes to retrieve info that is not defined in my EDMX schema. e.g. Community.FloorPlanImages would be a getter which filters only the floor plan images from all available Images. Worked pretty well until I started to optimize my queries. Using EFProf, I found out that none of my connections were being closed. I could not use an 'using' statement since I'm injecting the ObjectContext itself into my repository. So, I added the following in my Application_EndRequest().
ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects();
This works too as long as I don't access anything on my Partial POCOs. I think StructureMap is closing the connection before we get to the Partial. I'm presented with the following error.
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
Any ideas to get around this?
UPDATE - Here's the stack trace
ObjectDisposedException: The
ObjectContext instance has been
disposed and can no longer be used for
operations that require a connection.]
System.Data.Objects.ObjectContext.EnsureConnection()
+8550458 System.Data.Objects.ObjectQuery1.GetResults(Nullable1
forMergeOption) +46
System.Data.Objects.ObjectQuery1.Execute(MergeOption
mergeOption) +31
System.Data.Objects.DataClasses.EntityCollection1.Load(List1
collection, MergeOption mergeOption)
+243 System.Data.Objects.DataClasses.EntityCollection1.Load(MergeOption
mergeOption) +25
System.Data.Objects.DataClasses.RelatedEnd.Load()
+37 System.Data.Objects.DataClasses.RelatedEnd.DeferredLoad()
+8032198 System.Data.Objects.Internal.LazyLoadBehavior.LoadProperty(TItem
propertyValue, String
relationshipName, String
targetRoleName, Boolean mustBeNull,
Object wrapperObject) +85
System.Data.Objects.Internal.<>c_DisplayClass72.<GetInterceptorDelegate>b__1(TProxy
proxy, TItem item) +101
System.Data.Entity.DynamicProxies.Community_39641A615E1AD4E19D637735C7A1EBEE61BF70BF579CDD4EBB0267E6636BEC62.get_Videos()
+55 Rdx.Web.UI.AppCode.Controllers.CDController.GetCDModel(SearchParams
searchParams, Int32 page, Boolean
isSorting) in
D:\Solutions\RDX\Rdx.Mvc\src\app\Rdx.Web.UI\AppCode\Controllers\CDController.cs:365
Rdx.Web.UI.AppCode.Controllers.CDController.Show(Int32
cid, Int32 bid) in
D:\Solutions\RDX\Rdx.Mvc\src\app\Rdx.Web.UI\AppCode\Controllers\CDController.cs:70
lambda_method(Closure , ControllerBase
, Object[] ) +145
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase
controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext
controllerContext, IDictionary2
parameters) +208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
controllerContext, ActionDescriptor
actionDescriptor, IDictionary2
parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
+55 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
filter, ActionExecutingContext
preContext, Func1 continuation) +263
System.Web.Mvc.<>c_DisplayClass17.b_14()
+19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
filter, ActionExecutingContext
preContext, Func1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
+19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
filter, ActionExecutingContext
preContext, Func1 continuation) +263
System.Web.Mvc.<>c_DisplayClass17.b_14()
+19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
filter, ActionExecutingContext
preContext, Func1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
+19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
filter, ActionExecutingContext
preContext, Func1 continuation) +263
System.Web.Mvc.<>c_DisplayClass17.b_14()
+19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext
controllerContext, IList1 filters,
ActionDescriptor actionDescriptor,
IDictionary2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
controllerContext, String actionName)
+343 System.Web.Mvc.Controller.ExecuteCore()
+116 System.Web.Mvc.ControllerBase.Execute(RequestContext
requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext
requestContext) +10
System.Web.Mvc.<>c_DisplayClassb.b_5()
+37 System.Web.Mvc.Async.<>c_DisplayClass1.b_0()
+21 System.Web.Mvc.Async.<>c_DisplayClass81.<BeginSynchronous>b__7(IAsyncResult
_) +12 System.Web.Mvc.Async.WrappedAsyncResult1.End()
+62 System.Web.Mvc.<>c_DisplayClasse.b_d()
+50 System.Web.Mvc.SecurityUtil.b__0(Action
f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action
action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult
asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult
result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+8841105 System.Web.HttpApplication.ExecuteStep(IExecutionStep
step, Boolean& completedSynchronously)
+184
**UPDATE 2: My Application_EndRequest is getting hit twice. What might cause that to happen? **
STACK on first hit.
Nhs.Web.UI.DLL!Nhs.Web.UI.Global.Application_EndRequest(object sender = {ASP.global_asax}, System.EventArgs e = {System.EventArgs}) Line 58 C#
System.Web.dll!System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0x95 bytes
System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step = {System.Web.HttpApplication.SyncEventExecutionStep}, ref bool completedSynchronously = true) + 0x4c bytes
System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x13e bytes
System.Web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0xad bytes
System.Web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest wr = {System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6}) + 0x1a2 bytes
System.Web.dll!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest wr) + 0x7d bytes
System.Web.dll!System.Web.Hosting.ISAPIRuntime.ProcessRequest(System.IntPtr ecb, int iWRType) + 0xfd bytes
[Appdomain Transition]
[Native to Managed Transition]
STACK on second hit
Nhs.Web.UI.DLL!Nhs.Web.UI.Global.Application_EndRequest(object sender = {ASP.global_asax}, System.EventArgs e = {System.EventArgs}) Line 58 C#
System.Web.dll!System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0x95 bytes
System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step = {System.Web.HttpApplication.SyncEventExecutionStep}, ref bool completedSynchronously = true) + 0x4c bytes
System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x13e bytes
System.Web.dll!System.Web.HttpApplication.ResumeStepsWaitCallback(object error) + 0x1e bytes
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state) + 0x2d bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xb0 bytes
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x5a bytes
mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x147 bytes
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() + 0x2d bytes
[Native to Managed Transition]
[Appdomain Transition]
[Native to Managed Transition]
Try it
For(typeof(WebEntities)).LifecycleIs(InstanceScope.Hybrid);
Global.asax
protected void Application_EndRequest(object sender, EventArgs e) {
ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects();
}
StructureMap will store the context every time that you do the access
var db = ObjectFactory.GetInstance<WebEntities>();
Related
let a= 4
let f arg=
printfn "%s" (nameof arg)
f a
On https://fable.io/ it's working but it's not working with https://tryfsharp.fsbolero.io/
The first run the code on a server. The second run the code with webassembly on the computer calling this it.
https://fable.io/ :
arg
https://tryfsharp.fsbolero.io/
let a= 4
Compiler output:
Compilation succeeded.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: may not call directly, should always be optimized away
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x34197b0 + 0x000ce> in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x34197b0 + 0x000f6> in <filename unknown>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) <0x3419060 + 0x00014> in <filename unknown>:0
at <StartupCode$WebFsc-Client>.$Executor+Run#42-1.Invoke (Microsoft.FSharp.Core.Unit unitVar) <0x4a37948 + 0x00028> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult] (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt, TResult result1, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] part2) <0x4a2e408 + 0x0001a> in <filename unknown>:0
at <StartupCode$FSharp-Core>.$Async+Delay#1064[T].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2e298 + 0x00036> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Invoke[T] (Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2ee98 + 0x000a0> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Bind[T,TResult] (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt, Microsoft.FSharp.Control.FSharpAsync`1[T] part1, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] part2) <0x4a374d8 + 0x00068> in <filename unknown>:0
at WebFsc.Client.ScreenOut+Wrap#109-3[a].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a373c8 + 0x00014> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Invoke[T] (Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2ee98 + 0x000a0> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult] (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt, TResult result1, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] part2) <0x4a2e408 + 0x00064> in <filename unknown>:0
at <StartupCode$FSharp-Core>.$Async+Delay#1064[T].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2e298 + 0x00036> in <filename unknown>:0
at <StartupCode$FSharp-Core>.$Async+Catch#1142[T].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2de80 + 0x00074> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Invoke[T] (Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2dae0 + 0x000a0> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Bind[T,TResult] (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt, Microsoft.FSharp.Control.FSharpAsync`1[T] part1, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] part2) <0x4a2d860 + 0x00068> in <filename unknown>:0
at Elmish.Cmd+bind#52-3[a].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2d5d8 + 0x00014> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Invoke[T] (Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x3a95c38 + 0x000a0> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult] (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt, TResult result1, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] part2) <0x3a90ed8 + 0x00064> in <filename unknown>:0
at <StartupCode$FSharp-Core>.$Async+Delay#1064[T].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x3a90ce8 + 0x00036> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives+StartWithContinuations#915[T].Invoke (Microsoft.FSharp.Core.Unit unitVar0) <0x3abbdd0 + 0x000b6> in <filename unknown>:0
at Microsoft.FSharp.Control.Trampoline.Execute (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] firstAction) <0x3a90560 + 0x0004a> in <filename unknown>:0
does the problem come from webassembly and why?
As #JL0PD correctly guessed in their comment, this is because Bolero's tryfsharp runs an older compiler that doesn't support nameof.
Updating it has been on my to-do list for ever, but there have been non-trivial changes both in Blazor and in the F# compiler service since the latest release of tryfsharp.bolero.
I am using IdentityServer3 samples to make a MVCView Service to work with asp.net identity. The samples work individually (i.e. plain idserver using asp.net identity Or MVC View Service showing custom login/logout pages).
However, when I try to combine both I get below error
Unhandled exception accessing: /core/connect/authorize
Autofac.Core.DependencyResolutionException: A delegate registered to create instances of 'System.Object' returned null.
at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Execute() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Registration.ExternalRegistrySource.<>c__DisplayClass8.<RegistrationsFor>b__3(IComponentContext c, IEnumerable`1 p) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Execute() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at IdentityServer3.Core.Services.Default.AutofacDependencyResolver.Resolve[T](String name) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Services\Default\AutofacDependencyResolver.cs:line 36
at MvcViewServiceSample.Startup.<>c.<Configuration>b__0_2(IDependencyResolver resolver) in D:\users\gbrapur\documents\visual studio 2015\Projects\IdentityServer3.Samples-old\source\MVC ViewService\MvcViewServiceSample\Startup.cs:line 59
at IdentityServer3.Core.Configuration.Hosting.AutofacConfig.<>c__DisplayClass1a.<Register>b__17(IComponentContext ctx) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\AutoFacConfig.cs:line 317
at Autofac.RegistrationExtensions.<>c__DisplayClass10`1.<Register>b__f(IComponentContext c, IEnumerable`1 p) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
at Autofac.Builder.RegistrationBuilder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Execute() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Registration.ExternalRegistrySource.<>c__DisplayClass8.<RegistrationsFor>b__3(IComponentContext c, IEnumerable`1 p) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Execute() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Activators.Reflection.AutowiringParameter.<>c__DisplayClass2.<CanSupplyValue>b__0() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Execute() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Registration.ExternalRegistrySource.<>c__DisplayClass8.<RegistrationsFor>b__3(IComponentContext c, IEnumerable`1 p) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.InstanceLookup.Execute() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Internal\AntiXssLibrary\UnicodeCharacterEncoder.cs:line 0
at IdentityServer3.Core.Extensions.InternalOwinExtensions.ResolveDependency(IOwinContext context, Type type) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Extensions\InternalOwinExtensions.cs:line 78
at IdentityServer3.Core.Extensions.InternalOwinExtensions.ResolveDependency[T](IOwinContext context) in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Extensions\InternalOwinExtensions.cs:line 70
at IdentityServer3.Core.Results.AuthorizeFormPostResult.<ExecuteAsync>d__6.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Results\AuthorizeFormPostResult.cs:line 61
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext() in c:\ballen\github\identity\IdSrv3\IdentityServer3\source\Core\Configuration\Hosting\NoCacheAttribute.cs:line 0
iisexpress.exe Error: 0 : 09/21/2017 09:49:09 +01:00 [Error] ()
my configuration for Idserver is as listed below -
appBuilder.Map("/core", core =>
{
var idSvrFactory = Factory.Configure();
// These registrations are also needed since these are dealt with using non-standard construction
idSvrFactory.Register(new Registration<HttpContext>(resolver => HttpContext.Current));
idSvrFactory.Register(new Registration<HttpContextBase>(resolver => new HttpContextWrapper(resolver.Resolve<HttpContext>())));
idSvrFactory.Register(new Registration<HttpRequestBase>(resolver => resolver.Resolve<HttpContextBase>().Request));
idSvrFactory.Register(new Registration<HttpResponseBase>(resolver => resolver.Resolve<HttpContextBase>().Response));
idSvrFactory.Register(new Registration<HttpServerUtilityBase>(resolver => resolver.Resolve<HttpContextBase>().Server));
idSvrFactory.Register(new Registration<HttpSessionStateBase>(resolver => resolver.Resolve<HttpContextBase>().Session));
idSvrFactory.ConfigureEPMUserService("AspId_CustomPK");
idSvrFactory.ViewService = new Registration<IViewService, MvcViewService<LogonWorkflowController>>();
var options = new IdentityServerOptions
{
SiteName = "IdentityServer3 - UserService-AspNetIdentity",
SigningCertificate = Certificate.Get(),
Factory = idSvrFactory,
AuthenticationOptions = new AuthenticationOptions
{
IdentityProviders = ConfigureAdditionalIdentityProviders
}
};
core.UseIdentityServer(options);
});
Error is thrown at this line
idSvrFactory.Register(new Registration<HttpContextBase>(resolver => new HttpContextWrapper(resolver.Resolve<HttpContext>())));
Note that i'm not using autofac or any other DI
I have an ASP.NET MVC I'm working on that works great when run from VS2015, but after deployment on IIS 8.5, I get the error in title when accessing controllers that use GET. Below there's a stack trace:
[IndexOutOfRangeException: Index was outside the bounds of the array.]
Accounting.Controllers.IesiriController.ShowInvoice(String tipDocument, String seria, Nullable`1 nrDocument, String dataDocument, String clientName) +12673
lambda_method(Closure , ControllerBase , Object[] ) +352
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +229
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +67
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +72
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +385
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +38
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +43
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +656
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +143
The target framework is 4.5
I have no idea why this is happening...
UPDATE (below is the ShowInvoice code):
public ActionResult ShowInvoice(string tipDocument, string seria, int? nrDocument, string dataDocument, string clientName)
{
//get company data
ViewBag.CompanyName = System.Configuration.ConfigurationManager.AppSettings["CompanyName"];
ViewBag.CodFiscal = System.Configuration.ConfigurationManager.AppSettings["CodFiscal"];
ViewBag.NrRegCom = System.Configuration.ConfigurationManager.AppSettings["NrRegCom"];
ViewBag.Adresa = System.Configuration.ConfigurationManager.AppSettings["Adresa"];
ViewBag.Adresa2 = System.Configuration.ConfigurationManager.AppSettings["Adresa2"];
ViewBag.IBAN = System.Configuration.ConfigurationManager.AppSettings["IBAN"];
ViewBag.Banca = System.Configuration.ConfigurationManager.AppSettings["Banca"];
if ((tipDocument == null) || (seria == null) || (nrDocument == null) || (dataDocument == null))
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
string dataDoc2 = dataDocument.Split(' ')[0];
string dataDoc = dataDoc2.Split('/')[1] + "/" + dataDoc2.Split('/')[0] + "/" + dataDoc2.Split('/')[2];
string dataDocTVA = dataDoc2.Split('/')[2] + "-" + dataDoc2.Split('/')[0] + "-" + dataDoc2.Split('/')[1];
//get Note
string queryNote = "SELECT TOP(1) * FROM Iesiris i "
+ "INNER JOIN Clients c ON i.ClientID = c.ID "
+ "INNER JOIN Articoles a ON i.ArticolID = a.ID "
+ "INNER JOIN SeriiFacturis s ON i.SeriaID = s.ID "
+ "WHERE i.NrDocument = " + nrDocument + " AND i.DataDocument = '" + dataDocument + "' AND s.Seria = '" + seria + "'";
var returnedNote = db.Database.SqlQuery<IesiriVMDetails>(queryNote).ToList();
ViewBag.note = returnedNote[0].Note;
int ClientID = returnedNote[0].ClientID;
//get date delegat
ViewBag.Delegat = returnedNote[0].Delegat;
ViewBag.DelegatSeria = returnedNote[0].DelegatSeria;
ViewBag.DelegatNumar = returnedNote[0].DelegatNumar;
ViewBag.DelegatEliberat = returnedNote[0].DelegatEliberat;
ViewBag.DelegatAuto = returnedNote[0].DelegatAuto;
//get emis de
ViewBag.fullName = returnedNote[0].EmisDe;
ViewBag.ci = returnedNote[0].CI;
//get date client
string queryClient = "SELECT TOP(1) * FROM Clients WHERE ID = " + ClientID;
var returnedClient = db.Database.SqlQuery<Clients>(queryClient).ToList();
if (returnedClient[0].VatPayer == true)
{
ViewBag.codFiscal = "RO" + returnedClient[0].FiscalCode;
}
else
{
ViewBag.codFiscal = returnedClient[0].FiscalCode;
}
/*
//get user data
string queryUser = "SELECT TOP(1) * FROM AspNetUsers WHERE UserName = '" + User.Identity.Name + "'";
var returnedUser = db.Database.SqlQuery<Users>(queryUser).ToList();
ViewBag.fullName = returnedUser[0].FirstName + " " + returnedUser[0].LastName;
ViewBag.ci = returnedUser[0].CI;
*/
ViewBag.nrRegCom = returnedClient[0].Regnumber;
ViewBag.adresa = returnedClient[0].Address;
ViewBag.contBancar1 = returnedClient[0].BankAcc1;
ViewBag.banca1 = returnedClient[0].BankName1;
string scadenta = returnedNote[0].ScadentaDocument.ToString();
string scadentaDoc2 = scadenta.Split(' ')[0];
ViewBag.scadentaDocument = scadentaDoc2.Split('/')[1] + "/" + scadentaDoc2.Split('/')[0] + "/" + scadentaDoc2.Split('/')[2];
ViewBag.tipDocument = tipDocument;
ViewBag.dataDocument = dataDoc;
ViewBag.nrDocument = nrDocument;
ViewBag.seria = seria;
ViewBag.clientName = clientName;
string query = "SELECT * FROM Iesiris i "
+ "INNER JOIN Clients c ON i.ClientID = c.ID "
+ "INNER JOIN Articoles a ON i.ArticolID = a.ID "
+ "INNER JOIN SeriiFacturis s ON i.SeriaID = s.ID "
+ "WHERE i.NrDocument = " + nrDocument + " AND i.DataDocument = '" + dataDocument + "' AND s.Seria = '" + seria + "'";
IEnumerable<IesiriVMDetails> data = db.Database.SqlQuery<IesiriVMDetails>(query);
//get Total and total TVA
decimal total = data.Sum(item => item.Valoare);
decimal totalTVA = data.Sum(item => item.ValoareTVA);
ViewBag.totalGeneral = total + totalTVA;
ViewBag.total = total;
ViewBag.totalTVA = totalTVA;
//verifica TVA la incasare vanzator pentru adaugarea notei
int cui = Int32.Parse(returnedClient[0].FiscalCode.ToString());
RTVAI.IService1 obj_rtvai = new RTVAI.Service1Client();
string tvaIncasare = obj_rtvai.checkVATonCollection(cui, dataDocTVA);
if (tvaIncasare == "DA")
{
ViewBag.TVAincasare = "TVA la incasare";
}
return View(data.ToList());
}
I wonder why this works perfectly when run in debug.... Once deployed, I get this error with other actions too... which are different that the ShowInvoice
It seems that the issue was generated by the server .net globalization option as the server returned the data pulled from SQL in a different format. I've set up globalization on the server the same as on the dev computer and now it works.
Not sure why my code isn't working as I've followed examples I've found. Trying to get my iOS game to save and load data back using Unity3D but not using the player.prefs.
On the scene's I have this
void OnDisable(){
GameController.Save ();
}
void OnEable(){
GameController.Load ();
}
Game Controller is a static method..
static public void Save()
{
Debug.Log("Saving Player Data...");
print ("Saving Player Data...");
var bf = new BinaryFormatter();
var file = File.Create(Application.persistentDataPath + "/CatEscapeInfo.dat");
var data = new PlayerData
{
PlayerLives = PlayerLives,
Score = Score,
Distance = Distance,
CurrentLevelNo = CurrentLevelNo,
HighestLevelCompleted = HighestLevelCompleted
};
bf.Serialize(file, data);
file.Close();
//PlayerPrefs.SetString (data);
Debug.Log ("Player Data Saved: " + PlayerLives + ", " + Score);
print ("Player Data Saved: " + PlayerLives + ", " + Score);
}
static public void Load()
{
Debug.Log("Loading Player Data...");
if (File.Exists(Application.persistentDataPath + "/CatEscapeInfo.dat"))
{
var bf = new BinaryFormatter();
var file = File.Open(Application.persistentDataPath + "/CatEscapeInfo.dat", FileMode.Open);
var data = bf.Deserialize(file) as PlayerData;
file.Close();
Debug.Log("Player Data Loaded: " + data.PlayerLives + ", " + data.Score);
print ("Player Data Loaded: " + data.PlayerLives + ", " + data.Score);
if (data != null)
{
PlayerLives = data.PlayerLives;
Score = data.Score;
Distance = data.Distance;
CurrentLevelNo = data.CurrentLevelNo;
HighestLevelCompleted = data.HighestLevelCompleted;
}
}
}
Even though I have this code running, when I manually close the game on iOS and bring it back up it never loads the game back to the stats it had.
Any thoughts? Am I missing something?
Update:
In iOS XCode, I find it's spitting out this stack trace when trying to "Load" though at the this point the file doesn't exist yet.
On Loading This is Stack Trace:
> (Filename:
> /Applications/buildAgent/work/d63dfc6385190b60/artifacts/iPhonePlayer-armv7Generated/UnityEngineDebug.cpp
> Line: 49)
>
> SerializationException: Unexpected binary element: 255 at
> System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject
> (BinaryElement element, System.IO.BinaryReader reader, System.Int64&
> objectId, System.Object& value,
> System.Runtime.Serialization.SerializationInfo& info) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject
> (BinaryElement element, System.IO.BinaryReader reader) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph
> (BinaryElement elem, System.IO.BinaryReader reader, Boolean
> readHeaders, System.Object& result,
> System.Runtime.Remoting.Messaging.Header[]& headers) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize
> (System.IO.Stream serializationStream,
> System.Runtime.Remoting.Messaging.HeaderHandler handler) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize
> (System.IO.Stream serializationStream) [0x00000] in <filename
> unknown>:0 at GameController.Load () [0x00000] in <filename
> unknown>:0 at GameController.OnEnable () [0x00000] in <filename
> unknown>:0 (Filename: Line: -1)
On Saving, This is Stack Trace:
> Saving Player Data... UnityEngine.Debug:Internal_Log(Int32, String,
> Object) UnityEngine.Debug:Log(Object)
> UnityEngine.MonoBehaviour:print(Object) GameController:Save()
> GameController:OnDisable() UnityEngine.Object:Destroy(Object, Single)
> UnityEngine.Object:Destroy(Object) GameController:Awake() (Filename:
> /Applications/buildAgent/work/d63dfc6385190b60/artifacts/iPhonePlayer-armv7Generated/UnityEngineDebug.cpp
> Line: 49)
>
> ExecutionEngineException: Attempting to JIT compile method
> 'PlayerData__TypeMetadata4:.ctor ()' while running with --aot-only.
>
> at System.Reflection.MonoCMethod.Invoke (System.Object obj,
> BindingFlags invokeAttr, System.Reflection.Binder binder,
> System.Object[] parameters, System.Globalization.CultureInfo culture)
> [0x00000] in <filename unknown>:0 Rethrow as
> TargetInvocationException: Exception has been thrown by the target of
> an invocation. at System.Reflection.MonoCMethod.Invoke
> (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder
> binder, System.Object[] parameters, System.Globalization.CultureInfo
> culture) [0x00000] in <filename unknown>:0 at
> System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr,
> System.Reflection.Binder binder, System.Object[] parameters,
> System.Globalization.CultureInfo culture) [0x00000] in <filename
> unknown>:0 at System.Reflection.ConstructorInfo.Invoke
> (System.Object[] parameters) [0x00000] in <filename unknown>:0 at
> System.Activator.CreateInstance (System.Type type, Boolean nonPublic)
> [0x00000] in <filename unknown>:0 at
> System.Activator.CreateInstance (System.Type type) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.CreateMemberTypeMetadata
> (System.Type type) [0x00000] in <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.GetObjectData
> (System.Object obj,
> System.Runtime.Serialization.Formatters.Binary.TypeMetadata& metadata,
> System.Object& data) [0x00000] in <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObject
> (System.IO.BinaryWriter writer, Int64 id, System.Object obj) [0x00000]
> in <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectInstance
> (System.IO.BinaryWriter writer, System.Object obj, Boolean
> isValueObject) [0x00000] in <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteQueuedObjects
> (System.IO.BinaryWriter writer) [0x00000] in <filename unknown>:0
> at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectGraph
> (System.IO.BinaryWriter writer, System.Object obj,
> System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize
> (System.IO.Stream serializationStream, System.Object graph,
> System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize
> (System.IO.Stream serializationStream, System.Object graph) [0x00000]
> in <filename unknown>:0 at GameController.Save () [0x00000] in
> <filename unknown>:0 at GameController.OnDisable () [0x00000] in
> <filename unknown>:0 UnityEngine.Object:Destroy(Object, Single)
> UnityEngine.Object:Destroy(Object) GameController:Awake()
Put this code to Awake or Start funtion in your scene script:
// Forces a different code path in the BinaryFormatter that doesn't rely on run-time code generation (which would break on iOS).
Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
By default Mono binary-serializer uses JIT-compilation which is unsupported by iOS. Fortunately, there is a way (the code above) to switch it to use reflection instead.
Proof / See also:
http://answers.unity3d.com/questions/725419/filestream-binaryformatter-from-c-to-ios-doesnt-wo.html
http://answers.unity3d.com/questions/30930/why-did-my-binaryserialzer-stop-working.html
Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
Create an error in the Unity editor like:
"Environment" not found in namespace
After hours of searching I found the following code that works perfectly:
System.Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER","yes");
I hope it'll help.
I am getting this error when trying to create a new View in an ASP.Net MVC 4 project in Xamarin Studio. There are no pending updates in my setup. How can I fix this?
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. ---> System.TypeLoadException: A type
load exception has occurred. at
MonoDevelop.AspNet.Mvc.Gui.FolderCommandHandler.AddView () [0x00070]
in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/addins/AspNet/MonoDevelop.AspNet.Mvc/Gui/FolderNodeBuilderExtension.cs:154
at (wrapper managed-to-native)
System.Reflection.MonoMethod:InternalInvoke
(System.Reflection.MonoMethod,object,object[],System.Exception&) at
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[]
parameters, System.Globalization.CultureInfo culture) [0x00054] in
/private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Reflection/MonoMethod.cs:230
--- End of inner exception stack trace --- at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[]
parameters, System.Globalization.CultureInfo culture) [0x00069] in
/private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Reflection/MonoMethod.cs:238
at System.Reflection.MethodBase.Invoke (System.Object obj,
System.Object[] parameters) [0x00000] in
/private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Reflection/MethodBase.cs:114
at MonoDevelop.Components.Commands.DefaultCommandHandler.Run
(System.Object target, MonoDevelop.Components.Commands.Command cmd)
[0x00019] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs:2094
at MonoDevelop.Components.Commands.CustomCommandTargetAttribute.Run
(System.Object target, MonoDevelop.Components.Commands.Command cmd)
[0x00009] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CustomCommandTargetAttribute.cs:101
at
MonoDevelop.Ide.Gui.Components.NodeCommandHandler+TransactedNodeHandlerAttribute.Run
(System.Object target, MonoDevelop.Components.Commands.Command cmd)
[0x0002d] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/NodeCommandHandler.cs:296
at
MonoDevelop.Components.Commands.CustomCommandTargetAttribute.MonoDevelop.Components.Commands.ICommandTargetHandler.Run
(System.Object target, MonoDevelop.Components.Commands.Command cmd)
[0x00004] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CustomCommandTargetAttribute.cs:58
at MonoDevelop.Components.Commands.CommandHandlerInfo.Run
(System.Object cmdTarget, MonoDevelop.Components.Commands.Command cmd)
[0x00021] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs:1963
at
MonoDevelop.Components.Commands.CommandManager+c_AnonStorey82.<>m_D2
() [0x0005f] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs:1054
at MonoDevelop.Components.Commands.CommandManager.DispatchCommand
(System.Object commandId, System.Object dataItem, System.Object
initialTarget, CommandSource source) [0x002b0] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs:1071