Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Accessing resources from non-DNX assembly Cause Exception System.IO.FileNotFoundException

$
0
0

Beta 8 load resource assembly cause exception System.IO.FileNotFoundException. The resource assembly is defined in legacy .NET class library, not DNX class library. The same solution works for Beta 7 but fails when using Beta 8.
Beta 8 Solution
https://github.com/luchen1021/AspNet5Beta8Resource.git
https://github.com/luchen1021/AspNet5Beta8Resource
Beta 7 Solution
https://github.com/luchen1021/AspNet5Beta7Resource.git
https://github.com/luchen1021/AspNet5Beta7Resource

Change project reference to binary reference for Legacy Library and Legacy Resource Library.
https://github.com/luchen1021/AspNet5Beta8ResourceBinaryReference.git
https://github.com/luchen1021/AspNet5Beta8ResourceBinaryReference
Running in Visual Studio 2015 with IISExpress still get the same exception as shown in top comment.
Publish works fine in binary reference approach. After deploying the published output to IIS (not IIS express), it works fine without any exception.

Based on sample code https://github.com/aspnet/dnx/blob/dev/misc/ResourcesTestProjects/ReadFromResources/src/ReadFromResources/Program.cs, I have to change the following line of code in generated Resources.Designer.cs by Visual Studio
From
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AspNet5Beta8LegacyLibrary.LegacyLibrary.Ext.Properties.Resources", typeof(Resources).Assembly);
To
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AspNet5Beta8LegacyLibrary.LegacyLibrary.Ext.Properties.Resources", System.Reflection.Assembly.Load(typeof(Resources).Assembly.GetName()));

Even the System.Reflection.Assembly.Load(typeof(Resources).FullName) does not work, has to be System.Reflection.Assembly.Load(typeof(Resources).Assembly.GetName()).
Is this by design? If so, how do we work around the issue with existing satallite resource assembly, which always use typeof(Resources).Assembly instead of System.Reflection.Assembly.Load(typeof(Resources).Assembly.GetName())?

Exception Detail:
System.IO.FileNotFoundException: {"Could not find file 'AspNet5Beta8Resource.LegacyResources.resources'.":null}
Data: {System.Collections.ListDictionaryInternal}
FileName: null
FusionLog: null
HResult: -2147024894
HelpLink: null
IPForWatsonBuckets: {1858045768}
InnerException: null
IsTransient: false
Message: "Could not find file 'AspNet5Beta8Resource.LegacyResources.resources'."
RemoteStackTrace: null
Source: "mscorlib"
StackTrace: " at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
at AspNet5Beta8Resource.LegacyResources.Properties.Resources.get_Title() in D:\Project\GitHub\AspNe
t5Beta8Resource\AspNet5Beta8Resource.LegacyResources\Properties\Resources.Designer.cs:line 68
at AspNet5Beta8Resource.LegacyLibrary.LegacyClass.GetTitle() in D:\Project\GitHub\AspNet5Beta8Resource\AspNet5Beta8Resource.LegacyLibrary\LegacyClass.cs:line 14
at AspNet5Beta8Resource.DnxWebHost.Controllers.ValuesController.Get() in D:\Project\GitHub\AspNet5Beta8Resource\AspNet5Beta8Resource.DnxWebHost\Controllers\ValuesController.cs:line 21"
TargetSite: {System.Reflection.RuntimeAssembly InternalGetSatelliteAssembly(System.String, System.Globalization.CultureInfo, System.Version, Boolean, System.Threading.StackCrawlMark ByRef)}
WatsonBuckets: null
_HResult: -2147024894
_className: null
_data: {System.Collections.ListDictionaryInternal}
_dynamicMethods: null
_exceptionMethod: {System.Reflection.RuntimeAssembly InternalGetSatelliteAssembly(System.String, System.Globalization.CultureInfo, System.Version, Boolean, System.Threading.StackCrawlMark ByRef)}
_exceptionMethodString: null
_fileName: null
_fusionLog: null
_helpURL: null
_innerException: null
_ipForWatsonBuckets: {1858045768}
_maybeFullPath: null
_message: "Could not find file 'AspNet5Beta8Resource.LegacyResources.resources'."
_remoteStackIndex: 0
_remoteStackTraceString: null
_safeSerializationManager: {System.Runtime.Serialization.SafeSerializationManager}
_source: "mscorlib"
_stackTrace: {sbyte[192]}
_stackTraceString: null
_watsonBuckets: null
_xcode: -532462766

_xptrs: {0}


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>