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.
Related
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.
I've a C# solution that consists of an MVC project and a Windows Application project. Is there any way for MVC to call a Windows Application method and pass values to it?
I added Windows Application to References in the MVC project. But when adding the namespace reference using Windows Application name in the MVC class, it can't be found.
I appreciate any pointers.
Check that classes are public (else you can't call methods from the class) and that you have added reference to the project in your solution.
Take the code that's shared between the two, add a class library, and place it in there. That's what they are for. Past this, referencing a Windows application (.exe) is sure to be an issue even further down the road.
Hi I would like to use the same class library from my Silverlight application and WCF based service. I created a Silverlight C# class library and found the WCF service does not allow adding reference to Silverlight Project types. So
What should i do to make this work?
Can Silverlight invoke methods on Silverlight Class library if it communicates with WCF service?
Is silverlight always this hard?
Portable Class Library
http://msdn.microsoft.com/en-us/library/gg597391.aspx
Try making 2 class libraries, one for Silverlight and one for WCF. Both use the same C# source code files. In the second project, you can add the files as link (In Visual Studio in solution explorer: add existing item, and then in the drop-down Add button, choose "Add as link".
That's how we solved it for shared code. You have to limit yourself to library calls that exist in both worlds though.
Now it is easy :D - just use the .shared trick. It allows you to share the same code between server and client. Look here: http://msdn.microsoft.com/en-us/library/ee707371(v=vs.91).aspx
PS.: You can even add conditional directives on your .shared classes, like this:
#if SILVERLIGHT
MessageBox.Show("yay, I will run only on silverlight");
#endif
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
I'm trying to reference my domain service by following this documentation.
The following two declarations work fine
xmlns:riaControls = "clr-namespace:System.Windows.Controls;
assembly=System.Windows.Controls.DomainServices"
and
xmlns:data = "clr-namespace:System.Windows.Controls;
assembly=System.Windows.Controls.Data"
but I'm having problems with this one
xmlns:domain="clr-namespace:SNMPApplication.Web"
This error appears, even after I rebuild the whole solution:
Undefined CLR namespace. The
'clr-namespace' URI refers to a
namespace that is not included in the
assembly.
I've tried adding a reference to my Silverlight project but I get this error
You can only add project references to
other Silverlight projects in the
solution.
Does anyone have an ideia of what the problem is? :/
Thank you so much in advance.
The way you add a reference to a RIA DomainService is not through the traditional Add Reference dialog. You do it through the project settings. In the Silverlight Application, goto the project settings, specifically the 'Silverlight' tab. On that tab will be a 'WCF RIA Services link'. You'll be able to select your project that contains the DomainService.
After you select the project, Visual Studio will generate code for your Silverlight application. This is found in a Generated_Code folder (which isn't visible in the project, though you can see it in the folder). This is where your code that you need to reference will be.
If you genuinely need to access the Web project from your SNMPApplication project, then I think what you'll need is either of the answers to this question: How to access web application class into silverlight application
You are not actually creating a reference to your web project when you do this, it resolves it at compiletime to create the generated g.cs files (I suspect), This is one of those magic things that does stuff in the background ( I think it stores it in your project file and you set it in the project properties --> silverlight tab under WCF Ria Services link).
Please check the following:
Your SNMPApplication.Web is in the same solution as your Silverlight project (SNMPApplication)
and that your reference is the same as your DomainService class namespace you added to your web.Project class (It might be in a sub folder and that is why it's not working,
If you haven't created a domain service please add one as this is what silverlight and ria services uses to connect between your entity model and silverlight. (Have a look here from Adding a DomainService class
xmlns:domain="clr-namespace:SNMPApplication.Web"