I have some test class
using System;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using Praktyka.Models;
namespace PraktykaTest
{
[TestClass]
public class PictureManagerTest
{
[TestMethod]
public void LoadImagesTest()
{
var pic = new PictureManager();
pic.LoadImages(new List<String>
{
"1.jpg",
"2.jpg"
});
// Assert.AreEqual(#"dataImages\1.jpg",pic.Current().UriSource);
Assert.AreEqual("test","test");
}
}
}
I have compile error
The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)
and
Cannot initialize object of type 'List<string>' with a collection initializer
How to add reference for correct working with Lists ?
First, add a reference to the System.Collections.Generic namespace to get the generic List<> class. Then try recompiling.
Related
I have a tough time wording this question but here's my code to start:
namespace UserInterface
{
class UiClass
{
};
}
namespace Project
{
namespace UserInterface
{
}
}
namespace Project
{
UserInterface::UiClass uiClass;
}
So that code won't work because a UserInterface is a global namespace but it's also inside Project so when I instaniate UiClass inside Project it tries to look inside Project->UserInterface instead of just UserInterface. Is there a some way to be specific that I want to use the global UserInterface and not the one inside Project or do I need to change my design?
You can force the name lookup to begin at the global scope using a leading ::.
::UserInterface::UiClass uiClass;
The following code compiles fine and runs as expected:
#include <iostream>
namespace
{
struct Base
{
void print() const { std::cout << "test"; };
};
};
class Derived : public Base
{
};
int main()
{
Derived d;
d.print();
return 0;
}
But when looking at d during runtime using QuickWatch, IntelliSense seems to be unable to find
Base.
I solved this by putting Base in a named namespace instead of an unnamed.
So is it a bug in Visual Studio, or am I missing something out?
This problem with anonymous namepaces has been an issue in VC++ for a while - see http://msdn.microsoft.com/en-us/library/0888kc6a%28VS.80%29.aspx. From the linked doc:
The native C++ expression evaluator does not support anonymous namespaces.
and
The only way to watch the symbol test in this example is to use the decorated name:
e.g. (int*)?test#?A0xccd06570#mars##3HA (using the namespace hierarchy given in the example to illustrate the point). Just use the decorated name? That's so convenient! Thanks, Microsoft.
My problem is as follows:
I got a Microsoft Visual C++ 2008 project and the order to organize all classes in it in nested namespaces. Now I get System::Resources::MissingManifestResourceException on runtime, because the custom System::Windows::Forms has a assembly ressource and with the new namespace, the old Resx-file does not fit anymore. My problem is now, that I have no idea how to reconnect it to the Form-class.
The old code of the Form was like:
namespace OldNamespace{
ref class MainForm : public System::Windows::Forms::Form{
...
};
}
The new code looks like:
namespace NewNamespace{
namespace GUI{
namespace MainWindow{
ref class MainForm : public System::Windows::Forms::Form{
...
};
}
}
}
I tried to adjust the filename of the created resource-file from the resx-file from
$(IntDir)\$(RootNamespace).$(InputName).resources
to
$(IntDir)\NewNamespace.GUI.MainWindow.MainForm.resources
But I am still getting System::Resources::MissingManifestResourceException on runtime.
What is my mistake?
I am writing unit test case for my internal method. I have made necessary changes in AssemblyInfo.cs of my mail class project
[assembly: InternalsVisibleTo("myunitest_assemblyname")]
now i can access my internal method in unit test case method.
but when i compile the code it is giving an error as below
Error 1 'main class project name' does not contain a definition for 'Process' and no extension method 'Process' accepting a first argument of type 'main class project name' could be found (are you missing a using directive or an assembly reference?)
my main class has strong name.
it would be great if some one point where i am missing.
main class structure
namespace Renewals
{
public class StateProcessor
{
internal virtual void PutEmailInQueue(DataTable dataTable)
{
}
}
}
//test class structure
namespace Renewals.Tests.Unit
{
[TestClass]
public class StateProcessorTest
{
[TestMethod]
public void PutEmailInQueueTest()
{
DateTime processingDate = Convert.ToDateTime("27-feb-2013"); ;
StateProcessor stateProcess = new StateProcessor(processingDate);
stateProcess.PutEmailInQueue(new DataTable());
}
}
}
PutEmailInQueue - this method giving me problem.
you wrote that your class use strong name.
I think you have to modify your InternalsVisibleTo() statement with the public key.
e.g.: [assembly: InternalsVisibleTo("friend_signed_B, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e3aedce99b7e10823920206f8e46cd5558b4ec7345bd1a5b201ffe71660625dcb8f9a08687d881c8f65a0dcf042f81475d2e88f3e3e273c8311ee40f952db306c02fbfc5d8bc6ee1e924e6ec8fe8c01932e0648a0d3e5695134af3bb7fab370d3012d083fa6b83179dd3d031053f72fc1f7da8459140b0af5afc4d2804deccb6")]
for more informations see: http://msdn.microsoft.com/en-us/library/bb385180.aspx
I need to make a new object of a cli class in plain C++ code.
I am new to cli, please help
my cli class:
using namespace System;
using namespace System::Windows::Forms;
using namespace CrystalDecisions::Shared;
using namespace CrystalDecisions::CrystalReports::Engine;
using namespace CrystalDecisions::Windows::Forms;
namespace CrystalRapport {
// This is the main form that will hold the viewer control.
ref class ViewForm : public System::Windows::Forms::Form
{
private:
//Declare the Viewer Control, Report Document, and other
//objects needed to set the connection information.
public:
ViewForm()..
void InitForm()..
//This function initializes the form and adds the viewer to the form.
void ViewForm_Load(System::Object^ sender, System::EventArgs^ e)..
};
}
You need to use gcnew if you want to create .NET object in CLI C++.
ref class Student
{
...
};
...
Student^ student = gcnew Student();
student->SelectSubject("Math", 97);
Ref:
http://www.codeproject.com/Articles/17787/C-CLI-in-Action-Instantiating-CLI-classes
I found an example. Use .NET Assemblies in Native C++ Applications
http://msdn.microsoft.com/en-us/vstudio/bb892742.aspx
If you create a C# Crystal Reports project you can use this example.
(with some changes)