License error using Benchmark.NET + DevArt dotConnect for PostgreSQL - c#

I'm working on an application consisting of several projects and using EntityFramework with dotConnect to run against PostgreSQL. I also have a license for dotConnect which successfully works in the main application.
In parallel, I'm crafting a console application(a different solution) using Benchmark.Net to measure the performance of the logic of one of the projects. But every time I run the benchmark I'm getting the error below:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> Devart.Data.PostgreSql.PgSqlException: Assembly that contains embedded dotConnect for PostgreSQL license cannot be used with this application: 0f238e83-669a-46b8-876f-40331880ee79.exe.exe.
Following this instruction, I have already generated licenses.licx through Visual Studio and <exe file>.licenses via lc.exe. But it is still producing the same error.
I'm suspecting that the fact that Benchmark.NET generates its own exe to run the benchmark causing this error but I'm not 100% sure. So I'm looking for a solution if anybody has one?
Thank you

I'm not sure it's a good idea to create a benchmark for code that does database calls etc. You're benchmarking not the code then, but your whole system instead: the file system, the database drivers, possible interop stuff, and so on.
This is not the idea of BenchmarkDotNet. It's actually created for benchmarking of relatively small CPU-bound tasks to find bottlenecks and perform optimizations based on measurements.
However, if you still want to do that, a solution might be to run the benchmark in-process of the console app you've created, without producing special benchmarking assemblies.
To do so, use the [InProcess] attribute. Just apply it to your benchmark class instead of usual job attributes:
[InProcess]
public class TypeWithBenchmarks
{
[Benchmark]
public void BenchmarkedMethod()
{
}
}

Related

PlatformNotSupportedException throws when using Dapper with WP

