The process was terminated due to an unhandled exception - c#

So let me start from the top. I have made a console app that will run daily with the use of a scheduled task. The console app works and has been tested. My issue is when I take the .exe and .exe.config from the bin I am moving these to a separate server changing the config to contain relevant connection strings but when the .exe runs I am getting the below error:
Application: xxx.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Data.SqlClient.SqlException
Stack:
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(System.Data.CommandBehavior, System.Data.SqlClient.RunBehavior, Boolean, Boolean)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(System.Data.CommandBehavior, System.Data.SqlClient.RunBehavior, Boolean, System.String, System.Data.Common.DbAsyncResult)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(System.Data.CommandBehavior, System.Data.SqlClient.RunBehavior, Boolean, System.String)
at System.Data.SqlClient.SqlCommand.ExecuteReader(System.Data.CommandBehavior, System.String)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(System.Data.CommandBehavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(System.Data.CommandBehavior)
at System.Data.Common.DbDataAdapter.FillInternal(System.Data.DataSet, System.Data.DataTable[], Int32, Int32, System.String, System.Data.IDbCommand, System.Data.CommandBehavior)
at System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable[], Int32, Int32, System.Data.IDbCommand, System.Data.CommandBehavior)
at System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)
at Dmc.V1.BatchTasks.DestinationMarketingEntityTableAdapters.HotelCodesTableAdapter.GetData()
at Dmc.V1.BatchTasks.Program.Main(System.String[])
Can anyone shed some light on this for me?

I just ran in to this issue and for me it turned out the user my app was logging to the database with didn't have execute permission on the stored procedure I was trying to running.
My app was targeting .Net Framework 4.7.2 and my app runs as a scheduled task. I got the same error message
Application: xxx.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Data.SqlClient.SqlException
If there have been recent changes to the database or to the connection string being used by the app check for a possible database permission issue.

it seems to me as a .NET Framework compatibility issue.
Problem : you have developed your application in your local machine with .NET Framework 4.5 and running the same on remote pc having .NET Framework 4.0.
Note : if you target your application to run on Higher Version of .NET Framework it wont run on below versions.
Solution : you need to target it to .NET Framework 4.0 to run on remote pc.
Step 1: right click on project - select properties
Step 2: change the Target Framework from .NET Framework 4.5 to .NET Framework 4.
Step 3: now rebuild your application and deploy.

Related

PlatformNotSupportedException in DbContext through COM

I wrote a simple .net framework library that exposed itself to COM in the appropriate way and I could then create and use the library from VB6. This library did some calculation and read databases rows through Entity Framework.
I have written a .net 7 (Core) version of this library, which still uses EF (not EF Core) and when the library is used through a .net console app, does the same job as the original (i.e. the code is fundamentally working).
I have exposed this to COM by:
a. Adding the following to the .csproj
<EnableComHosting>true</EnableComHosting>
<PlatformTarget>x86</PlatformTarget>
b. Registering the resulting comhost dll
regsvr32 my-library.comhost.dll
c. Creating an instance of the object in VB6
Set obj = CreateObject("new:{C3BBD3C1-FED4-43B0-A9CE-38C356D2BA8E}")
The object is successfully created and when I call one of the exposed functions in the object the code starts executing within the .net library (I can attach and step through using Visual Studio) but when it gets to the point where the DbContext is being created, I get the following:
System.TypeInitializationException: 'The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.'
ConfigurationErrorsException: Configuration system failed to initialize
PlatformNotSupportedException: Operation is not supported on this platform.
I understand it is trying to say that in the current environment it is executing, it doesn't know what the target platform is supposed to be? I'm not sure what I should/could do about this to allow this issue to be resolved.
Edit 1:
Full exception details:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
at System.Data.Entity.Internal.LazyInternalConnection..ctor(DbContext context, String nameOrConnectionString)
at System.Data.Entity.DbContext..ctor()
at LibTest.Domain.Infrastructure.ConfigurationDbContext..ctor() in X:\SOURCE\WEBSERVE\1\LibTestCore\LibTestCore.Domain\Infrastructure\ConfigurationDbContext.cs:line 27
at LibTest.Domain.Configuration.Concrete.DbConfigurationRepository..ctor() in X:\SOURCE\WEBSERVE\1\LibTestCore\LibTestCore.Domain\Concrete\Configuration\DbConfigurationRepository.cs:line 12
at LibTest.Domain.Concrete.Configuration.LegacyConfigurationRepository..ctor()
at LibTest.Domain.Concrete.Legacy.ComInterface..ctor() in X:\SOURCE\WEBSERVE\1\LibTestCore\LibTestCore.Domain\Concrete\Legacy\ComInterface.cs:line 16
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
This exception was originally thrown at this call stack:
System.Configuration.ClientConfigPaths.ClientConfigPaths(string, bool)
System.Configuration.ClientConfigPaths.GetPaths(string, bool)
System.Configuration.ClientConfigurationHost.ConfigPaths.get()
System.Configuration.ClientConfigurationHost.GetStreamName(string)
System.Configuration.ClientConfigurationHost.IsAppConfigHttp.get()
System.Configuration.Internal.DelegatingConfigHost.IsAppConfigHttp.get()
System.Configuration.ClientConfigurationSystem.ClientConfigurationSystem()
System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
Inner Exception 1:
ConfigurationErrorsException: Configuration system failed to initialize
Inner Exception 2:
PlatformNotSupportedException: Operation is not supported on this platform.

Publishing WPF Application with EmguCV and Clickonce

