WebApi - error 500 Internal Server Error

I have a issue to access the WEBAPI. Webscreen is working.

Error in Postman:

500Internal Server Error
"error": {

"code": "InternalServerError",
"message": {
"lang": "en-US",
"value": "Internal Server Error"
}
}

Trace Log error:

Timestamp: 3/24/2025 2:33:54 PM
Message: Error-[Tenant:] [Company:] [Module:] [User:] - Sage 300 Web API encountered an error for Url '90.90.90.248/.../ARCustomers'.:
(Inner Exception)
(Inner Exception)
Exception Source: EntityFramework
Exception Type: System.BadImageFormatException
Exception Message: Bad IL range.
---- Stack Trace ----
System.Data.Entity.Core.Metadata.Edm.GlobalItem..ctor() in EntityFramework.dll
System.Data.Entity.Core.Metadata.Edm.StructuralType..ctor() in EntityFramework.dll
System.Data.Entity.Core.Metadata.Edm.ComplexType..ctor() in EntityFramework.dll
System.Data.Entity.Core.Metadata.Edm.MetadataItem..cctor() in EntityFramework.dll

(Outer Exception)
Exception Source: EntityFramework
Exception Type: System.TypeInitializationException
Exception Message: The type initializer for 'System.Data.Entity.Core.Metadata.Edm.MetadataItem' threw an exception.
---- Stack Trace ----
System.Data.Entity.Core.Metadata.Edm.PrimitiveType.GetEdmPrimitiveTypes() in EntityFramework.dll
System.Data.Entity.Utilities.TypeExtensions..cctor() in EntityFramework.dll

