odata skip and top issue - odata

I've implemented Abp.OData according to documentation.
For example
http://localhost:21021/odata/regions?$count=true works without issue. It returns;
{"result":[{"id":1,"name":"Gebze"},{"id":2,"name":"Ankara"},{"id":3,"name":"Bursa"}],"targetUrl":null,"success":true,"error":null,"unAuthorizedRequest":false,"__abp":true}
But http://localhost:21021/odata/regions?$count=true&$skip=0&$top=12 doesn't work.
It returns;
{"result":null,"targetUrl":null,"success":false,"error":{"code":0,"message":"Sayfa işlenirken sunucu tarafında beklenmedik bir hata oluştu!","details":null,"validationErrors":null},"unAuthorizedRequest":false,"__abp":true}
My Startup file is:
And my oData controller is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.AspNetCore.OData.Controllers;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Microsoft.AspNet.OData;
using TSE.Merkez.KalIsteks;
namespace TSE.Merkez.Web.Host.Controllers
{
[EnableQuery]
public class RegionsController : AbpODataEntityController<Region.Region>, ITransientDependency
{
public RegionsController(IRepository<Region.Region> repository) : base(repository)
{
}
//[EnableQuery]
//public override IQueryable<Region.Region> Get()
//{
// return base.Get();
//}
}
}
I am gettin an error message given as below
ERROR 2019-02-25 12:10:21,218 [10 ]
Mvc.ExceptionHandling.AbpExceptionFilter - Did not call Complete
method of a unit of work. Abp.AbpException: Did not call Complete
method of a unit of work. at
Abp.Domain.Uow.InnerUnitOfWorkCompleteHandle.Dispose() at
Abp.AspNetCore.Mvc.Uow.AbpUowActionFilter.d__4.MoveNext() --- 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.Runtime.CompilerServices.TaskAwaiter.GetResult() at
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext
context) at
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&
next, Scope& scope, Object& state, Boolean& isCompleted) at
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__13.MoveNext()
--- 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.Runtime.CompilerServices.TaskAwaiter.GetResult()
Do you have any idea? Where do I go wrong? Thanks in advance..

Ok. Problem was solved. It was because of not constructing the entity proper way. I forced the abp to construct the entity with an extra Id property that comes form my old table. However Id column in an entity reserved for ABP framework. I should have not forced the framework to use my old Id property. I've transfered the old Id data to another column in entity and problem solved. Regards.

Related

Entity Framework 6.4 throwing NullReferenceException with Azure Functions V3

