I'm using Visual Studio 2010 unit testing features in a project of mine. I'm running into problems trying to create a private accessor.
MyProject:
The strong name key is password protected (.pfx file instead of .snk)
I use InternalsVisibleTo attribute to provide access to internals for MyProject.Tests
Verification of the key is skipped (on development systems) with sn -Vr ... to allow instrumentation in Release builds; for the purpose of obtaining code coverage. This is because the instrumentation part of Visual Studio does not support password protected keys.
MyProject.Tests:
Signed with the same key as MyProject, to allow use of InternalsVisibleTo
I'm trying to generate a private accessor in this project to test some private methods.
When trying to compile the test project with the newly added private accessor, I'm getting the following error message:
Error occurred during processing of assembly 'MyProject.dll': Unable
to obtain public key for StrongNameKeyPair.
I've browsed the internet regarding the error message, but the only solution I could find was to disable signing on the test project. Doing so would mean that I am no longer able to use InternalsVisibleTo. It might work if I rewrite all my existing unit tests for internal members to use shadowed types as well, but obviously I don't want to do so.
Are there any better options?
In case it matters: the strong name key is password protected because the source control system is fairly public, but I wanted to prevent access from anybody outside the development team.
Related
I am trying to generate an OpenApi service reference in Visual Studio 2019. .Net 5.0.
Right clicking project >Add>Connected Services>+ Service References
I am using NetDocs api "https://api.vault.netvoyage.com/v2/swagger/docs/v2".
Result: I get generated c# client code but it is duplicating the types with the errors below.
Severity Code Description Project File Line Suppression State
Error CS0102 The type 'v2Client' already contains a definition for '_settings' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4941 Active
Error CS0579 Duplicate 'System.CodeDom.Compiler.GeneratedCode' attribute OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4936 Active
Error CS0102 The type 'v2Client' already contains a definition for '_baseUrl' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4939 Active
Error CS0102 The type 'v2Client' already contains a definition for '_httpClient' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4940 Active
Is there a way I can get this to work with the connector way without the duplicates? Or even cli? Any suggestions on why it is creating the duplicates?
I had the same issue, it turns out the code generation didn't like enpoints with an underscore in its operationId. Lucky for me, the service I was consuming was also part of our code, so I could just go to the Swagger configuration in the API side and change the CustomOperationIds setting.
I downloaded and use NSwagStudio to generate the client code and did not have the same issue that the Visual Studio connector had when generating the code.
https://github.com/RicoSuter/NSwag/wiki/NSwagStudio
It is actually caused by this option
OperationGenerationMode:MultipleClientsFromOperationId
MultipleClientsFromOperationId : Multiple clients from the Swagger operation ID in the form '{controller}_{action}'
However, if your classname is set as a static name, it will cause an error like you have.
The correct solution should be change the classname to something like
ClassName="{controller}ServiceClient"
So it will generate different classes.
I want to set connection string for my DataSet to None, because i use string that i build in run time. So i do not want keep fake string in app.config, just tome make xsd compile. Is there any way to achieve this?
If i set None in designer its still turn it to existing connection string from config.
I use visual studio 2017.
The best way I've found to have the benefits of the XSD designer and be able to change the connection settings for staging and production is as follows: - NOTE: this works in VS 2012 ... think it should also in 2010 - Also, DataSets were created by dragging from the Server Explorer, which saves connection information in the class library app.config and Properties.Settings.settings which is used at design time.
1) For each DataTable, click on the TableAdapter header (below the attributes and above the methods) and look at the properties 2) Change the Connection Modifier to Public 3) Then, the code to access the table should be something like the following (where the class library is named DALib) ...
using DALib;
using System.Web.Configuration;
PriceData.averageSalePriceFDataTable priceTable;
DALib.PriceDataTableAdapters.averageSalePriceFTableAdapter priceAdapter
= new DALib.PriceDataTableAdapters.averageSalePriceFTableAdapter();
priceAdapter.Connection.ConnectionString
= WebConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;
priceTable = priceAdapter.GetData( ... parameters ...);
This uses the connection string in the class library for design and picks it from Web.config when running.
Hope I understood your problem correctly, let me know.
I'm trying to integrate Magento 1.7 with a C# application.
When I tried to use the "Add Service Reference" function in Visual Studio, it finds the service and all the operations but when I click OK, it doesn't generate anything. i.e. the Reference.cs file is almost empty (only has one line with namespace).
I tried using wsdl.exe to generate the proxy in command prompt and I got the following error:
R2718: A wsdl:binding in a DESCRIPTION MUST have the same set of wsdl:operations as the wsdl:portType to which it refers.
- Operation 'catalogProductAttributeRemove' on portType 'Mage_Api_Model_Server_Wsi_HandlerPortType' from namespace 'urn:Magento' has no matching binding.
For more details on the WS-I Basic Profile v1.1, see the specification
at http://www.ws-i.org/Profiles/BasicProfile-1.1.html.
Error: Unable to import binding 'Mage_Api_Model_Server_Wsi_HandlerBinding' from namespace 'urn:Magento'.
- The operation 'catalogProductAttributeRemove' on portType 'Mage_Api_Model_Server_Wsi_HandlerPortType' from namespace 'urn:Magento' had the following syntax
error: The operation has no matching binding. Check if the operation, input and output names in the Binding section match with the corresponding names in the PortType section.
I then tried using Soap UI to load the same wsdl and it works fine. The proxy was generated and I can make calls without any problems.
The original wsdl file is here: https://gist.github.com/4514723
except I have replaced line 6297 with an example url.
So my questsion is why was Soap UI able to generate the proxies and making calls without any problems but Visual Studio can't? How can I fix it?
See Generate a Web Service Client in WS-I compliance mode .
You will need to modify your Magento code to correct the WS-I compliant WSDL definition in app\code\core\Mage\Catalog\etc\wsi.xml.
The SOAP UI is probably more tolerant of mistakes in WSDLs compared to other .NET/Java tooling.
I have a unit test that behaves differently depending on parameters passed. Does VS 2010 MS Testing framework have a facility to call the same test with different parameters.
I am looking for something like this:
[TestRun(False)]
[TestRun(True)]
[TestMethod]
public void FooTest(bool a)
{
RunTest(a);
}
I have no idea why Micosoft's decided not to include this feature in their unit testing framework, whenever I search for it I find reference to the DataSource attribute that enable loading data from external resource (XML file, data base etc.)
If you do not want to use and external data source then you have two choices:
Add RowTest support using MSTest extensability framework - explained here
I wrote in my blog how to use PostSharp to create the external data source from the test attributes.
If you're already using VS2010 I suggest you go with the first option - there is even a full working code at Microsoft's code gallery.
The following page tells how to achieve the same with MSTest data-driven testing capabilities: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.dataaccessmethod.aspx
I have a weird visual studio error which is bugging me.
I am using Visual Studio 2010
My solution is small and contains 2 projects:
Project 1 a class library contains the following classes:
Namespace1.DataClass (a serializable class to hold data)
Namespace2.AccessorClass (a class with a method to pull instances of Namespace1.DataClass from a database via Linq to Sql)
Project 2, a console application contains the following classes:
Namespace3.Program (with main function which pulls data from the database and sends it via a wcf service)
Namespace4.WCFProxy (a wcf proxy generated by svcutil)
The WCF client sends objects to the service in the form of:
[System.Runtime.Serialization.KnownTypeAttribute(typeof(Namespace1.DataClass))]
public class SendItem
{
public object Item { get; set; }
public string Label { get; set; }
}
(This is generated by svcutil, so I am paraphrsing to save space)
So, within my proxy class there is a reference to Namespace1.DataClass.
When building my application I first created the project to access the database, I then created my console app, I added a reference from my console app to my my class library and finally I generated my proxy and added it (un-edited) to the console app project.
Everything looks fine, no VS compile errors BEFORE building.
Then, when I build, VS seems to forget the reference from my console app project to my class library project and I get a heap of compile errors accordingly.
If I exclude my proxy class from the project, VS can see the reference again. If I re-add the proxy everything is still fine (no errors and full intellisense support) but click build and everything goes haywire again.
Has anyone come across this issue before?
Cheers
Shane
It was log4net, beware of this behavior in future.
Just to clarify, this problem had nothing to do with WCF as I though it did.