(Outer Exception)
Exception Source: EntityFramework
Exception Type: System.TypeInitializationException
Exception Message: The type initializer for 'System.Data.Entity.Utilities.TypeExtensions' threw an exception.
---- Stack Trace ----
System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType) in EntityFramework.dll
System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model) in EntityFramework.dll
System.Data.Entity.DbContext..ctor(String nameOrConnectionString) in EntityFramework.dll
Sage.CA.SBS.ERP.Sage300.Common.BusinessRepository.Landlord.LandlordDbContext..ctor() in Sage.CA.SBS.ERP.Sage300.Common.BusinessRepository.dll,file: LandlordDbContext.cs,line: 0026
Sage.CA.SBS.ERP.Sage300.Common.BusinessRepository.Landlord.LandlordRepositoryBase.Get(Guid productUserId, Guid tenantId) in Sage.CA.SBS.ERP.Sage300.Common.BusinessRepository.dll,file: LandlordRepositoryBase.cs,line: 0024
Sage.CA.SBS.ERP.Sage300.Common.Services.Landlord.LandlordService.Get(Guid productUserId, Guid sageTenantId) in Sage.CA.SBS.ERP.Sage300.Common.Services.dll,file: LandlordService.cs,line: 0039
Sage.CA.SBS.ERP.Sage300.Common.Web.Security.UserTenantResolverOnPremise.ResolveUserTenant(IUnityContainer container, Context context, String company, String userId, SecureString passwordSStr, List`1 companies) in Sage.CA.SBS.ERP.Sage300.Common.Web.dll,file: UserTenantResolverOnPremise.cs,line: 0060
Sage.CA.SBS.ERP.Sage300.Common.WebApi.Controllers.ResourceController.SetContext() in Sage.CA.SBS.ERP.Sage300.Common.WebApi.dll,file: ResourceController.cs,line: 0055
Sage.CA.SBS.ERP.Sage300.Common.WebApi.Controllers.ViewResourceController`1.InitializeRepository(Boolean forWriteAccess) in Sage.CA.SBS.ERP.Sage300.Common.WebApi.dll,file: ViewResourceController.cs,line: 0247
Sage.CA.SBS.ERP.Sage300.Common.WebApi.Controllers.ViewResourceController`1.Post(TModel model) in Sage.CA.SBS.ERP.Sage300.Common.WebApi.dll,file: ViewResourceController.cs,line: 0187
(Closure , Object , Object[] ) in <In Memory Module>
System.Web.Http.Controllers.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) in System.Web.Http.dll
System.Web.Http.Controllers.ActionExecutor.Execute(Object instance, Object[] arguments) in System.Web.Http.dll
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) in System.Web.Http.dll
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in mscorlib.dll
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in mscorlib.dll
System.Web.Http.Controllers.<InvokeActionAsyncCore>d__0.MoveNext() in System.Web.Http.dll
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in mscorlib.dll
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in mscorlib.dll
System.Web.Http.Filters.<CallOnActionExecutedAsync>d__5.MoveNext() in System.Web.Http.dll
System.Web.Http.Filters.<CallOnActionExecutedAsync>d__5.MoveNext() in System.Web.Http.dll
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in mscorlib.dll
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in mscorlib.dll
System.Web.Http.Filters.<ExecuteActionFilterAsyncCore>d__0.MoveNext() in System.Web.Http.dll
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in mscorlib.dll
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in mscorlib.dll
System.Web.Http.Controllers.<ExecuteAsync>d__2.MoveNext() in System.Web.Http.dll
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in mscorlib.dll
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in mscorlib.dll
System.Web.Http.Filters.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext() in System.Web.Http.dll
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in mscorlib.dll
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in mscorlib.dll
System.Web.Http.Controllers.<ExecuteAsync>d__0.MoveNext() in System.Web.Http.dll

Any suggestions?

Regards,

  • Hi  before requesting data via Postman, can you confirm you can return the requested data via SwaggerUI e.g. 90.90.90.248/Sage300WebAPI E.g for example:

    If you can't access SwaggerUI, can you please share the error you receive attempting to access it?

    Good luck!

  • 0

    Try running PORTAL setup again in dbsetup.

    Do you have local program files installed on the web server? Maybe they are the wrong patch to the rest of your Sage300 system?

    Last ditch effore, restart the machine?

  • 0

    Have you enabled the "Sage 300 Web API" security group for the AR resource that you are attempting to access? The Web API will reject a request if the "Sage 300 Web API" security group is not enabled.

  • Hi Tim, thanks for the suggestion.

    This is the error i get from the Swagger.

    Response Code

    500

    Response Headers

    {
    "cache-control": "no-cache",
    "content-length": "148",
    "content-type": "text/plain; charset=utf-8",
    "date": "Wed, 26 Mar 2025 13:17:01 GMT",
    "expires": "-1",
    "pragma": "no-cache",
    "server": "Microsoft-IIS/10.0",
    "x-aspnet-version": "4.0.30319",
    "x-powered-by": "ASP.NET"
    }
  • 0 in reply to John Thomas

    Yes, actually I select for the user all the options in all modules just to avoid any possible issues.

  • 0 in reply to SergeB

    All are installed in the same server, exept SQL.  PORTAL database is created and Webscreens work fine.

  • Hi  OK thank you for the reply and confirming you can't access the SwaggerUI.  I would highly recommend contacting your local Sage 300 consultant or Business Partner for prompt assistance to resolve it as there are many possible causes of the problem.  Meanwhile, I'll still try to assist as we need to ensure you can reach the Swagger UI screen before you can start engaging with the API. 

    The next thing to check is that the IIS users have access to the Sage300WebApi application files.  Please work through the following steps and let us know how you go.  Good luck!

    Check/add IIS User permissions to Sage 300 Online subfolder:
    Open IIS Manager -> Right-click on Sage300WebApi -> Left-click Explore e.g:

    Left-click your Sage 300 / Sage 300 Applications folder e.g.:

    Right-click your Online folder -> Left-click Properties e.g.:

    Click the Security tab -> Click the Edit button -> click the Add button -> type in IUSR -> click Check Names -> Click OK e.g.:

    Select the IUSR object and assign the permissions e.g.:


    Repeat the process but this time add <yourservername>\IIS_IUSR e.g.:

    Select <SERVERNAME>\IIS_IUSRS and assign permissions again e.g.:

    Click OK -> Click OK again.

    Now see if you can access the Swagger site e.g.:

    Again, good luck and let us know how you go!

  • 0 in reply to Jesus Feliciano - TS

    What version of Sage300? Maybe apply the latest patch or reapply the patch.

    The only times I've seen EF throw a BadImageFormat ex is when im running wrong bitness of builds. Seeing as the webscreens work for you, it would rule out the Sage300 app pool not being set to 32bit compat.

    Do you have anything in your AV logs to suggest something is blocking? Any exotic settings in IIS? Do you have all the IIS requirements and features loaded?
    "under World Wide Web Services’ Application Development Features, select the ASP, CGI, ISAPI Extensions, and ISAPI Filters options"