I'm using Azure Functions V3 (.Net Core 3.1) and trying to call an Entity FrameWork class built using EF 6.4 (.Net 7.2) and Entity Framework is throwing a NullReferenceException. The same call succeeds while using .Net Core console app instead of Azure Function. Appreciate your help here.
Here is my function definition:
namespace FunctionAppV32
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 * * * * *")]TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
var cstr = ConnectionString2.BuildConnectionString();
FlighterSIEntities entities = new FlighterSIEntities(cstr);
foreach (var x in entities.TGBotComplexVectorParamSettings)
{ .... }
}
}
}
The exception is thrown while accessing entities.TGBotComplexVectorParamSettings in for loop.
Exception Stack Trace:
System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=EntityFramework StackTrace:
at System.Data.Entity.Core.EntityClient.EntityConnection.GetStoreConnection(DbProviderFactory factory)
at System.Data.Entity.Core.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.Entity.Core.EntityClient.EntityConnection..ctor(String connectionString) at System.Data.Entity.Internal.LazyInternalConnection.Initialize() at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel() 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.InternalSet1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable.GetEnumerator()
at FunctionAppV32.Function1.Run(TimerInfo myTimer, ILogger log) in D:\src\RnR-ExperimentationTools\src\TGBot\FunctionAppV32\Function1.cs:line 20
at Microsoft.Azure.WebJobs.Host.Executors.VoidMethodInvoker2.InvokeAsync(TReflected instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\VoidMethodInvoker.cs:line 20 at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.d__10.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
I was able to resolve exactly same issue with updating below packages to mentioned versions. Hope it helps to you or anyone facing the same issue.
EntityFramework to Version=6.4.4
Microsoft.EntityFrameworkCore to Version=3.1.6
Microsoft.Extensions.Configuration to Version=3.1.6
Kindly check.

How to create an instance of a model that inherits RenderModel inside UmbracoApiController?

I'm using Umbraco CMS. I have the following model:
public class LoyaltyPromo : RenderModel
{
public LoyaltyPromo(IPublishedContent content)
: base(content)
{
}
//properties removed for brevity
}
I want to use this model inside UmbracoApiController. So i do this:
public class PromoServiceController : UmbracoApiController
{
public async Task<object> GetAll()
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent content = umbracoHelper.TypedContent(1050);
var list = new List<LoyaltyPromo>();
list.Add(new LoyaltyPromo(content));
return list;
}
}
Unfortunately it doesn't work, i get the NullReferenceException:
An error has occurred.
Object reference not set to an instance of an object.
System.NullReferenceException
at Umbraco.Web.Models.RenderModel..ctor(IPublishedContent
content) at LoyaltyOps.Models.LoyaltyPromo..ctor(IPublishedContent
content) in C:\Users\mkallingal\documents\visual studio
2015\Projects\LoyaltyOps\LoyaltyOps.Models\LoyaltyPromo.cs:line 13 at
LoyaltyOps.Controllers.PromoServiceController.d__0.MoveNext()
in C:\Users\mkallingal\documents\visual studio
2015\Projects\LoyaltyOps\LoyaltyOps\Controllers\PromoServiceController.cs:line
32 --- 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.Threading.Tasks.TaskHelpersExtensions.d__3`1.MoveNext()
--- 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.d__0.MoveNext()
--- 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.d__2.MoveNext()
--- 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.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()
How can i resolve this?
Your problem is that RenderModel is not intended to be used within WebAPI, which has no context regarding a front end page at all. Internally RenderModel is relying on the PublishedContentRequest property of UmbracoContext being set properly, which doesn't happen with WebAPI.
If you really do need to base your model on RenderModel, then use the alternative constructor:
RenderModel(IPublishedContent content, CultureInfo culture)
And pass in the culture as well as the content - this will get around the need for PublishedContentRequest being set, but you may run into other problems further on.
The better approach would be to create a view model that doesn't rely on RenderModel at all. Since WebAPI typically serialises your model to JSON anyway, the lighter you can make it the better.
One other thing - your listing for GetAll() doesn't return at all - I assume there's no extra processing going on in your actual method that requires your model to be based on RenderModel, and you're just returning the list?

System.InvalidCastException in ASP.NET MVC6 tutorial sample

I am exactly following the contents of the site http://aspnetmvc.readthedocs.org/projects/mvc/en/latest/getting-started/first-web-api.html
After copy and paste the ode, when I run the program by F5, I get below error.
Any idea what I need to do to resolve this error
System.InvalidCastException Unable to cast object of type
'TodoApi.Models.TodoRepository' to type
'TodoApi.Models.ITodoRepository'. at
Microsoft.Framework.Internal.PropertyHelper.CallPropertySetter(Action setter, Object target, Object
value)
at Microsoft.Framework.Internal.PropertyHelper.SetValue(Object
instance, Object value)
at
Microsoft.AspNet.Mvc.DefaultControllerActionArgumentBinder.ActivateProperties(Object
controller, Type containerType, Dictionary properties)
at
Microsoft.AspNet.Mvc.DefaultControllerActionArgumentBinder.d__4.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)

Proxem Stanford Parser asp MVC

I'm using Proxem wrapper for Stanford Parser and I'm facing problem with Parsing in ASP.NET MVC 3 and 4 application. It throws
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Proxem.Antelope.Parsing.Sentence.a(List`1 A_0)
at Proxem.Antelope.Parsing.Sentence..ctor(SerializationInfo info, StreamingContext ctxt)
--- End of inner exception stack trace ---
In WPF and console application it works fine.
I fixed it. Constructor Parser(string path) is invoking constructor Parser(string path, int poolsize) with poolsize value = 1. Using constructor Parser(string path, int poolsize) with values -> Parser(yourPath, 0) make it work with MVC and WCF.

Basic web application using Saxon API and IKVM throws exception

