.net Reference Web in class library - c#

I am writing an n-layer app/site and in my Common class library I need to call on NetSqlAzMan Web reference but that cannot be imported into a class library, only into a website type project.
One way to get around it is to make my Common layer a site but that just doesn't seem right.
How to properly implement that?
I am using VS2010 Pro

Sounds like the project type of your class library is Client Profile instead of a normal one.
Client profile class libraries are not allowed to reference System.Web
If you change the target platform to ".NET Framework 4" you should be able to reference System.Web

Related

How to create object of class from client project

When we create a Silverlight application, which includes two projects. The Silverlight project and the web project. I have a class in my SilverlightApplication1.Web namespace and I am trying to create an object of that class in my MainPage.xaml.cs class which is present in SilverlightApplication1 namespace.
But seems like I can't create an object of the web project from the Silverlight project. How can I do this? What's the concept?
When I create object I get error:
The type or namespace could not be found
It sounds like your Silverlight project doesn't have a reference to the web project. That's probably a good thing, mind you - I would suggest you set up a third project (as a Silverlight class library) called "Common" or something similar, and make both the web project and the Silverlight project refer to that. Put types which aren't web-specific or Silverlight-specific in that project, and then you can use them from both the web and Silverlight projects.

XNA not recognizing new class

So XNA 4.0 is being a pain in the butt and selectively not recognizing classes.
I have two projects in my solution, 2DRPGLibrary and Avalon. A class in Avalon, named GamePlayScreen, is trying to reference 2 classes in 2DRGLibrary: World and WorldBuilder.
However, WorldBuilder gives me the annoying "Type or namespace X could not be found" error. I've included a reference to 2DRPGLibrary in Avalon, and World doesn't produce an error. It's only tripping over WorldBuilder.
Help?
EDIT: The only thing that seems relevant is that the 2DRPGLibrary has a Client target class when it should be v4.0 instead. There doesn't seem to be a way to fix this, though, because it doesn't have a .csproj file like Avalon...thoughts?
In my opinion, the reason could be that the implementation of WorldBuilder is using some classes or libraries that Avalon project doesn't have reference to. And these classes or libraries are not registered on the GAC (Global Assembly Cache).
For example: 2DRGLibrary has reference to library A contained in the A.dll file under that project, WorldBuilding uses some classes of A library for its implementation while World doesn't use any. Then Avalon has reference to 2DRGLibrary and use WorldBuilding but doesn't have a reference to library A.
Just check your referencing on both projects to make sure that the above situation is not present then you should be ok.

How can I dynamically load classes from another project within Visual Studio 2012?

I'm developing a WCF service that uses an interface (not the ServiceContract interface) to perform some internal work. My goal is to extend the functionality of this service after deployment by delivering New DLLs with classes that implement this interface (and corresponding web.config updates).
I'm starting with just one class that implements the interface. In my solution, I have the Service in one project (WCF Service Application) with the interface definition, and the class that implements the interface in another project (Windows Class Library).
I am using the following code to dynamically load the class (based on a parameter passed when the service is called):
InterfaceFoo af = (InterfaceFoo)System.Activator.CreateInstance(AssemblyQualifiedName, ClassType).Unwrap();
When this line is called, I get a FileNotFoundException, Could not load file or assembly.
I believe the above code is correct, as I have it working at runtime from a separate proof of concept project once it's built and deployed, and the DLL is placed in the same folder as the EXE. I believe my problem is related to how I've referenced the projects, or the variables I'm passing to the CreateInstance() method when run within Visual Studio.
What I've tried and I still get the same error: In the WCF Service Project I've set the Class Library project as a reference. In the WCF Service Project I've added a link to the interface implementing class.
I'm wondering if the values I'm using for AssemblyQualifiedName and ClassType won't work within Visual Studio since they aren't yet deployed?
Any advice is appreciated, even if you think a completely different approach is better.
ADDED AFTER INITIAL POST:
I had an idea after posting, I moved the interface implementing class from the Class Library Project to the WCF Service Project. When I do this, it works. That to me eliminates the assembly and type parameters as issues, and the issue is that I'm not linking correctly to the Class Library Project.
You can move your interface defenition to another shared library (dll) and then use it.

How to call a class from a project to another project without call the DLL as reference in C#?

I have three parts of a project, one is Core(bussiness) project, one is webproject and the last is the test project.
I want to call some classes that I saved in one folder from core project to webproject without calling the dll of the core project. Since core project is already refereed into the webproject. So it will call the cycling if the references and not allow me to do that.
How I can use classes from core project to web project without call the DLL?
I Have already tried 'using', The code is following. It's not working for me.
using BlogEngine.Core.API.PageML; // I need to call all classes from this folder
using BlogPage = BlogEngine.Core.API.PageML;
namespace admin.Settings
{
public partial class DownloadInsertPage : System.Web.UI.Page{
protected void BtnPageMLInsertClick(object sender, EventArgs e)
{
var reader = new PageReaders(); // the class, I want to call from the core project
}
}
Thanks
Your question is unclear ("since web project is already refereed into the webproject" for example) but you should really make the web project have a reference to the core project, but not the other way round. The core business logic shouldn't know about your web "view" onto it, but the web project should absolutely know about the core business classes.
If you have classes in the web project which you're currently referring to from the core project, you should probably move them to the core project - or to a third project which both of the other projects refer to, if they don't logically belong in the core project itself.
Your model may benefit from contract interfaces - that would help you redesign your current model in order to avoid circular references. Here's some posts about this:
a design to avoid circular reference in this scenario
Resolving Circular References (C#)
Now, I may have misunderstood your question, and you'd rather benefit more from learning about add-on models. In that case, this post may be of some help:
C# Plugin Architecture with interfaces share between plugins
You cannot.
If you need these classes to be accessible in both assembly, you should create a third one that would be referenced by both of them although this should be reserved to cross-cutting concerns only (e.g. logging logic).
Thank you guys for your valuable comments..
I want to share, what was the problem and how I resolved it.
I build the core project after created some classes into the PageML folder and build it without calling this folder into the web project. and update the reference(dll) of core project in the webproject. and it's working for me.
Thank you All
Keep clam and do coding.
:) have a nice time

MvvmCross Portable Class Library - System.Net.ServicePointManager

In my PCL I am trying to call to an SSL service so I am trying to set ServerCertificateValidationCallback like so:
System.Net.ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertficate;
but it seems I can't add a reference to System.Net in my PCL and it says the type ServicePointManager does not exist.
How do I reference this in my PCL?
You can't reference this in your pcl - it isn't defined in any current portable subset.
If you need to use it, you can reference it in some of your Ui projects - eg in your setup class - or for reuse you can build a plugin to reference it for some platforms. However there are some modern platforms which simply don't support it - WindowsPhone (and perhaps windows store too?)
For more on injecting platform specific code into pcl core libraries, see http://slodge.blogspot.co.uk/2013/06/n31-injection-platform-specific.html

Categories