Executing a UWP application in DEBUG works perfectly.
Using exactly the same code compiled in RELEASE crashes with this error message
System.PlatformNotSupportedException:
'Dynamic code generation is not supported on this platform.'
when executing this code (it's using Dapper 1.5.1 and System.Data.SQLite 1.0.109.2)
using (var c = NewConnection())
{
var sql = #"
update settings
set
""value"" = #SetDate
where ""key"" = 'week_date'";
c.Execute(sql, new { SetDate = date }); //<= throws PlatformNotSupportedException
// only on RELEASE not in DEBUG
}
The application is UWP configured as below. Furthermore, the faulting code is a .NET Standard 2.0 Class Library
Why is it crashing on RELEASE only and how to fix it?
Dapper is very deeply based on runtime IL generation, in ways that it would be basically impossible to change. Runtime IL generation is fundamentally not compatible with UWP.
There is no simple way of making this work.
So: to do this, you'd need to use something dapper-like-but-not-dapper, with one of two alternative implementations:
reflection-based binding (relatively slow, depending on how much data access you're doing)
compile-time code-gen of the missing pieces, presumably using some kind of roslyn analysis and partial class generation
Perhaps right now, the more pragamatic approach would be: don't use dapper in this case.

SQLCLR-Publish fail for project using ICSharpCode.SharpZipLib

I have a sql clr that has a few functions and Stored procedures. I have the project in an EXTERNAL_ACCESS mode and a key for signing. - works just fine.
I have added another function to the project that uses the ICSharpcode.SharpZipLib. I initially got an incompatibility error for the versions, which I think I resolved following instructions on another post.
The project buids ok, but now I get the following error during that last phase of my project (SQL server db project). This is on my local machine, where I have admin privileges.
Creating [ICSharpCode.SharpZipLib]...
(47,1): SQL72014: .Net SqlClient Data Provider: Msg 6211, Level 16, State 1, Line 1 CREATE ASSEMBLY failed because type '<PrivateImplementationDetails>' in safe assembly 'ICSharpCode.SharpZipLib' has a static field '$$method0x6000014-1'. Attributes of static fields in safe assemblies must be marked readonly in Visual C#, ReadOnly in Visual Basic, or initonly in Visual C++ and intermediate language.
(47,0): SQL72045: Script execution error. The executed script:
CREATE ASSEMBLY [ICSharpCode.SharpZipLib]
AUTHORIZATION [dbo]
FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C0103003877BE5A0000000000000000E00002210B010B000000020000200000000000009E1B02000020000000200200000040000020000000100000040000000000000004000000000000000060020000100000000000000300408500001000001000000000100000100000000000001000000000000000000000004C1B02004F000000002002003804000000000000000000000000000000000000004002000C00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000A4FB0100002000000000020000100000000000000000000000000000200000602E7273726300000038040000002002000010000000100200000000000000000000000000400000402E72656C6F6300000C000000004002000
An error occurred while the batch was being executed.
Appreciate any help !
Thx,
Satya
I guess the first thing would be to see if you could do without IcSharpcode.SharpZipLib. If not then:
If you have access to the source for IcSharpcode.SharpZipLib you could change the static to be read-only.
Last option is to deploy the assemblies with PERMISSION_SET = UNSAFE.
The CLR host that runs within SQL Server is highly restricted as compared to the CLR host running on the OS. One reason for the restrictions is that the App Domains are shared across sessions. So everyone executing a particular SQLCLR method (be it a Stored Procedure, Function, User-Defined Type, User-Defined Aggregate, or Trigger) is executing the same method in the same static class in the same App Domain. Hence, static class variables are shared resources, and unless you are very careful and deliberate in using them, they can quite easily lead to race conditions and odd (and difficult-to-debug) behavior.
The error message is about this, but it is also a bit misleading since it mentions that SAFE Assemblies do not allow such things. More accurately, it is non-UNSAFE Assemblies do not allow such things (i.e. neither SAFE nor EXTERNAL_ACCESS).
So, as Niels mentioned in his answer, you can mark the Assembly as UNSAFE and it will load and probably work. However, unless you know how that variable (and any others that are marked as static but were not yet mentioned) is used, it could lead to race conditions if one session overwrites the value that another session was still using. Or there is potential for a previous value to be left there that could adversely impact the next caller. You would need to look through the code to ensure that this isn't an issue prior to attempting to set the Assembly to UNSAFE.
While not as quick and easy, you really do need to start with updating the code to mark those static variables as readonly and try recompiling to make sure that there are no attempts to write to that variable throughout the code. And if other parts of the code do write to that static variable, then you need to refactor the code or find other code to do the same thing. I ran into this years ago and opted to use DotNetZip for my SQL# project, though I still did need to make minor modifications for things such as static variables.

Method dominator message in CAT.NET

I have installed CAT.NET to analyze a binary.
This is a VS 2013, EF project with output as Class Library.
During the analysis it reports this:
Disabling method dominator caching due to excessive memory usage.
There is no information regarding that message in the output html.
What does this mean and where can I find more info.
Thanks.
I had the same problem with this tool. I opened the task manager during a dll scan and saw that the memory was increasing quickly, after that the tool showed the message, the memory usage decreased and the scan finished in a few seconds. It seems like the tool has a memory usage prevent system and I didn't find any information about it.
What I found was that this tool wasn't seem to be in code maintaining (the tool was released more than 3 years ago) and the version 2.0 never was released, in fact the 2.0 beta version was removed from the download repository. In the next link, there is a discussion, including Microsoft's developers opinions and the reason why they removed the file, but there isn't opinion about the new release http://social.msdn.microsoft.com/Forums/Lync/en-US/31663b6d-254e-48ce-8345-3355cb8b6023/whats-the-status-of-catnet-20?forum=catnet.
I ignore the reason why you use this tool, personally I chose it to prevent sql injection attacks. I did a very simple example to prove it:
internal static List<Category> GetCategoryNames(CategoryRequest request)
{
string sql = #"select classId, name from class where name like %"+ request.Name + "%";
return SqlUtils.ExecuteList(sql, "dbname", CategoryNameMapper);
}
and the tool didn't show me any risk in the report. I found another guy with the same problem http://social.msdn.microsoft.com/Forums/en-US/c99de49d-c541-40df-bb85-de5951261e0c/using-catnet-to-check-for-security-vulnarabilities-better-tool-available?forum=clr
That's why I decided to look around another options, if I find another tools with similar issues, I let you know.
Regards,
Omar.

Exception from HRESULT: 0x80040013: when Integrating R with C#:

I am trying to interface R with C# web application.I tried many solutions being provided but couldn't get it through. Error I am getting is: Exception from HRESULT: 0x80040013
Steps I followed were:
Installing R 2.15.1 for windows xp (32 bit)
Installed R_Scilab_DCOM3.0-1B5
Loaded rscproxy_1.3-1 package in the R/R.15.1/library
Set the System Variable path to C:/Program Files/R/R.15.1/bin
Added 3 COM references-STATCONNECTORCLNTLib,StatConnectorCommonLib,STATCONNECTORSRVLib
Code:
private StatConnectorClass _statconnector = new STATCONNECTORSRVLib.StatConnectorClass();
_statconnector.Init("R");--> Line shows the Exception from HRESULT: 0x80040013
I have used the COM method to interface to c# some years ago, but I gave up because on each version change there were problems similar to that you mentioned. In addition, the licensing scheme of R(D)COM is a bit obscure to me, and the .NET/COM/R tour has too many corners.
My current choice is Rserve, which is well maintained and has never let me down. I had written my own test bed for c#, but I consider it obsolete because RserveCLI is more complete.
R.NET in theory is a better concept, but for strange reasons it is considered "stable" by the author, which is highly euphemistic because of the many bugs mainly in memory management. Too bad it never took off.
I believe R.NET is a much better way to access R functionality from C#. It all runs in-process and so doesn't require an external R process to be running.
If you install the NuGet package, you will get version 1.5. This incorporates some memory management fixes I made that address most of the crashes people have reported. As Dieter points out, we use R.NET extensively via the F# RProvider, and it is extremely stable with the latest version. The RProvider also comes with a wrapper generator that generates wrapper functions for R functions which can be used from C#. So for example you could call the plot function from C# as R.plot(...params...). And you get Intellisense.

FunctionWithCollation unit test fails with System.Data.Sqlite

I downloaded SqlLite 3.7.3 and allegedly the best .NET wrapper for this database engine. I put them in the same directory and ran their provided test.exe.
Most tests succeeded, but two failed. FunctionWithCollation failed with SQLite error "no such function: CHARINDEX" and FunctionWithCollation2 failed with "The method or operation is not implemented".
The support site is silent and so is google. Does anybody have an idea what that means, and how if at all should I proceed?
First of all it would be very good to mention what are FunctionWithCollation and FunctionWithCollation2 do so it would be easier to see what happens.
AFAIK sqlite3 does not support collation built-in as it is quite hard thing to do and allows you to plug in your own collation functionality: http://www.sqlite.org/c3ref/create_collation.html, AFAIK there are some ICU based collation providers.
So check this direction if it does not require you do add some plugin or so.
EDIT: From quick glance to the source code, the unit tests do some testing on charindex function. This function is extension, so:
It seems a problem with either build or with the program or combination of them
I don't think you should care unless you are using extensions. See: http://www.sqlite.org/contrib
In any case I would suggest filling a bug.

Categories