I created a basic .NET 4.0 application and referenced the Saxon assemblies. Here is the list of dll's I referenced in the project.
saxon9.dll
saxon9api.dll
IKVM.OpenJDK.ClassLibrary.dll
IKVM.Runtime.dll
The code for the application is as follows:
Sub Main()
Console.WriteLine("Trying to instantiate SaxonProcessor...")
Try
Dim SaxonProcessor As Saxon.Api.Processor = New Saxon.Api.Processor()
Catch ex As Exception
Console.WriteLine("Error: " & ex.Message & ex.StackTrace)
Console.Read()
End Try
Console.WriteLine("Saxon instantiated successfully!")
Console.Read()
End Sub
When I run this application on our IIS machine, I get the following output:
Trying to instantiate SaxonProcessor...
Saxon instantiated successfully!
I then created a basic web application project and referenced the same files as the windows application. I deployed the web application to a virtual directory that contains all the referenced assemblies. I put the following code inside my Default.aspx page:
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write("Trying to instantiate SaxonProcessor...")
Try
Dim SaxonProcessor As Saxon.Api.Processor = New Saxon.Api.Processor()
Response.Write("Saxon instantiated successfully!")
Catch ex As Exception
Response.Write("Error: " & ex.Message & ex.StackTrace)
End Try
End Sub
End Class
When I load the page, it gives me this exception:
Trying to instantiate SaxonProcessor...Error: The type initializer for 'IKVM.NativeCode.java.lang.Thread' threw an exception. at IKVM.NativeCode.java.lang.Class.forName0(String name, Boolean initialize, Object loader) at java.lang.Class.forName0(String , Boolean , ClassLoader ) at java.lang.Class.forName(String className) at net.sf.saxon.dotnet.DotNetExtensionFunctionFactory.class$(String x0) at net.sf.saxon.dotnet.DotNetExtensionFunctionFactory..ctor(Configuration config) at net.sf.saxon.dotnet.DotNetPlatform.initialize(Configuration config) at net.sf.saxon.Configuration.init() at net.sf.saxon.Configuration..ctor() at Saxon.Api.Processor..ctor() at BealSaxxon._Default.Page_Load(Object sender, EventArgs e) in C:\Users\u0147101\Desktop\BealSaxxon\BealSaxxon\Default.aspx.vb:line 9
FULL STACKTRACE FROM IIS MACHINE:
System.TypeInitializationException: The type initializer for 'IKVM.NativeCode.java.lang.Thread' threw an exception. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'java.io.BufferedInputStream' threw an exception. ---> java.lang.RuntimeException: java.lang.IllegalAccessException: Class java.util.concurrent.atomic.AtomicReferenceFieldUpdater can not access a member of class java.io.BufferedInputStream with modifiers "volatile" ---> java.lang.IllegalAccessException: Class java.util.concurrent.atomic.AtomicReferenceFieldUpdater can not access a member of class java.io.BufferedInputStream with modifiers "volatile"
at sun.reflect.misc.ReflectUtil.ensureMemberAccess(Class currentClass, Class memberClass, Object target, Int32 modifiers)
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.AtomicReferenceFieldUpdaterImpl..ctor(Class , Class , String )
--- End of inner exception stack trace ---
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.AtomicReferenceFieldUpdaterImpl..ctor(Class , Class , String )
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(Class tclass, Class vclass, String fieldName)
at java.io.BufferedInputStream..cctor()
--- End of inner exception stack trace ---
at java.io.BufferedInputStream.__<clinit>()
at java.lang.System.initializeSystemClass()
--- End of inner exception stack trace ---
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 IKVM.NativeCode.java.lang.Thread..cctor()
--- End of inner exception stack trace ---
at IKVM.NativeCode.java.lang.Class.forName0(String name, Boolean initialize, Object loader)
at java.lang.Class.forName(String className)
at net.sf.saxon.dotnet.DotNetExtensionFunctionFactory.class$(String x0)
at net.sf.saxon.dotnet.DotNetExtensionFunctionFactory..ctor(Configuration config)
at net.sf.saxon.dotnet.DotNetPlatform.initialize(Configuration config)
at net.sf.saxon.Configuration.init()
at net.sf.saxon.Configuration..ctor()
at Saxon.Api.Processor..ctor()
at EDG.Transforms..ctor()
at EDG.Main..ctor(NameValueCollection applicationSettings, List`1 exceptionList)
at EDG.EGallery..ctor(NameValueCollection ConfigurationSettings, List`1 ExceptionList)
Has anyone seen this exception before? I've searched extensively on Google but nobody seems to have had this specific exception. I'm thinking it's a permissions problem with IIS, but I don't know for sure. The application pool this application is running under is setup with a machine administrator.
I think this can be 2 types of causes.
One of the IKVM dll is missing. Add all dll of IKVM to test if this solve the problem.
IKVM is compiled for .NET 2 and not version 4. You need to add a version mapping to your app.config.
In this situation, it was a product called OpNET that was interfering with apps using the JVM. Once its services and processes were stopped, the Saxon assembly worked fine.

Resources