Page 1 of 1

GetService<IOrderStore>() throws TargetInvocationException

Posted: Tue Nov 21, 2017 1:28 pm
by at2k21
Hello,

I am trying to get my SoftPro Select programming sea legs about me and going through the example Open an Order in the documentation. When I get to the line IOrderStore os = ss.GetService<IOrderStore>(); in code it throws the following stack.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'SoftPro.Select.Client.Formula.FormulaCompilationConfiguration' threw an exception. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at SoftPro.Select.Client.Formula.FormulaCompilationConfiguration.AddPreconfiguredProviders()
at SoftPro.Select.Client.Formula.FormulaCompilationConfiguration..ctor()
at SoftPro.Select.Client.Formula.FormulaCompilationConfiguration..cctor()
--- End of inner exception stack trace ---
at SoftPro.Select.Client.Formula.FormulaCompilationConfiguration.get_Instance()
at SoftPro.OrderTracking.Client.Orders.OrderStoreProvider..ctor(IServiceProvider site, Uri uri, Boolean profilerEnabled)
at SoftPro.OrderTracking.Client.Orders.OrderStore..ctor(IServiceProvider site)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at SoftPro.ClientModel.Server.CreateService(IServiceContainer container, Type serviceType)
at System.ComponentModel.Design.ServiceContainer.GetService(Type serviceType)
at SoftPro.ClientModel.Server.GetService(Type serviceType, Boolean ensureAuthenticated)
at SoftPro.ClientModel.Server.GetService(Type serviceType)
at SoftPro.Select.Client.SelectServer.GetService(Type serviceType)
at SoftPro.Select.Client.SelectServer.GetService[T]()
at SoftProSelect.Program.Main(String[] args)

I have checked the event logs on the server and there is no matching error on the server side. The select version number is 4.3.50811.25 and the SDK dll's are versioned the same. Not really sure how to get around this. Maybe something has changes and the documentation has not been updated? Any help with this is greatly appreciated.

Re: GetService<IOrderStore>() throws TargetInvocationException

Posted: Tue Nov 21, 2017 3:40 pm
by John Morris
This is usually a sign of a missing dll. To find out which one, you can use the .net tool called fuslogvw to enable .net clr binding logging. The log will help you find the missing item.

Re: GetService<IOrderStore>() throws TargetInvocationException

Posted: Fri Jun 08, 2018 10:29 am
by czentman
was this error resolved with fuslogvw? We are getting the same error in the same select version. We just upgraded and this was an oversight on our website and desparate for help. We tried restoring nuget packages. Everything worked fine in 4.1 version we were previously on. Why would the softpro dll need new dependancy dll's now with 4.3? Are you sure it's not something else changed in 4.3? Or do you know which dll it's missing?

Re: GetService<IOrderStore>() throws TargetInvocationException

Posted: Fri Jun 08, 2018 12:15 pm
by BobRichards
I can only assume they found the problem as there are no further posts. Did you copy *all* the DLLs and EXEs from a working midtier instance of the same version? If so, please describe your scenario.

Re: GetService<IOrderStore>() throws TargetInvocationException

Posted: Mon Jun 11, 2018 2:31 pm
by czentman
I got it working on my local version when I copied the dll's (not all dll's in select folder but the ones I already had in my project) into my project directory, adding as references, and building and running it. The problem is when I push to our dev and live hosting web servers, I get the following error

