I have produced a custom class serializer for a sole class contained in 'VcdcClassStructure.dll' using sgen as-per the documentation. The documents now state that all I need to do is
Add assembaly references to both 'VcdcClassStructure.dll' and the sgen-generated 'VcdcClassStructure.XmlSerializers.dll'.
Add references to the namespace that contains the newly generated serialization classes via
using VcdcClassStructure;
using Microsoft.Xml.Serialization.GeneratedAssembly;`
(I have confirmed that the namespaces are correct using DotPeek).
I have then changed my code from
XmlSerializer serializer = new XmlSerializer(typeof(message));
serializer.Serialize(writer, vcdMsg);
to
messageSerializer serializer = new messageSerializer();
serializer.Serialize(writer, vcdMsg);
but on compilation I am getting
The type or namespace name 'VcdcClassStructure' could not be found (are you missing a using directive or an assembly reference?)
and
The type or namespace name 'Xml' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
I have reference the relevant assemblies and added the using code for the namespace. Why is the compiler complaining about these references?
Thanks for your time.
Edit. To prove that I have not missed any of the steps above.
I've checked, and the process described works correctly. I would have to assume, therefore, that you've made an error in the steps. It works fine (note: the type I created in the library was SomeType, hence the names):
You might want to try going through the steps again.
Related
I have a puzzling issue with Visual Studio 2017 and C#. The editor thinks one of my base classes does not exist. It keeps giving me a red-squiggly line underneath it with the message that the class cannot be found. I inherit from this class in two places and get the same red squiggly line.
But what is odd is that:
My application runs perfectly.
I can debug it and step into the derived and base class code with no problems.
I can still right-click on the class name and go to definition and it goes to the right place.
Both the base class and the derived class are in exactly the same namespace in the same assembly. Their source files are in exactly the same folder and both are public classes.
I do not have this problem with any other class in my solution (which is large)
Here is one example of the inhertance that's giving me the red squiggly line
using System.Collections.Generic;
using Trainer.Core.Interfaces;
using Trainer.Core.ViewModels;
using Trainer.Model;
using Trainer.Sdk;
namespace Trainer.Capture.ViewModels
{
public class CalibrationJob : JobVm // <-- RED SQUIGGLY LINE UNDER "JobVm" HERE
{
... etc ...
When I put the mouse cursor over the red-underlined base-class name "JobVm", I get the following error message from Intellisense
"The type or namespace 'JobVm' could not be found (are you missing a
using directive or an assembly reference?)"
Here are the first few lines of JobVm's source file
using System.Threading;
using System.Windows.Input;
using Trainer.Core.Interfaces;
using Trainer.Core.ViewModels;
namespace Trainer.Capture.ViewModels
{
public class JobVm
{
...
So I tried changing the inheritance explicitly specify the full base class name
namespace Trainer.Capture.ViewModels
{
public class CalibrationJob : Trainer.Capture.ViewModels.JobVm
{
... and then the error message became slightly different:
"The type or namespace JobVm does not exist in namespace Trainer.Capture.ViewModels"
But of course it does exist. It's right there in the same assembly and folder.
I've tried to find a way to delete the Visual Studio intellisense cache but I don't have any .SDF files and I don't see anything else. This is a completely C# solution.
I guess I can keep on going as everything works fine but this is bugging me. I'm thinking there must be some other issue.
Any idea what's going on here? Am I missing something obvious?
Even though they use the same namespace, if your objects are in different projects, then you want to make sure any Nuget packages or included assemblies used in each project are running the same version. I have found that if one project is running a different version then you may get the squiggle lines. I have experienced that before.
I have a directory tree as such:
+Enums
|+MyEnums.cs
+Src
+Model
+MyModel.cs
And I would like to use the namespace Enums that I declared in MyEnums.cs in the file MyModel.cs. But I cannot figure out how to do such, because when using the code
using Enums;
I constantly get the error/warning that
The type or namespace name 'Enums' could not be found (are you missing a using directive or an assembly reference?)
If I use it in the same folder I have no issue, but I would like to use it across a larger directory tree.
The directory structure of your project and the structure of the namespaces are technically two unrelated things; nevertheless it makes sense to have them organized in parallel, but still they are orthogonal concepts. You have to define a namespace by putting types into it as follows.
namespace Enums
{
// some definitions
}
namespace Enums.MyEnums
{
// some more definitions
}
After populating the namespace, you can import the namesepace with the using directive.
Adding a file to a directory like that typically gives you a namespace that is the same as the directory name, but that is not necessarily the case (such as when you move a file from one folder to another). The namespace is determined like this in the file. Check what the namespace is and change it to Enums if that's what you want it to be:
using System;
namespace Enums
{
enum Testing
{
Test1,
Test2
}
}
Solution contains 2 projects:
Geo.Data project, which contains CodeRepository class, defined in namespace Geo.Data
ConsoleApp1 project, in which I have Program.cs class, where I want to instantiate CodeRepository from the other project.
So, I add to ConsoleApp1 - project references - the assembly from Geo.Data\Bin\Debug\Geo.Data.dll; I also add a using directive on top of Program.cs: using Geo.Data;
using Geo.Data;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Geo.Data.CodeRepository x = new Geo.Data.CodeRepository();
// here, if I add x. after the dot I can all methods listed (from class CodeRepository)
}
}
}
CodeRepository is coloured accordingly, so it's recognized as being part of Geo.Data
However, I do get an error when running the solution. Just don't see what I am doing wrong:
The type or namespace name 'Geo' could not be found (are you missing a
using directive or an assembly reference?) ConsoleApp1\Program.cs
As described earlier, I have already added both the using Geo.Data and the assembly reference to Geo.Data. Is this a conflict of diff namespaces or what? Thanks.
Also, after writing the first letter "G" in the using directive, it's suggested to me through intellisense to use Geo; so at that point it does find it. Problem is when I run the project. The error points to the using directive. Thanks!
If you want to reference Geo.Data as a library, you need to right-click the project in your solution explorer, select PROPERTIES, and change OUTPUT TYPE to CLASS LIBRARY (note that Geo.Data does NOT need to be a part of your solution if you do this - you would build Geo.Data elsewhere).
Otherwise, if you want Geo.Data to be part of your solution(edit, update, build at the same time), then add your reference by ADD REFERENCE and choosing SHARED PROJECTS from the right-side of the reference window.
I am following the tutorial
http://www.asp.net/mvc/tutorials/older-versions/models-(data)/creating-model-classes-with-linq-to-sql-cs.
I'm getting the following error:
The type or namespace name 'MovieDataContext' could not be found (are you missing a using directive or an assembly reference?)
As the error message says:
(are you missing a using directive or an assembly reference?
So add the correct using clause to bring the namespace into which this class is defined into scope:
using MvcApplication1.Models;
Check this Listing 1 – Controllers\HomeController.cs
using System.Linq;
using System.Web.Mvc;
using MvcApplication1.Models; // you have forgotten to include this
Listing 1 uses a LINQ to SQL DataContext class (the MovieDataContext) to represent the MoviesDB database. The MoveDataContext class was generated by the Visual Studio Object Relational Designer.
If you have done the work of creating the LINQ to SQL Classes then
just include the using statements as in the listing 1
I have a webservice project with a class (let's refer to it as webservice.classA).
I have another class project producing a dll which references that class in its own namespace and instantiates an instance of it (lets call the dlls namespace dllnamespace).
In another project I want to access the member in the dll
e.g.
using webservice;
namespace other_project
{
class B
{
classA copy = null;
//....
dllnamespace.dostuff(); // amongst other things instantiates a classA object
//....
copy = dllnamespace.getclassA(); // method to return classA member
The compiler error I get is cannot convert type from dllnamespace.webservice.classA to other_project.webservice.classA
I guess I have a fundamental design flaw but I figure there must be (?) a way to declare/use "webservice.classA" in more than one namespace.
You have a name clash. The supported way of avoiding this (short of not naming your classes the same), is to define a using alias for one of the classes:
using webservice.classA = myWebserviceClassA;
You are right...the design flaw does exist in terms of naming.
Let us assume:
you have a class named
MyClass
the class exists both in namespace- abc.xyz.qwe.tyu.MyClass
and in namespace - sed.qwe.dfg.ert.MyClass
The workaround is -
using NS1 = abc.xyz.qwe.tyu.MyClass;
using NS2 = sed.qwe.dfg.ert.MyClass;
This way you avoid the clash.
Also, helpful to use if you have very long namespaces.
FURTHER REFERENCE : (From MSDN article on using Directive )
The scope of a using directive is
limited to the file in which it
appears.
Create a using alias to make it easier to qualify an identifier to a
namespace or type.
Create a using directive to use the types in a namespace without having to specify the namespace. A using directive does not give you access to any namespaces that are nested in the namespace you specify.
Change the copy definition line to:
dllnamespace.webservice.classA copy = null;
That's just the problem - you cannot have a class in more than one namespace. This is what namespaces were designed for - to prevent classes with the same name written by different people from aliasing. You'll need to decide for one of your namespaces to own that class and in the other one to import it. Alternatively if the dll and the web service are part of the same distributed app then they should use the same namespace.