Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems on .Net Core #1

Closed
mwittmann opened this issue Apr 4, 2020 · 7 comments
Closed

Problems on .Net Core #1

mwittmann opened this issue Apr 4, 2020 · 7 comments
Assignees
Labels
question Further information is requested

Comments

@mwittmann
Copy link

I've tried integrating this into .Net Core 3.1 web project. While basic Dapper.Query<>(...) commands are fine, when I tried a Repository.Delete(...) call, I got:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'Microsoft.Data.SqlClient.SqlConnection' threw an exception.
  Source=Microsoft.Data.SqlClient
  StackTrace:
   at Microsoft.Data.SqlClient.SqlConnection..ctor()
   at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString, SqlCredential credential)
   at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
   at Dapper.SimpleRepository.Repository.OpenConnection(String connectionString)
   at Dapper.SimpleRepository.Repository.Delete[T](Int32 id)
   at Dapper.SimpleRepository.Repository`1.Delete(Int32 id)
   ...other call stack omitted...

Inner Exception 1:
MissingMethodException: Method not found: 'System.Security.CodeAccessPermission System.Data.Common.DbProviderFactory.CreatePermission(System.Security.Permissions.PermissionState)'.

Digging around, it seems that the System.Data.Common.DBProviderFactory for .Net Core is incomplete (per dotnet/SqlClient#17, https://apisof.net/catalog/System.Data.Common.DbProviderFactory.CreatePermission(PermissionState)).

I've hit a wall. Any fixes or workarounds for this?

@ccrookston
Copy link
Owner

Hello mwittmann, I have not been able to reproduce this error. If you like, I can send you a sample solution that I am using for testing (which contains a Core 3.1 Web App). Or, if it would be easier, you could send me your own solution (scaled down, if you like, to remove any proprietary code) and I can troubleshoot it. Let me know which you prefer.

@ccrookston ccrookston self-assigned this Apr 6, 2020
@ccrookston ccrookston added the question Further information is requested label Apr 6, 2020
@mwittmann
Copy link
Author

I think it would be faster for you to send your sample solution. I'll let you know what I find.

@ccrookston
Copy link
Owner

Sure mwittmann. My personal email is [email protected]. Send me an email, and I will reply with a copy of the test solution.

@mwittmann
Copy link
Author

Casey, your .Net Core 3.1 test project worked fine for me, thanks. I did some additional testing, and it appears to me that my issue arose because I was calling from a .Net Core 3.1 web app into a class library containing the Dapper and Dapper.SimplerRepository code targeting .Net Framework 4.7.2. I did not get to the precise reason why why the straight Dapper code worked in that scenario, while SimpleRepository did not. But when I converted the class library to target .Net Core 3.1, everything worked fine... the original problem disappeared.

I ended up converting the class library to target .Net Standard 2.0 so it could be used with better compatibility (presumably) in both .Net Core and .Net Framework projects. I also ended up switching the "System.Data.SqlClient" to "Microsoft.Data.SqlClient." I haven't actually looped back to test Dapper.SimpleRepository with these changes, but will update this thread when I do. The library is working fine with Dapper and direct SqlClient access.

@mwittmann
Copy link
Author

Quick follow-up: Dapper.SimpleRepository is working fine with the class library targeting .Net Standard 2.0 and "Microsoft.Data.SqlClient."

@ccrookston
Copy link
Owner

Hi, I am going to close this issue. Please let me know if you have any more issues. Thank you.

@sunilsutar-veyo
Copy link

This issue still exists with .net6 if I use my new project with .net6 and dapper's library implementation class library with .net framework 4.7.2.

We can't upgrade the dapper's common library implementation to .net6 yet.
But the issue occurs with following error -
"Method not found: 'System.Security.CodeAccessPermission System.Data.Common.DbProviderFactory.CreatePermission(System.Security.Permissions.PermissionState)'." with basic use of using (context)
{
connection.open()...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants