开发者

Error while compiling a library in C#

I am trying to compile a class(sqlAccess) declared as public with few methods related to database connection in it. I am getting the following error ...

Error   1   Friend access was granted to 'SqlAccess, PublicKey=00c8', but the      output assembly is named 'SQLAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Try adding a reference to 'SqlAccess, PublicKey=00c8' or changing the output assembly name to match.    c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.开发者_Python百科Data.dll  SQLAccess

What could be the reason? is there already a method of that name? I am new to programming so am unable to understand this clearly. Thank you.


This worked for me: Open the Properties|Signing Tab. Ensure that you have "Sign the Assembly" checked and the strong name key file referenced. Save and compile the Project/Solution. (cited from MSDN)


.NET seems to get grumpy if you give your assembly/project a name that isn't unique. In your case, SqlAccess must already exist in .NET or a referenced assembly.

The fix is to rename your assembly.

Similar issue: Weird error in C#


That's because SqlAccess assembly has a reference which granted internal access to SqlAccess. It must be something like this [you will find it in AssemblyInfo.cs] :

[assembly: InternalsVisibleTo("Name of assembly goes here, PublicKey=")]

During compile time when compiler can not find assembly with specific PublicKey, you will get the error such as 'Friend access was granted to...'. In order to resolve this problem one solution is to remove above attribute from source assembly, or add new public key and change it in source assembly.


Reason behind this should be either you have reinstall/update that particular dll within your solution and but old dll was not deleted properly from your solution and system. That's why, it got worked when you change the Assembly name (from sqlAccess to sqlAccessXYZ)


I changed the Assembly name to sqlAccessXYZ and now its working, the problem is with the name. Not sure what exactly the problem, for now the issue is resolved. Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