Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7192261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:54:16+00:00 2026-05-28T19:54:16+00:00

I have some code in a common library to support internationalization. The basic idea

  • 0

I have some code in a common library to support internationalization. The basic idea is that given the fully qualified name of a RESX file location, you can look up values using a markup extension:

    resx:ResxProperty.Name="SampleApp.Common.Resources.MainWindow"
    Title="{Resx Key=Window.Title}" 
    Icon="{Resx Key=Window.Icon}"

To find the RESX file there is a routine to search all assemblies as shown below, and it works fine when the RESX file is in the same assembly as the xaml. BUT it breaks down when it is not.

Consider the solution structure below, where SampleApp.Wpf has the calling XAML and has a dependency on both the LocalizationLib and SampleApp.Common.

enter image description here

AppDomain.CurrentDomain.GetAssemblies() does not have SampleApp.Common at run time (although it does at design time).

How can I modify this code so it will know about SampleApp.Common at runtime?

Cheers,
Berryl

Library code

/// <summary>
/// Find the assembly that contains the type
/// </summary>
/// <returns>The assembly if loaded (otherwise null)</returns>
public static Assembly FindResourceAssembly(string resxName)
{
    // check the entry assembly first - this will short circuit a lot of searching
    //
    var assembly = Assembly.GetEntryAssembly();
    if (assembly != null && HasSpecifiedResx(assembly, resxName))
        return assembly;

    var assemblies = AppDomain.CurrentDomain.GetAssemblies();
    foreach (var searchAssembly in assemblies)
    {
        // skip system assemblies
        var name = searchAssembly.FullName;
        if (_isSystemAssembly(name)) continue;

        if (HasSpecifiedResx(searchAssembly, resxName))
            return searchAssembly;
    }
    return null;
}

UPDATE

More details.

SampleApp.Wpf is targeting .net 4.0. Below are the references for it as displayed in Visual Studio.

enter image description here

The only project references in there are Infralution.Localization.Wpf and SampleApp.Common, both of which also target .Net 4.0.

Based on Metro Smurf’s input I tried using assembly.GetReferencedAssemblies(). When I use this method, the VS designer does NOT find SampleApp.Common, and the following AssemblyNames are known in the debugger at runtime:

{System.Reflection.AssemblyName[6]}
    [0]: {PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35}
    [1]: {mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [2]: {System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [3]: {Infralution.Localization.Wpf, Version=2.1.2.0, Culture=neutral, PublicKeyToken=547ccae517a004b5}
    [4]: {System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [5]: {PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35}

And when I use the origional AppDomain.CurrentDomain.GetAssemblies(), the designer DOES know SampleApp.Common, and these assemblies are known at runtime:

?AppDomain.CurrentDomain.GetAssemblies()
{System.Reflection.RuntimeAssembly[21]}
    [0]: {mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [1]: {Microsoft.VisualStudio.HostingProcess.Utilities, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a}
    [2]: {System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [3]: {System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a}
    [4]: {System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [5]: {Microsoft.VisualStudio.HostingProcess.Utilities.Sync, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a}
    [6]: {Microsoft.VisualStudio.Debugger.Runtime, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a}
    [7]: {vshost32, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a}
    [8]: {System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [9]: {System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [10]: {System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [11]: {Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a}
    [12]: {System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [13]: {System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [14]: {System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
    [15]: {WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35}
    [16]: {PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35}
    [17]: {PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35}
    [18]: {SampleApp.Wpf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
    [19]: {System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a}
    [20]: {Infralution.Localization.Wpf, Version=2.1.2.0, Culture=neutral, PublicKeyToken=547ccae517a004b5}

In both cases, SampleApp.Common isn’t known at runtime. For the fun of it, I loaded that assembly in the debugger and got:

?Assembly.Load("SampleApp.Common")
{SampleApp.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
    [System.Reflection.RuntimeAssembly]: {SampleApp.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
    CodeBase: "file:///C:/.../SampleApp.Wpf/bin/Release/SampleApp.Common.DLL"
    EntryPoint: null
    EscapedCodeBase: "file:///C:.../SampleApp.Wpf/bin/Release/SampleApp.Common.DLL"
    Evidence: {System.Security.Policy.Evidence}
    FullName: "SampleApp.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
    GlobalAssemblyCache: false
    HostContext: 0
    ImageRuntimeVersion: "v4.0.30319"
    IsDynamic: false
    IsFullyTrusted: true
    Location: "C:\\...\\SampleApp.Wpf\\bin\\Release\\SampleApp.Common.dll"
    ManifestModule: {SampleApp.Common.dll}
    PermissionSet: {<PermissionSet class="System.Security.PermissionSet"
version="1"
Unrestricted="true"/>
}
    ReflectionOnly: false
    SecurityRuleSet: Level2

I also tried Metro Smurf’s suggestion to reference a static string from SampleApp.Common in SampleApp.Wpf. No change on that one, although I guess it further proves that SampleApp.Common is properly referenced.

Other things to try on SampleApp.Common might include adding an EntryPoint, a SNK, or a HashAlgorithm.

the FIX

asm.GetReferencedAssemblies sounds like the ticket, but it only returns assemblies which are loaded in the memory, and assemblies aren’t loaded if they aren’t referenced in the code (as in it’s confusing that while also quite proper to say one project has a reference to another, but that isn’t the sort of reference this method returns).

It turns out that AppDomain.CurrentDomain.GetAssemblies() works the same way.

Metro Smurf was on the right track, but apparently a static reference won’t get the assembly loaded, but creating a type instance from the assembly will. So:

Console.WriteLine(Class1.MyDummyString)  // this won't do it
Console.WriteLine(new Class1())  // finally, the assembly is loaded

As much as I dislike creating a dummy class, in this case it is an easy fix; I can leave the original library code as is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:54:17+00:00Added an answer on May 28, 2026 at 7:54 pm

    You may want to consider using the Assembly.GetReferencedAssemblies Method. However, if I’m not mistaken, you’ll need to exclude the framework assemblies as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code in a javascript file that needs to send queries back
I have some code that gives a user id to a utility that then
I have three web application projects that share a common library of custom server
I have written a static library to re-use some code between iOS projects, let's
I have a common library where I've put classes that are used between multiple
We have a macro for signalling errors in a common utilities library that goes
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
I have some code like this in a winforms app I was writing to
I have some code which collects points (consed integers) from a loop which looks
I have some code like this: If key.Equals(search, StringComparison.OrdinalIgnoreCase) Then DoSomething() End If I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.