1

Hey, I use the CSharpCodeProvider class to compile c# code into a dll.

That works fine, but only with sourcecode. I would compile into my dll Resources.

I have found the class

CodeCompileUnit codeCompileUnit =
    StronglyTypedResourceBuilder.Create(
       dicResources, "Resources", 
       "Customer.Premium.XmlAppResources.Properties", cSharpCodeProvider,
       true, out errors
    );

this class creates my a perfect c# class that i can compile and i get a wonderfull dll =) BUT :P ...

if i use this dll and i work with the CultureInfo.CurrentCulture i get an error like this :

For the specified culture or the neutral culture resources could not be found. Make sure that Customer.Premium.XmlAppResources.Properties.Resources.resources embedded at compile correctly in the assembly Customer.Premium.XmlAppResources was, or that the required satellite assemblies can be loaded and completely unsigned.

I have no Customer.Premium.XmlAppResources.Properties.Resources.resources in my dll.. and i have no idee where i get this from ...

1
  • I muss create a Resource file in dll dynamic from my c# project, because the user can edit Xml Files and should export this edited files into a dll .. Commented Feb 21, 2011 at 18:33

4 Answers 4

1

If I understand your question correctly: You can do this from the command line using resgen.exe. It will generate a resource file you can use from .Net applications.

Sign up to request clarification or add additional context in comments.

Comments

0

You're making this way harder than it needs to be. Just choose a Class Library Project type when creating your project and the output will be a dll, resources and all.

3 Comments

I muss create a Resource file in dll dynamic from my c# project, because the user can edit Xml Files and should export this edited files into a dll ...
Looks like he's running the compiler from his own code, not from Visual Studio.
in my programm i can edit xml files ... i would have a funktion that take this xml files and put them as an resource into a new dll
0

The issue you have is that the StronglyTypedResourceBuilder creates from your resources a C# class which has a property ResourceManager where this one has the wrong namespace or you generate a ResourceManager by hand and assume a different resource name. From where did you get the ResourceManager that did cause the problem? You can work around this by using an overload of the ResourceBuilder where you can specify the Resource Base Name, Resource Name and the namespace of the generated class. The naming scheme is

  • Resource Base Name: Customer.Premium.XmlAppResources.Properties
  • Resource Name: Resources
  • Resource Extension: .ressources

This 3 things define the resource name which is stored as resource stream in your assembly. In this case Customer.Premium.XmlAppResources.Properties.Resources.ressources

Please check with e.g. Reflector if under which name the resources are created in your assembly and alter your namespace accordingly to make either the creator of the ResourceManager happy or change the creation of the ResourceManager to successfully load the resources.

Yours, Alois Kraus

Comments

0

Yes Thanks! This is exactly what I need:

  IResourceWriter writer = new ResourceWriter("myResources.resources");

  // Adds resources to the resource writer.
  writer.AddResource("String 1", "First String");

  writer.AddResource("String 2", "Second String");

  writer.AddResource("String 3", "Third String");

  // Writes the resources to the file or stream, and closes it.
  writer.Close();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.