{
"message": "An error has occurred.",
"exceptionMessage": "Could not load file or assembly 'SoftPro.EntityModel' or one of its dependencies. The system cannot find the file specified.",
"exceptionType": "System.IO.FileNotFoundException",
"stackTrace": " at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)\r\n at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)\r\n at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)\r\n at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)\r\n at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)\r\n at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)\r\n at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)\r\n at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)\r\n at SoftPro.EntityModel.EntityRuntime.RunCompiler(ModelName modelName, String packageFile, String assemblyName, String outputPath, IEnumerable`1 redirects)\r\n at SoftPro.EntityModel.EntityRuntime.EnsureModelLoaded(ModelName modelName)\r\n at SoftPro.EntityModel.EntityRuntime.Deserialize(Stream stream, EntityEditMode editMode)\r\n at SoftPro.EntityModel.EntityRuntime.Load(Stream stream, SerializationFormat format, EntityEditMode editMode)\r\n at SoftPro.OrderTracking.Client.Orders.OrderStoreProvider.Load(Stream memory, OrderEditMode mode)\r\n at SoftPro.OrderTracking.Client.Orders.OrderStore.OpenOrder(OrderIdentifier id, OrderEditMode mode)\r\n at SoftPro.OrderTracking.Client.Orders.OrderStore.SoftPro.OrderTracking.Client.Orders.IOrderStore.OpenOrder(IOrderInfo orderInfo, OrderEditMode mode)\r\n at SoftPro.OrderTracking.Client.Orders.OrderStore.SoftPro.OrderTracking.Client.Orders.IOrderStore.OpenOrder(IOrderInfo orderInfo, Boolean readOnly)\r\n at Title.API.Functions.SelectFunctions.GetInfo(String OrderNumber, String Info)\r\n at Title.API.Controllers.RequirementsController.GetRequirements(String orderNum)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}


I noticed that Microsoft.ApplicationInsights.dll is a newer version in my project than the one in the select folder. We think that may be an issue. I tried removing with my nuget package and bringing in this dll and it gives me a different error as follows:


Could not load file or assembly 'Microsoft.ApplicationInsights' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.ApplicationInsights' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.ApplicationInsights' could not be loaded.


=== Pre-bind state information ===
LOG: DisplayName = Microsoft.ApplicationInsights
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.ApplicationInsights | Domain ID: 10
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/czentman/Documents/Development/Title/Title.API/
LOG: Initial PrivatePath = C:\Users\czentman\Documents\Development\Title\Title.API\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\czentman\Documents\Development\Title\Title.API\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/title.api/b96b1dd5/fd1b6662/Microsoft.ApplicationInsights.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/title.api/b96b1dd5/fd1b6662/Microsoft.ApplicationInsights/Microsoft.ApplicationInsights.DLL.
LOG: Attempting download of new URL file:///C:/Users/czentman/Documents/Development/Title/Title.API/bin/Microsoft.ApplicationInsights.DLL.
LOG: Using application configuration file: C:\Users\czentman\Documents\Development\Title\Title.API\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 2.1.0.0 redirected to 2.6.4.0.
LOG: Post-policy reference: Microsoft.ApplicationInsights, Version=2.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/title.api/b96b1dd5/fd1b6662/Microsoft.ApplicationInsights.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/title.api/b96b1dd5/fd1b6662/Microsoft.ApplicationInsights/Microsoft.ApplicationInsights.DLL.
LOG: Attempting download of new URL file:///C:/Users/czentman/Documents/Development/Title/Title.API/bin/Microsoft.ApplicationInsights.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Stack Trace:


[FileLoadException: Could not load file or assembly 'Microsoft.ApplicationInsights' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]

[FileLoadException: Could not load file or assembly 'Microsoft.ApplicationInsights, Version=2.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +225
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +110
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22
System.Reflection.Assembly.Load(String assemblyString) +34
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48

[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.ApplicationInsights, Version=2.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +729
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +247
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +157
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +226
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +73
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +321
System.Web.Compilation.BuildManager.ExecutePreAppStart() +170
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +734

[HttpException (0x80004005): Could not load file or assembly 'Microsoft.ApplicationInsights, Version=2.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +525
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +118
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +708

Re: GetService<IOrderStore>() throws TargetInvocationException

Posted: Mon Jun 11, 2018 3:35 pm
by BobRichards
I cannot answer questions about the web site portion of the question. However, Select is built using the fully qualified names of external DLLs. This means that you must use the same versions in the application folder. In our case, you need to put the Select distributed version of ApplicationInsights in the Select application folder. Since this should be loaded before exploring the GAC, it should work fine even though others versions may exist on the system.

Look at Could not load file or assembly 'XYZ' or one of its dependencies to determine the name of the missing file.

Re: GetService<IOrderStore>() throws TargetInvocationException

Posted: Tue Jun 12, 2018 11:31 am
by czentman
We finally figured it out. The dll's were in the bin folder, but only once all the Dll's were also in the main project as well, then it worked. Are you able to explain why this is the case?

Re: GetService<IOrderStore>() throws TargetInvocationException

Posted: Tue Jun 12, 2018 11:46 am
by BobRichards
Probably the Select DLLs are being called in the Main project folder by the web portal code. The default .NET search algorithm didn't find acceptable DLLs. (Complete order at Search Path Used by Windows to Locate a DLL)

Bottom line, Select runtime either found only the wrong version DLL or couldn't find it at all in the search path.