Microsoft.SqlServer.Management.Smo.FailedOperationException (Could not load batchparser.dll) - c#

I have C# project in which I am using Microsoft.SqlServer.Management.Smo, Microsoft.SqlServer.batchparser.dll and few other SqlServer dlls.
When I run the code on development box it works fine, but when I try running the executable on a clean machine (client's machine), it fails and throws this exception:
Microsoft.SqlServer.Management.Smo.FailedOperationException: ExecuteNonQuery failed for Database 'testdb'. ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.SqlServer.BatchParser.dll' or one of its dependencies. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)
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)
at Microsoft.SqlServer.Management.Common.ServerConnection.GetStatements(String query, ExecutionTypes executionType, Int32& statementsToReverse)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType)
at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries, ExecutionTypes executionType)
at Microsoft.SqlServer.Management.Smo.Database.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType)
Now if I install "Microsoft SQL Server 2012 Shared Management Objects" on the client's machine it starts working.
I want to find out exactly what dependency is causing batchparser to fail. I grabbed the assemblies from the "Microsoft SQL Server 2012 Shared Management Objects" installer and copied them into GAC, but still the same error.
My questions are:
1 - How can I find the dependency of the batchparser.dll and append it to my installer?
2 - Is there a re distributable package for sql server 2012 that I can install before my application.
Thanks,
Ali

For anyone having the same problem,
Installing Microsoft Visual C++ Redistributable Package ATL Security Update fixed the problem for me.
Cheers,

Related

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).

Emgu Could not found cvextern in IIS server

I'm having some issues running the Emgu on my server. It runs fine locally, but when I try to use it on the server with IIS, it doesnt work.
Here is the error:
System.TypeInitializationException: The type initializer for 'Emgu.CV.CvInvoke' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'cvextern': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Emgu.CV.CvInvoke.RedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)\r\n at Emgu.CV.CvInvoke..cctor()
--- End of inner exception stack trace ---
at Emgu.CV.CvInvoke.cvCreateImageHeader(Size size, IplDepth depth, Int32 channels)
at Emgu.CV.Image`2.AllocateData(Int32 rows, Int32 cols, Int32 numberOfChannels)
at Emgu.CV.Image`2.set_Bitmap(Bitmap value)
at VerifyID.Managers.ImageTreatmentsManager.ExtractDocumentFromImage(Bitmap bitmap)
at VerifyID.VerifyWorker.ExecuteOCR(BigIdRequest request, BigIdEvent bigIdEvent)
I have the following dlls inside the x86 and x64:
concrt140.dll*
liblept172.dll*
msvcp140.dll*
vcruntime140.dll*
cvextern.dll*
libtesseract304.dll*
opencv_ffmpeg320.dll*
IIS version: 10.0
After copying the x64 dlls directly to the bin directory of the build the error changed to:
System.TypeInitializationException: The type initializer for 'Emgu.CV.CvInvoke' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at Emgu.CV.CvInvoke.RedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)
at Emgu.CV.CvInvoke..cctor()
--- End of inner exception stack trace ---
at Emgu.CV.CvInvoke.cvCreateImageHeader(Size size, IplDepth depth, Int32 channels)
at Emgu.CV.Image`2.AllocateData(Int32 rows, Int32 cols, Int32 numberOfChannels)
at Emgu.CV.Image`2.set_Bitmap(Bitmap value)
at VerifyID.Managers.ImageTreatmentsManager.ExtractDocumentFromImage(Bitmap bitmap)
at VerifyID.VerifyWorker.ExecuteOCR(BigIdRequest request, BigIdEvent bigIdEvent)
Could someone help ?
I had this same problem, the application works perfectly on the local server (IIS Express used by the Visual Studio) but not on the remote Windows server, the solution that worked for me was:
(Please test your application between each step, maybe you don't need to do them all)
In Visual Studio, open your application project properties and set the "Platform" to "Any CPU". Then publish your application to the remote server.
Move all .dll files inside the x86 folder to the bin folder, pay special attention to the cvextern.dll, it must be inside the bin folder side by side with your application dll.
Install Visual C++ Redistributable for Visual Studio on the remote server (just google it and you will find the download link. Please choose the download version according to your VS version, 2013, 2015, 2017, 2020, 2050...). Use the x86 installation even if you sever OS is x64.
Activate your app_pool for the application for running 32 bit. https://help.webcontrolcenter.com/kb/a1114/how-to-enable-32-bit-application-pool-iis-7-dedicatedvps.aspx
Go to the application \bin folder, grant the file security for the folder "x86" (which contains all the dll for emgu) as described in the following link "http://www.iis.net/learn/manage/configuring-security/application-pool-identities if your apppool being in used in defaulapppool, then you should add user "IIS AppPool\DefaultAppPool"
I really don't know why the x64 versions of those dlls are not working on the server for me. I still investigating it and as soon I find out why I will update this post.
Another solution (that is not elegant at all, but works) is to install the Visual Studio at the server, doing the same installation process that you have done for your development environment. By doing this you will have all dependencies and dlls needed (including the Visual C++) installed on the server.
Hope it helps!

ClickOnce Deployment - FileNotFoundException

I'm having a problem using ClickOnce,
It is an online Clickonce.
My project is C# project built in Visual Studio 2013.
The application works on 99% of the machines , but there are few computers which it doesnt deploy containing the error:
Following errors were detected during this operation. * [16/08/2015
14:19:05] System.IO.FileNotFoundException
- The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
- Source: mscorlib
- Stack trace: at System.Deployment.Internal.Isolation.IsolationInterop.CreateActContext(CreateActContextParameters&
Params) at
System.Deployment.Internal.Isolation.IsolationInterop.CreateActContext(IDefinitionAppId
AppId) at
System.ActivationContext.CreateFromName(ApplicationIdentity
applicationIdentity) at
System.ActivationContext.CreatePartialActivationContext(ApplicationIdentity
identity) at
System.Deployment.Application.ApplicationActivator.Activate(DefinitionAppId
appId, AssemblyManifest appManifest, String activationParameter,
Boolean useActivationParameter) at
System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri
activationUri, Boolean isShortcut, String textualSubId, String
deploymentProviderUrlFromExtension, BrowserSettings browserSettings,
String& errorPageUrl) at
System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object
state)
The error occur in the end of the installion, but I suppose it doesnt really install (there are some files in the appdata folder, but when I click the ClickOnce installer again, it reinstall it from 0)
I've done some research, and I got to the registry key :
HKEY_CURRENT_USER\Software\Classes\Software\Microsoft\Windows\CurrentVersion\Deployment\OnlineAppQuotaUsageEstimate
Which is the cache location for online Clickonce applications.
On the computers which works, after the installer the value change to 837207846
On the computers which the ClickOnce doesnt work, it changes to 0.
any suggestions how to fix that problem?

