Accessing Resources File from a WCF Service

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
8/10/2010 5:19:39 PM
Gravatar
Total Posts 156

Accessing Resources File from a WCF Service

Basically, I have a Resource File in the web application project (foundation.Web.UI) which needs to be accessed by a wcf service class library in a separate project (foundation.Services).  I've done the following:

 1) In Designer.resx.cs file, I specified  foundation.Service assembly as a friend:

 using System.Runtime.CompileServices;
 [assembly: InternalsVisibleTo("foundation.Services")]

 

 2) In the foundation.Services class library project, I added a reference to  foundation.Web.IU

 3) In the class (*.cs) file of the foundation.Service project, I added

 using Resources;

 

 And after having done the above, I was able to access the resource file with all the labels in it.  Is this the recommended approach in your opinion, or am I overkilling this somehow?

8/11/2010 6:46:36 AM
Gravatar
Total Posts 18439

Re: Accessing Resources File from a WCF Service

That approach is ok if you really need to share the resources from another project, I don't think you need step 1.

But also consider that you could add resources to the class library and if the only reason you are referencing the other project is to get to resources, it might be better to just add the needed resources to the class library. Right click the class library project and choose properties, then see the Resources tab.

Best,

Joe

8/11/2010 10:58:25 AM
Gravatar
Total Posts 156

Re: Accessing Resources File from a WCF Service

Yes, I didn't like adding the fact that I had to reference foundation.Web.UI.  If  InternalsVisibleTo  attribute isn't required here, then when would it be?  Did I misunderstand it? http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx

8/12/2010 8:51:42 AM
Gravatar
Total Posts 18439

Re: Accessing Resources File from a WCF Service

After testing this I see it is not possible without your change, but I would not recommend this approach, you should not have to touch designer files they are generated so it is better not to touch them. Possibly the same workaround I mentioned for this thread would make it generate as public, but I would probably just add resources to the project itself even if they duplicate resources from another project rather than reference another project for resources.

8/12/2010 1:04:28 PM
Gravatar
Total Posts 156

Re: Accessing Resources File from a WCF Service

Thank you for taking the time to look into this. 

Yes, I ended adding a resources file to the WCF Service Class Library project itself.

You must sign in to post in the forums. This thread is closed to new posts.