I've been trying to publish a WPF application I've been working on to a specific folder using Microsoft Clickonce. In my application I use the OpenCV wrapper EmguCV. However, when I publish the application and download and install it on a new machine, it gets thrown the following error.
Application: Photo.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.DllNotFoundException
at Emgu.CV.CvInvoke.RedirectError(CvErrorCallback, IntPtr, IntPtr)
at Emgu.CV.CvInvoke..cctor()
Exception Info: System.TypeInitializationException
at Emgu.CV.CvInvoke.cvCreateImageHeader(System.Drawing.Size, Emgu.CV.CvEnum.IplDepth, Int32)
at Emgu.CV.Image`2[[Emgu.CV.Structure.Gray, Emgu.CV, Version=4.6.0.5131, Culture=neutral, PublicKeyToken=7281126722ab4438],[System.Byte, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].AllocateData(Int32, Int32, Int32)
Whats really confusing me though is if I download my bin folder to that same machine and run the application, it works completely fine. Because of this I know the machine is not missing any runtimes, so it would have to be with Clickonce itself. I've verified that I'm targeting x64, and have also checked that all of the EmguCV dll's are being included in the Application Files section of Clickonce. I've also checked EmguCV's documentation about the issue and I've also verified that I have the correct Nuget package with the Emgu.CV.runtime.windows package.

Published WIndows Console App fails with System.ComponentModel.Win32Exception at Microsoft.Data.SqlClient.SNINativeMethodWrapper..cctor()

I have a Windows Console application that accesses our SQL database. This app works fine from VS2019, the debug folder and the release folder. However, if I publish this app, the installed version fails with the exception shown below.
I do note the following differences between the installed location (\AppData\Local\2.0\xxx\yyy) and the \Release folder:
The \Release folder has SNI files in the \x86 and \64 directories, but the installed directory is missing this information. How do I include this in the manifest? I suspect that this is the main issue causing the exception.
The manifest file in the installed location is missing information related to Identity - not sure if this is a concern, but perhaps it is?
Application: SmartRView Configuration.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ComponentModel.Win32Exception
at Microsoft.Data.SqlClient.SNINativeMethodWrapper..cctor()
Exception Info: System.TypeInitializationException
at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize()
at Microsoft.Data.SqlClient.SNILoadHandle..ctor()
at Microsoft.Data.SqlClient.SNILoadHandle..cctor()
Exception Info: System.TypeInitializationException
at Microsoft.Data.SqlClient.TdsParser..cctor()

Call .NET Standard DLL in SQL Server

I have a requirement set upon me to run a .NET Standard project from T-SQL. I'm finding very little info about this. I've set the TRUSTWORTHY setting to ON.
Importing the test program dll I'm receiving the error below.
I try importing the netstandard.dll from the C:\Program Files\dotnet\sdk\2.2.103\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\ folder. This fails with the error below. But even after importing System.Data.Common from the same folder I keep receiving the error below.
When importing netstandard.dll from the C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.3\build\netstandard2.0\ref folder I receive no errors. However when calling the function I receive the error below.
Msg 10313, Level 16, State 51, Line 17
An error occurred while using the .NET Framework during IL compilation. The server may be running out of resources. Try running the query again. If the problem persist, contact a support professional.
System.IO.FileLoadException: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Assembly in host store has a different signature than assembly in GAC. (Exception from HRESULT: 0x80131050) See Microsoft Knowledge Base article 949080 for more information.
System.IO.FileLoadException:
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
.NET Framework assemblies work without issue. Is running .NET Standard assemblies supported on SQL Server? If it's not supported what would be the workaround? Is there any solution more simple than calling a web service through .NET Framework and letting the web service call the .NET Standard code?
SQL Server supports .NET Framework 4 assemblies, using certain libraries listed at https://learn.microsoft.com/en-us/sql/relational-databases/clr-integration/database-objects/supported-net-framework-libraries?view=sql-server-2017.
The latest "what's new" page regarding CLR in SQL Server mentions only features added in SQL Server 2012: https://learn.microsoft.com/en-us/sql/relational-databases/clr-integration/clr-integration-what-s-new?view=sql-server-2017
.NET Core and .NET Standard are newer things (introduced in 2014 and 2016, respectively).

How to use SignalR as client in windows service? (File not found exception: at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.Initialize)

I'm going to use SignalR in a windows service as client.
Service is running under administrator privileges.
And "Microsoft.AspNet.SignalR.Client" package added by nuget.
running code as windows application has no errors and runs correctly. but when I install it as service, service stops and in windows Events I can see this error.
this answer did not resolved my problem.
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Exception Info: System.IO.FileNotFoundException
at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.Initialize(Microsoft.AspNet.SignalR.Client.IConnection)
at Microsoft.AspNet.SignalR.Client.Transports.TransportHelper.GetNegotiationResponse(Microsoft.AspNet.SignalR.Client.Http.IHttpClient, Microsoft.AspNet.SignalR.Client.IConnection, System.String)
at Microsoft.AspNet.SignalR.Client.Transports.AutoTransport.GetNegotiateResponse(Microsoft.AspNet.SignalR.Client.IConnection, System.String)
at Microsoft.AspNet.SignalR.Client.Transports.AutoTransport.Negotiate(Microsoft.AspNet.SignalR.Client.IConnection, System.String)
at Microsoft.AspNet.SignalR.Client.Connection.Negotiate(Microsoft.AspNet.SignalR.Client.Transports.IClientTransport)
at Microsoft.AspNet.SignalR.Client.Connection.Start(Microsoft.AspNet.SignalR.Client.Transports.IClientTransport)
at Microsoft.AspNet.SignalR.Client.Connection.Start()
I don't know why, but when I catch error, the error text changes and says System.Net.Http is missing.
And I don't know why it runs perfectly as widows application, but not in service.

Categories

Resources