Intermittent Catastrophic Failure exception with .Net application via PsExec

we're seeing an intermittent problem when we try to run a .Net 4.0 application on a remote computer via PsExec.
The target computer is Windows Server 2008 SP2 64-bit with .Net 4.0 and .Net 4.5 installed.
I've been told that this has been happening here since .Net 4.5 was installed, but I'm new to the project, so I can't confirm that this is when the problem started happening.
The code that is failing is doing this:
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
return (ParameterData)config.GetSection("ParameterData");
Here's the stack trace:
System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) ---> System.Runtime.InteropServices.COMException: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at System.Security.Policy.PEFileEvidenceFactory.GetLocationEvidence(SafePEFileHandle peFile, SecurityZone& zone, StringHandleOnStack retUrl)
at System.Security.Policy.PEFileEvidenceFactory.GenerateLocationEvidence()
at System.Security.Policy.PEFileEvidenceFactory.GenerateEvidence(Type evidenceType)
at System.Security.Policy.AssemblyEvidenceFactory.GenerateEvidence(Type evidenceType)
at System.Security.Policy.Evidence.GetHostEvidenceNoLock(Type type)
at System.Security.Policy.Evidence.GetHostEvidence(Type type, Boolean markDelayEvaluatedEvidenceUsed)
at System.Security.Policy.AppDomainEvidenceFactory.GenerateEvidence(Type evidenceType)
at System.Security.Policy.Evidence.GetHostEvidenceNoLock(Type type)
at System.Security.Policy.Evidence.RawEvidenceEnumerator.MoveNext()
at System.Security.Policy.Evidence.EvidenceEnumerator.MoveNext()
at System.Configuration.ClientConfigPaths.GetEvidenceInfo(AppDomain appDomain, String exePath, String& typeName)
at System.Configuration.ClientConfigPaths.GetTypeAndHashSuffix(AppDomain appDomain, String exePath)
at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigurationHost.get_ConfigPaths()
at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath)
at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
--- End of inner exception stack trace ---
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.Configuration..ctor(String locationSubPath, Type typeConfigHost, Object[] hostInitConfigurationParams)
at System.Configuration.ClientConfigurationHost.OpenExeConfiguration(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath)
at System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath, Boolean preLoad)
at System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel userLevel)
This is executed during our automated test build deployment process. I've been able to boil it down to a simple executable that does the code above, and I call PsExec from my Windows 7 development machine, but the problem's intermittent.
It seems to occur more regularly if I wait several minutes between invocations of PsExec. I started looking at this problem today, and was able to repro it pretty regularly in the morning, but not very easily in the afternoon.
I also see warnings like this in the Event Log:
Windows detected your registry file is still in use by other applications or services. The file will be unloaded now. The applications or services that hold your registry file may not function properly afterwards.
DETAIL -
1 user registry handles leaked from \Registry\User\mySID:
Process 5568 () has opened key \REGISTRY\USER\mySID
I don't know how the Event Log errors are related to the exception, if at all.
The PsExec command line is: PsExec /accepteula \\myServerName -d "path_to_exe"
I'm wondering if it's a problem with the user profile service, so I was thinking about not loading the profile when calling PsExec, but since it's so intermittent, I'm not sure how I would know if I've fixed it.
Searching the internet shows that some people think it might be related to impersonation, but nothing that directly matches my situation.
Has anyone seen anything like this? This is really weird.
Thanks!
Phil
if it works when run locally but not when run remotely there's a possibility:
When using PsExec the programs on the remote machine are limited to 150MB of memory
Running this on the remote machine will allow remote commands to use more than 150 MB of memory:
set-item wsman:localhost\Shell\MaxMemoryPerShellMB 2048

