I've split out my domain services into a separate WCF RIA Services Class Library project. However there now seems to be a problem with using the resource strings in the client side library.
e.g.
The client project library has generated code like this:
[DataMember()]
[Display(Description="FullNameDescription", Name="FullNameLabel", Order=-1, ResourceType=typeof(MetadataStrings))]
[StringLength(255, ErrorMessageResourceName="BadFullNameLength", ErrorMessageResourceType=typeof(MetadataStrings))]
public string FullName
{
// ...
}
where MetadataStrings is a resource file in the class library. This class library is then referenced by the silverlight project.
But the meta attributes that use ResourceType cause the designer to throw an exception when opening a view and at runtime cause a MissingManifestResourceException.
If I comment out the attributes and rebuild it all works fine. So something is not right with the resources being in another assembly i'm guessing?
Edit: Nevermind finally got this working, problem was that i renamed my class library projects and the namespace of the resource file was wrong. 3 days wasted.
Related
I have a Silverlight web project where I apply the MVVM pattern. In my entire solution I have 4 projects.
Project "A3", which contains all of my Views and ViewModels.
Project "A3.Web", which contains my main html files, images, sound files, etc.
Project "A3Lib", which contains my XAML binding converters and other helpful classes that I created.
Project "A3Lib.Web", which contains the Data Models and Domain Logic.
All of my entity models are inside my DataModels folder and all of my Domain Service server side code is inside the DomainLogic folder. I created a new folder inside the DataModels folder named "Common".
So when I want to add the data model to my VM, I tried "using A3Lib.Web.DataModels.Common;" and that did not find the namespace.
Issue: when I add a new folder and a new entity model to the DataModels folder, I do not see the namespace in my View or ViewModel in the "A3" project.
However, I already have existing code there (was added by someone else) and the models he added show perfectly fine (when doing using ...... in the View or VM).
I checked web.config to make sure the connection string is there and it's correct. I also tried to add a brand new context to the base class of the project (where other contexts are) and that did not help. My project simply cannot resolve or see the data model namespace that I create.
Thanks
Yura
The Silverlight app sees the models and namespaces from the server-side project through the generated code - you should see it in the Generated_Code folder of your A3Lib project. If it is not there, then the proxy classes are not being generated on build. A couple things to check:
class is not private (hey - sometimes it's the simple things)
if using Domain Services, the service needs to have at least 1 method that returns an IQueryable or IEnumerable (even if method returns null) in order to see the class in the Silverlight-side domaincontext
if the class is just a utility class that you want to share with the client, save the file as classname.shared.cs, and the proxy will pick it up.
make sure the project references are to the projects and not (possibly older) .dlls in another location.
That's all I've got based on the info provided.
I have a Solution with different Projects:
A Silverlight Class Library:
- In this I have a "Link" to the CS File with Attribute wich is used on a DTO
- In this Class there is also a modified Datagrid wich uses the Attribute
A RIA Class Library:
- It has a Link to a web project, and loads my DTO class
- It also has a Reference to the class Library defined before!
A Silverlight Project:
- This is my runtime and loads dynamicly the RIA Project.
Now to the Problem:
The DTO in the RIA Project does not have the Attribute defined on the real DTO! When I move the Attribute to the RIA-Class-Library, it works, but this is not possible, because then I have no access to the attribute from my normal Class Library!
when I did this bevore, using a normal RIA-Project instead of RIA-ClasLibrary, there it worked. It did find the types from the Referenced DLLs.
But now I need the other aproach.
Anyone can help?
Ah, the error code is: The attribute '...' is not visible in the client project '...'
I got it now! Seams like i referenced two Versions of Microsoft.Iteractivity, and this broke Ria from finding the Attributes
I am building an Asp Net website in Visual Studio that uses Razor developed HTML pages. I would like to be able to use some C# from the javascript on one of the web pages (this is not creating a plugin that would be displayed in the browser.) I have tried to create a simple Cs class that has a single method that returns a fixed string to test this. The following code is in the ManagedCsClass.cs file is in the App_Code folder in my project.
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public class ManagedCsClass
{
public ManagedCsClass()
{
//
// TODO: Add constructor logic here
//
}
public string ReturnText()
{
return "Text from ManagedCsClass";
}
}
What I am not clear on is where to create the object that would be used by the HTML page (in the same .cs file as the class, another .cs file, or from a call from the HTML browser page).
And what code do I need to use in the javascript to reference the object/method?
Thanks for any help or guidance you can provide.
Mark
You are trying to use "ActiveX" com objects, this requires the dll containing that class registered on the client and you will have a lot of security/deploy issues ( the client must trust your object and have the framework installed ). It is not the best way to create a web app today.
I was using a simple WCF service with silverlight but I wanted to validate data with annotations and I didn't want to write a whole new layer in silverlight project. So I decided to switch to using a DomainService, created through generating code in the silverlight project.
Now comes the trouble. I have a parent class and about 10 derived classes. Through WCF, I was able to just use the base class. Now I am trying to use a DomainService with the base class decorated with the KnownType attribute. The problem is now those attributes get replicated in silverlight client and a compilation error is thrown. Anybody know how to use DomainService with inheritance? I want to deliver only the information from the base class.
I don't completely follow what your problem is, but this is a great tutorial on how to use Domain Services in Silverlight, and the example includes an abstract base class for all entities, similar to what I think you're doing.
I have the following Ria Service define:
namespace SilverlightTest.Web
{
[EnableClientAccess()]
public class ContactService : LinqToEntitiesDomainService<AdventureWorksEntities>
{
public IQueryable<Contact> GetContactSearch(string lastName)
{
ContactRepository rep = new ContactRepository();
return rep.SearchByLastName(lastName);
}
}
}
When I compile the solution, my SilverlightTest project does create the SilverlightTest.Web.g.cs file and the appropriate Context objects are created when I look at it. However, when I attempt to import the SilverlightTest.Web namespace to access the Data Context class for the above service, it says it cannot find the Web namespace.
The only difference I can see between what I'm doing and many examples that are out there on the web is that my AdventureWorksEntities data context is located in a separate business object dll. I tried to query the context directly instead of using the Repository Pattern I'm attempting to do and it also isn't work working.
Any ideas? Is it possible to have Ria Services access a separate DLL handling data access or does it HAVE to be in the same project?
I've been able to put the Ria service in a separate project before, although I do remember having issues. Not sure exactly what it was, but I would check two things: your references and your web.config (in the hosting website). When you add a ria service to a web project it does some things behind the scenes that wire everything up correctly.
Could try adding a service to your web project temporarily and see what it adds.
It seems that Resharper does not recognize the .gs files and their name spaces. If you disable R# or just code without intelisense it works.