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)
Related
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.
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?
I worked through the Setup documentation found here. I have a sample dashboard application and a sample client application which throws Elmah errors into a SQL database.
The client application has elmah working correctly and I can view the error logs at elmah.axd. When I attempt to access the Dashboard application the page loads and kicks off the "Sending Commands" message. I then get a 500 Internal Server error from the first "send?transport=..." command.
The Dashboard app is an ASP.Net MVC 5 app running on my localhost.
This is the URL that generates the error:
http://localhost/ElmahR/elmahr/commands/send?transport=serverSentEvents&connectionToken=k6HUNtFtmSXrJZgH_2oexTg_cx-el2G7PhJ6NZD4aBLT_svpboE31meZG4wazu7VDS8_WWRjnnV-yGSVhBzBbYWlXFTo08onRvNCzYgYhH5kwMw9KvKOSQIakT6Wzv_Y0
When I inspect that error, this is what I get:
RazorEngine.Templating.TemplateCompilationException
Unable to compile template. Source file 'C:\Windows\TEMP\lahvjqh3.0.cs' could not be found Other compilation errors may have occurred. Check the Errors property for more information.
System.AggregateException: One or more errors occurred. ---> RazorEngine.Templating.TemplateCompilationException: Unable to compile template. Source file 'C:\Windows\TEMP\lahvjqh3.0.cs' could not be found
Other compilation errors may have occurred. Check the Errors property for more information.
at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Compilation\DirectCompilerServiceBase.cs:line 100
at RazorEngine.Templating.TemplateService.CreateTemplateType(String razorTemplate, Type modelType) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 256
at RazorEngine.Templating.TemplateService.CreateTemplate(String razorTemplate, Type templateType, Object model) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 127
at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 435
at ElmahR.Core.Plugins.<BuildPlugins>b__a(<>f__AnonymousType2`2 <>h__TransparentIdentifier6)
at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at ElmahR.Core.StartupConnection.<.ctor>b__1(IConnection c, IRequest r, String cid, String d)
at ElmahR.Core.StartupConnection.OnReceived(IRequest request, String connectionId, String data)
at Microsoft.AspNet.SignalR.PersistentConnection.<>c__DisplayClassa.<>c__DisplayClassc.<ProcessRequest>b__7()
at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod(Func`1 func)
--- End of inner exception stack trace ---
at Microsoft.Owin.Host.SystemWeb.CallContextAsyncResult.End(IAsyncResult result)
at System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)
---> (Inner Exception #0) RazorEngine.Templating.TemplateCompilationException: Unable to compile template. Source file 'C:\Windows\TEMP\lahvjqh3.0.cs' could not be found
Other compilation errors may have occurred. Check the Errors property for more information.
at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Compilation\DirectCompilerServiceBase.cs:line 100
at RazorEngine.Templating.TemplateService.CreateTemplateType(String razorTemplate, Type modelType) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 256
at RazorEngine.Templating.TemplateService.CreateTemplate(String razorTemplate, Type templateType, Object model) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 127
at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName) in c:\_git\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 435
at ElmahR.Core.Plugins.<BuildPlugins>b__a(<>f__AnonymousType2`2 <>h__TransparentIdentifier6)
at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at ElmahR.Core.StartupConnection.<.ctor>b__1(IConnection c, IRequest r, String cid, String d)
at ElmahR.Core.StartupConnection.OnReceived(IRequest request, String connectionId, String data)
at Microsoft.AspNet.SignalR.PersistentConnection.<>c__DisplayClassa.<>c__DisplayClassc.<ProcessRequest>b__7()
at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod(Func`1 func)<---
Any idea what might be configured incorrectly for it to throw this error? Is is something I need to change with Razor?
This is what I see:
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.
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.