ASP.NET integration tests - TestDrive.net won't run them, other testrunners will

I recently had problems with integration tests after I upgraded my solution to .NET 4.0 - the answer to that question was to grab the 64 bit version of System.Data.SQLite.dll.
I've figured that out but I have a related problem. My integration tests execute when I use the Resharper testrunner, but an exception is thrown when I use the TestDriven.NET testrunner:
Test 'MyApp.IntegrationTests.DataAccess.Providers.ContactFormSubmissionProviderTest.CanFetchContactFormSubmissionById' failed:
System.TypeInitializationException : The type initializer for 'MyApp.DataAccess.NHibernate.SessionManager' threw an exception.
----> NHibernate.HibernateException : Could not create the driver from NHibernate.Driver.SQLite20Driver.
----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> NHibernate.HibernateException : The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. Ensure that the assembly System.Data.SQLite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
at MyApp.DataAccess.NHibernate.SessionManager.OpenSession()
DataAccess\Providers\ContactFormSubmissionProviderTest.cs(28,0): at MyApp.IntegrationTests.DataAccess.Providers.ContactFormSubmissionProviderTest.CanFetchContactFormSubmissionById()
--HibernateException
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
at NHibernate.Connection.ConnectionProvider.Configure(IDictionary`2 settings)
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2 settings)
at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2 properties)
at NHibernate.Cfg.Configuration.BuildSettings()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
NHibernate\SessionManager.cs(18,0): at MyApp.DataAccess.NHibernate.SessionManager..cctor()
--TargetInvocationException
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
--HibernateException
at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName)
at NHibernate.Driver.SQLite20Driver..ctor()
The image:
I also tried the solution in this link; it didn't help. How can I run my tests from Testdriven.Net?
UPDATE:
My project is set to built as Any CPU, Release platform.
My OS is Windows 7 64-bit. I have linked against both x86 and x64 versions SQLite. Explanation:
My solution has several projects - DataAccess, IntegrationTests, Core, and UI. All are .net 4.0 projects, and all are class libraries with the exception of UI, which is an MVC 3.0 project. I'm using nUnit 2.4.8.0. My DataAccess layer utilizes NHibernate.
My UI project references 1.0.60.0 (Otherwise I cannot run my app from within VS2010).
My IntegrationTests project references 1.0.74.0 (Otherwise I cannot run my tests using Resharper's TestRunner).
My DataAccess project references 1.0.60.0, and
My Core project has no knowledge of anything database related.
1.0.60.0 is the x86, and 1.0.74.0 is the x64.
When the site is deployed, the server requires x86.
UPDATE 2:
There is an option for TestDriven.NET for it use 32-bit or 64-bit processes under Tools -> Options -> TestDriven.NET. I changed this to 64-bit. Now, rightclicking and selecting "run tests" will execute them fine, but I still have the same problem with "Test with NCover" or "Test with Coverage", which is what I really want to accomplish.
I think you might have answered your own question :)
Most of the runners you mention will run in x86 mode by default, you've had to find specific instances where you can tell certain runners (like TestDriven.net) to use x64 to run on your machine, but now you're hitting the same problem with NCover or Coverage.
So, the solution is to just force the project to build against x86 instead. Your libraries will target x86; ReSharper's runner will detect this from the build configuration in your solution. Since your target production machine is x86, there's no issue. You can run x86-targetted assemblies on Win7 x64.
Go to your solution config, and for each of your projects, select the "target platform" to be x86. Reference the x86 SQLite assembly from all your projects. This is how we have it set up on several projects on Win7x64 dev machines with NCrunch, R#, dotCover all behaving fine.

Categories

Resources