Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All,
I am writing a view. I need to include a namespace or reference of COM library namespace.
@model ABCCOM.Documents
this lines gives error and asks me to include library reference. while in my controler or model I am able to use ABCCOM.Documents.
I am not finding any solution. Please Help
Posted

1 solution

The "using" directive does not "include" anything at all. It only introduces default/alias naming for top-level types, nothing else. In other words, you can remove all "using" directives and still be able to access the same very types by writing their full names, that is, then names including namespace names. Please see:
https://msdn.microsoft.com/en-us/library/0d941h9d.aspx[^].

It's important to understand that namespaces have nothing to do with modularity of .NET. The real units of separate compilation in .NET are assemblies and their modules. There are no any rules requiring any correspondence between assemblies and namespaces: any assembly can declare its type in and number of different namespaces, and any namespace can be used in any number of assemblies. Nevertheless, mixing up such different notions as assemblies and namespaces is a usual big mistake in some of the beginners.

To use the assembly in other assembly, you need to reference it. Please see:
https://msdn.microsoft.com/en-us/library/8wxf689z%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/ms973231.aspx[^],
https://msdn.microsoft.com/en-us/library/xwb8f617%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/s1sx4kfb%28v=vs.110%29.aspx[^].

Also, assemblies can be loaded during runtime and used through reflection. But this is another story…

—SA
 
Share this answer
 
Comments
J imran 4-Mar-15 2:06am    
Ok I understand what is namespace and what is assembly. I have an assembly I refered in assembly reference. there is a class in that assembly that I can't access in my view. This is my concern. while in controller I can access my desired object.
Thank you for understanding.
Sergey Alexandrovich Kryukov 4-Mar-15 2:19am    
Than I don't know what else you are missing. You can see the declared class in VS, "(from reflection)" and can show the code trying to use it, and the error message...
—SA
J imran 5-Mar-15 23:07pm    
Actually it is a COM object I am trying to use in view. I am afraid I cann't call the reference directly in view. I have to declare a class with reference of my desired object and redeclare the properties of my desired object to get and set.
this way of indirect access I can use my COM Class object in view.
Very strange to know that cshtml doesn't allow to use everything that is usable in controller class.
Sergey Alexandrovich Kryukov 5-Mar-15 23:28pm    
I know it's COM. .NET referencing of COM component is not that trivial, but this is transparent to you. How did you do the reference. You can reference registered (important!) COM component just by using the "COM" page of the "Add Reference" window. Have you done that?
—SA
J imran 6-Mar-15 7:39am    
I included COM Object from com page of add reference window.
The Classes in the Com Objects are visible in model and Controller classes but they do not appear and not accessible in cshtml views. Hope I have explained it good now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900