Call .NET Standard DLL in SQL Server - c#

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

Related

Missing Browserlink in VS2019, Where is browserlink acquired / loaded from normally?

My local install of VS2019 (16) seems to be missing references to BrowserLink. I've tried repairing the installation, and installing multiple different SDK's to no avail.
Where is BrowserLink normally located? And what is the mechanism that causes it to be loaded in development versions? It doesn't seem to be packaged seperately from VS since version 12, unless you are using the new .net core versions.
We have checked the GAC, NuGET, and are running out of options.
It's a .net 4.5 project, if that's relevent.
Could not locate assembly Microsoft.WebTools.BrowserLink.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in the Assembly Stores configured. Requesting assembly:
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.Exception: Could not locate assembly Microsoft.WebTools.BrowserLink.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in the Assembly Stores configured. Requesting assembly:
The root cause is almost certainly something to do with the dumb way this project has a shared non-standard assembly cache, and doesn't fallback to normal dev locations, but the question is about what the normal location/mechanism is for BrowserLink (16) to be loaded.
If you have installed your VS2019 in default options, you can find the Browser Link library files in this path:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\Microsoft\Web Tools\Browser Link
(Replace the path of your installation location as appropriate)
You can then decide whether to copy Microsoft.WebTools.BrowserLink.*.dll to the assembly cache of your application or include this path in your application.

Could not load file or assembly System, Version=2.0.5.0 in .NET 4 MVC 4 application

