Currently we are trying to localise our rather extensive module, and what use a single resx (for ease of management), WE have written the following code which does return keys however it does leave us with a log message in the event viewer (below the code)
I should also add I cannot use httpcontext.current.server.mappath, as the functions are also used where there is not a httpcontext
Code:
Public Shared Function GetString(ByVal key As String, ByVal ParamArray params As String()) As String
Dim SharedResourceFolder As String = "~/App_GlobalResources/"
Dim myStr As String = Nothing
If CultureInfo.CurrentCulture.Name <> "en-GB" Then
myStr = Localization.GetString(key, SharedResourceFolder & "Resources." & CultureInfo.CurrentCulture.Name & ".resx")
If myStr Is Nothing OrElse myStr = "" Then
myStr = Localization.GetString(key, SharedResourceFolder & "Resources." & CultureInfo.CurrentCulture.Name.Substring(0, 2) & ".resx")
End If
End If
If myStr Is Nothing OrElse myStr = "" Then
myStr = Localization.GetString(key, SharedResourceFolder & "Resources.resx")
End If
If myStr IsNot Nothing AndAlso myStr <> "" Then
Return String.Format(CultureInfo.CurrentCulture, myStr, params)
End If
Dim res As String = Localization.GetString(key, "Resources.resx", "en-GB")
If String.IsNullOrEmpty(res) Then
Return Nothing
End If
Return String.Format(CultureInfo.InvariantCulture, res, params)
End Function
Error Message:
System.ArgumentException: The relative virtual path 'sharedresources.resx' is not allowed here. at System.Web.VirtualPath.FailIfRelativePath() at System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) at System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath) at System.Web.Hosting.HostingEnvironment.MapPath(VirtualPath virtualPath) at System.Web.Hosting.HostingEnvironment.MapPath(String virtualPath) at DotNetNuke.Services.Localization.Localization.GetResourceFileCallBack(CacheItemArgs cacheItemArgs) at DotNetNuke.Common.Utilities.DataCache.GetCachedData[TObject](CacheItemArgs cacheItemArgs, CacheItemExpiredCallback cacheItemExpired, Boolean storeInDictionary)
Thankful for any help
UPDATE:
Changing to a physical path caused me an issue within the DNN core, reverting back to a virtual path and changing a line of code else where in the module Fixed the issue
My guess here is that you are using a root relative path, which since you are outside of an HTTP Context the system is failing. This is based on the stack trace provided and the call to "FailIfRelativePath()" method.
If you look at the DotNetNuke code for Localization.GetString, typically it is provided a physical file path and not a relative path. To confirm this look at the LocalResourceFile property that is available on any module control that inherits from PortalModuleBase.