Been searching for ages, can't find anything helpful. Here is the exception I'm getting:
Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
Exception Details: System.IO.FileLoadException: Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
Stack Trace:
[FileLoadException: Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)]
StructureMap.Graph.PluginGraph..ctor() in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Graph\PluginGraph.cs:41
StructureMap.PluginGraphBuilder..ctor() in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\PluginGraphBuilder.cs:22
StructureMap.InitializationExpression..ctor() in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\InitializationExpression.cs:22
StructureMap.ObjectFactory.Initialize(Action`1 action) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\ObjectFactory.cs:47
...
This applications works fine on the test server but is throwing this exception on the production server. As you can see, the StructureMap code is what is causing the exception.
I had to convert this app to .NET 4 from 4.5 because 4.5 wasn't installed on the production server. After the conversion, the app still works fine on my local machine and the test server.
I have already set the Copy Local to True for the System assembly, but since the referenced version is 4.0.0.0 and not 2.0.5.0, I this made no difference.
Let me know if any more info is needed. Any help you may be able to provide is appreciated.
Make sure your .NET framework is patched. Microsoft released patches to .NET to allow Portable Class Libraries to properly find the appropriate runtime (KB2468871). If you are seeing the above exception (or something like it), it means you're missing the latest .NET framework patches.
Edit the web.config file to remove the reference, which is not required for normal operation:
1 - Open the web.config file in the root of your site
2 - Find the following line and comment it out():xxxxx-is your assembly name.
<add assembly="xxxxx", Version=2.0.5.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
3 - Save and close the web.config file and try again
I found that it was the "await" and "async" that where giving me trouble.
I had Windows XP SP3 with only .NET 4.0, but had to update it to .NET 4.0.3 using KB2600211 - this wasn't updated automatically through Windows Update when .NET 4.0.3 came out because the computer is off-grid.
This is the link to the update:
https://www.microsoft.com/en-us/download/details.aspx?id=29053
I just want to share another solution from here that solved the problem on my development machine: installing Silverlight 5 SDK (only 11.2MB at the time of writing this post) was enough to make everything working.
Install Microsoft® Silverlight® 5 SDK from the following link. It resolves and works fine for me.
SDK download
Starting from a machine configuration that only had VS2017 and Silverlight 5 SDK on it, I installed VS2015 on top of that. This is when I started getting the System.Core and System.Windows problems.
When I uninstalled VS2015 and re-installed Silverlight 5 SDK, these problems went away.

Error in deploying SQL CLR

Error1:
The following error might appear if you deploy a SQL CLR project that was built for a version of the .NET Framework that is incompatible with the target instance of SQL Server: "Deploy error SQL01268: CREATE ASSEMBLY for assembly failed because assembly failed verification". To resolve this issue, open the properties for the project, and change the .NET Framework version.
Error2:
Deploy error SQL01268: .Net SqlClient Data Provider: Msg 6503, Level 16, State 12, Line 1 Assembly 'system.servicemodel, version=3.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.' was not found in the SQL catalog.
An error occurred while the batch was being executed.
Have to install System.ServiceModel in Sql Server 2008 and it worked after that.
Happy Coding :)

Ngen error because "Mscorlib.dll does not have a native image" (x64 only, .NET 4.0 only)

I'm trying to generate a native image of my .NET 4.0 application using Ngen using a 64-bit Windows 7. When Platform is set to x64 (or Any CPU) - Ngen fails, complaining that 'NGen cannot proceed because Mscorlib.dll does not have a native image.'
When compiling as x86 and using the appropriate Ngen - it works fine. Also, when changing the .NET version to 2.0 - it works. (When trying to Ngen the x64 application with the x86 Ngen, it tells me I should use the 64-bit version.)
More information:
This is (part of) what I see in CMD: The ellipses (= ...) are present in the original.
1> Compiling assembly mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 (CLR v4.0.30319) ...
1>mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
.
2> Compiling assembly Accessibility, Version=4.0.0.0,
Culture=neutral, Public KeyToken=b03f5f7f11d50a3a (CLR v4.0.30319) ...
.
2>Ngen failed to generate native code for image Accessibility,
Version=4.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
because of the following error: NGen cannot proceed because
Mscorlib.dll does not have a native image (Exception from HRESULT:
0x80131F06)
Searching inside C:\Windows\assembly I found 3 mscorlib.dll's. One in GAC_32, one in GAC_64 (both in subfolders beginning with 2.0.0.0) and one in a subfolder temp.
When searching inside C:\Windows\Microsoft.NET I found six of them: two under assembly (in GAC's 32 and 64) both in folders that begin with 'v4.0...', and four in Framework's: 2 in Framework, and two in Framework64 (in each - one in 'v2.0...' and one in 'v4.0...').
Does this mean that only .NET 2.0 mscorlib's are really run as native images (when needed)? And why doesn't Ngen succeed in saving native images of .NET 4.0?
Bottom line: How do I create a native image of a .NET 4.0 application that targets x64?
This is unhealthy. The ngen-ed image of mscorlib.dll should have been created when .NET was installed on your machine. It is located in c:\windows\assembly\NativeImages_v4.0.30319_64\mscorlib\ab0a8fc3d086a3aaf942f366a12a9185\mscorlib.ni.dll. I'm not sure how well the hashed part of the directory name repeats from one machine to another.
You cannot see this file with Windows Explorer, you must use the command prompt. Go check to see if it there, something went seriously wrong when .NET was installed if it is missing. The ".NET Runtime Optimization Service" is the one that gets that job done, make sure you didn't disable it.
A standard mistake is running ngen.exe from a command prompt that isn't elevated.

The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception

I'm working on a project and have run into an issue. When I run my code I get this error message:
The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception
The title of the message is "TypeInitializerException was unhandled".
I receive this error at this line of code:
this.crystalReportViewer = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
I've been looking up ways to fix this issue, but I keep running into another issue. Everything I find about how to fix this says that the platform target should be changed to x86. All the comments that follow that advice are always positive because it seems to work for everyone, but it's not working for me. I also tried the platform target as x64. When I do that, I don't receive the previously stated error, but instead I receive a new error that reads:
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
The title of this message is "InvalidOperationException was unhandled".
And the error is on this line:
db.Open();
db, of course, being set to a new OleDbConnection(connection). connection = an Access db.
Why am I receiving the first error and not the second error when platform target is x86, and vice versa if the platform target is x64?
Stacktrace:
System.TypeInitializationException was unhandled
Message=The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception.
Source=CrystalDecisions.Shared
TypeName=CrystalDecisions.Shared.SharedUtils
StackTrace:
at CrystalDecisions.Shared.SharedUtils.get_CurrentControl()
at CrystalDecisions.Shared.SharedUtils.GetEffectiveCulture()
at CrystalDecisions.Shared.LocaleManager..ctor()
at CrystalDecisions.Windows.Forms.CrystalReportViewer.InitReportViewer()
at CrystalDecisions.Windows.Forms.CrystalReportViewer..ctor()
at Client_Manager.ReportViewer.InitializeComponent() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\ReportViewer.Designer.cs:line 31
at Client_Manager.ReportViewer..ctor() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\ReportViewer.cs:line 27
at Client_Manager.Form1..ctor() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\Form1.cs:line 174
at Client_Manager.Program.Main() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.BadImageFormatException
Message=Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source=CrystalDecisions.Shared
FileName=log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304
FusionLog==== Pre-bind state information ===
LOG: User = Will-PC\Will
LOG: DisplayName = log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304
(Fully-specified)
LOG: Appbase = file:///C:/Users/Will/Desktop/Client_Manager/SyndicateII/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Will\Desktop\Client_Manager\SyndicateII\bin\Debug\Client_Manager.vshost.exe.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304
LOG: Attempting download of new URL file:///C:/Users/Will/Desktop/Client_Manager/SyndicateII/bin/Debug/log4net.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
StackTrace:
at CrystalDecisions.Shared.SharedUtils..cctor()
InnerException:
This looks like it's the original problem:
InnerException: System.BadImageFormatException
Message=Could not load file or assembly 'log4net, Version=1.2.10.0,
Culture=neutral, PublicKeyToken=692fbea5521e1304'
or one of its dependencies. An attempt was made to load a program
with an incorrect format.
So it looks like either you're using the wrong version of log4net if it has multiple versions for different architectures, or you've just copied the assembly incorrectly. This part of the log seems relevant too:
LOG: Attempting download of new URL
file:///C:/Users/Will/Desktop/Client_Manager/SyndicateII/bin/Debug/log4net.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
That looks like it's the file you need to check for correctness.
It could be useful to someone: if you have the option to do it, go to IIS and set the Application Pool to 32 bit applications only.
That made the trick for me.
(Of course, your application could be made to run only on 64 bit. In that case, I think the installing of the 64 bit redistributable of CrystalReports should solve the issue)
You should install SAP Crystal Reports runtime for .Net 4.0
I had the same issue. 32bit app running on a 64bit server. I had installed the 64bit runtime and the above exception was thrown. After installing the 32bit version all worked as expected.
What I did for this error was to install CrystalReport Runtime. It seems missing some dlls. Check this post out for the package SAP Crystal Reports runtime for .Net 4.0 (64-bit).
Make sure you have the correct version installed for your environment it try the 64bit installer not the 32bit one as they will both install fine but then the wrong one will cause the mentioned error.
I had the exact same problem and installing the 64bit version instead fixed things for me
this problem is the driver of crystal report is not install on the client and they are in the crystal report home directory and sub folder
and named crystal.forms and crystal.shared and crystal suport and so
I solved my problem changing the application pool identity, using the local profile and the administrator login (take a look if the password expires).
Symptoms are similar.
I think that Log4net pops up because Crystal wants to log the error that has already happened.
I don't have any log4net in my project, neither the dll file.
My project is compiled with AnyCpu over a 64bit server, and I already have both CRRedist x86 x64 installed.
I also tried to run in 32bit mode without any change.
I'm having the same issue with crystal report, I just change Platform Target "Any CPU" as you can see in screenshot below too.
Depending on the version you have installed, if you only have the 32-bit version installed you must compile to x86 or if you only have the 64-bit version installed you must compile on x64, if you have both versions installed you must compile on anycpu.
If you compile on anycpu but on the pc you have the 32-bit version it will send you an error.
Cheers
As other people already figured out: This can happen due to runtime mismatch (x86 / x64).
After force building my application for x86 architecture, the error was fixed.
You should install the Crystal Reports Runtime Engine for .Net Framework and
Crystal Reports for Microsoft Visual Studio.

Categories

Resources