473,503 Members | 8,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Satellite assemblies and strong names

Hi,

I created an assembly (let's call it assembly (B)) that returns a localized
resource for a given key (similar to System.Globalization.ResourceManager).
I checks if the caller assembly (let's call it assembly (A)) has a satellite
assembly (let's call it assembly (sA)) with localized resources.
If it exists, it gets the resource with the given key and returns it,
otherwise it reads information from a support database and dinamically
compiles a new satellite assembly and places it in the calling assembly's
respective folder, and then returns the requested resource.
It is all working fine, but once I started signing the assemblies (A) and
(B) with strong names, I got a dreadful error:

"The located assembly's manifest definition with name '(A).resources' does
not match the assembly reference."

Naturally, I assume I need to sign (sA) with strong name too, so I tried to
do it when I create the satellite assembly, but so far I have been
unsuccessful. Below are my efforts to provide (sA) with a strong name
dinamically:

----------- 1st Try -----------------------------
AssemblyName assName = new AssemblyName();
assName.Name = assemblyName + ".resources";
assName.CultureInfo = new CultureInfo(culture);

// ------ Sign the satellite assembly -----
FileStream fs = null;
StrongNameKeyPair kp = null;

try
{
fs = new FileStream(@"MyKey.snk", FileMode.Open, FileAccess.Read,
FileShare.Read);
kp = new StrongNameKeyPair(fs);
}
catch (FileNotFoundException)
{
Diag.Trace.Write("Strong name key pair file not found.");
throw;
}
catch(Exception ex)
{
Diag.Trace.Write("Error obtaining strong name key pair from file." +
fs.Name);
throw;
}
finally
{
if (fs != null)
{
fs.Close();
}
}

assName.KeyPair = kp;

----------- 2nd Try -----------------------------
try
{
FileStream publicKeyStream = File.Open("MyKey.snk",
FileMode.Open,FileAccess.Read, FileShare.Read);
byte[] publicKey = new byte[publicKeyStream.Length];
publicKeyStream.Read(publicKey, 0, (int)publicKeyStream.Length);
// Provide the assembly with a public key.
assName.SetPublicKey(publicKey);
}
catch(Exception ex)
{
throw;
}
---------------------------------------------
Can anyone help me ?


-----------------------------
Mário Sobral
Inosat
Research & Development
-----------------------------


Nov 16 '05 #1
2 2884
JMW
Do early signing as opposed to late signing of the assembly. The framework is going to verify the signature at load time. Try including this line in your assemblyinfo.cs class.

[assembly: AssemblyKeyFile(@"my.snk")]

Change the path of course! And take out your signing code.

jason.

"Mário Sobral" wrote:
Hi,

I created an assembly (let's call it assembly (B)) that returns a localized
resource for a given key (similar to System.Globalization.ResourceManager).
I checks if the caller assembly (let's call it assembly (A)) has a satellite
assembly (let's call it assembly (sA)) with localized resources.
If it exists, it gets the resource with the given key and returns it,
otherwise it reads information from a support database and dinamically
compiles a new satellite assembly and places it in the calling assembly's
respective folder, and then returns the requested resource.
It is all working fine, but once I started signing the assemblies (A) and
(B) with strong names, I got a dreadful error:

"The located assembly's manifest definition with name '(A).resources' does
not match the assembly reference."

Naturally, I assume I need to sign (sA) with strong name too, so I tried to
do it when I create the satellite assembly, but so far I have been
unsuccessful. Below are my efforts to provide (sA) with a strong name
dinamically:

----------- 1st Try -----------------------------
AssemblyName assName = new AssemblyName();
assName.Name = assemblyName + ".resources";
assName.CultureInfo = new CultureInfo(culture);

// ------ Sign the satellite assembly -----
FileStream fs = null;
StrongNameKeyPair kp = null;

try
{
fs = new FileStream(@"MyKey.snk", FileMode.Open, FileAccess.Read,
FileShare.Read);
kp = new StrongNameKeyPair(fs);
}
catch (FileNotFoundException)
{
Diag.Trace.Write("Strong name key pair file not found.");
throw;
}
catch(Exception ex)
{
Diag.Trace.Write("Error obtaining strong name key pair from file." +
fs.Name);
throw;
}
finally
{
if (fs != null)
{
fs.Close();
}
}

assName.KeyPair = kp;

----------- 2nd Try -----------------------------
try
{
FileStream publicKeyStream = File.Open("MyKey.snk",
FileMode.Open,FileAccess.Read, FileShare.Read);
byte[] publicKey = new byte[publicKeyStream.Length];
publicKeyStream.Read(publicKey, 0, (int)publicKeyStream.Length);
// Provide the assembly with a public key.
assName.SetPublicKey(publicKey);
}
catch(Exception ex)
{
throw;
}
---------------------------------------------
Can anyone help me ?


-----------------------------
Mário Sobral
Inosat
Research & Development
-----------------------------


Nov 16 '05 #2
Hi !

Thanks for the suggestion, but my problem is that the satellite assembly is
being generated dinamically with System.Reflection.Emit. That's why it
should be signed dinamically also.

There is a method that reads the resources associated to a certain calling
assembly from a database, then generate the satellite assembly for that
calling assembly:

----------------------------------------------------------------------------
-------
AssemblyName assName = new AssemblyName();

assName.Name = assemblyName + ".resources";

assName.CultureInfo = new CultureInfo(culture);

assName.Version = new System.Version(1,0,0,0);

AssemblyBuilder assBuilder =
Thread.GetDomain().DefineDynamicAssembly(assName,
AssemblyBuilderAccess.RunAndSave,outputPath);

[Code to sign the satellite assebly here (?)]
ModuleBuilder modBuilder = assBuilder.DefineDynamicModule(assName.Name +
".dll", assName.Name + ".dll", true);
IResourceWriter resourceWriter = modBuilder.DefineResource(assemblyName +
"." + culture + ".resources",

assemblyName + "." + culture + ".resources",

ResourceAttributes.Public);

resStream.Seek(0,System.IO.SeekOrigin.Begin);

// We need ResourceSet object for its GetObject function, to get images and
other binary objects.

System.Resources.ResourceReader reader = new
System.Resources.ResourceReader(resStream);

ResourceSet rs = new ResourceSet(reader);

IDictionaryEnumerator resourcesEnumerator = reader.GetEnumerator();

while(resourcesEnumerator.MoveNext())

{

if(resourcesEnumerator.Value.GetType().ToString(). ToLower() ==
"system.string")

{

resourceWriter.AddResource(resourcesEnumerator.Key .ToString(),resourcesEnume
rator.Value.ToString());

}

else

{

resourceWriter.AddResource(resourcesEnumerator.Key .ToString(),rs.GetObject(r
esourcesEnumerator.Key.ToString()));

}

}

reader.Close();

rs.Close();
Diag.Trace.Write("Saving assembly to: " + assemblyPath + "\\" + assemblyName
+ ".resources.dll");

assBuilder.Save(assemblyName + ".resources.dll");


-----------------------------
Mário Sobral
Inosat
Research & Development
-----------------------------


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
276
by: Ice | last post by:
All - I read out on MSDN that "If your main assembly uses strong naming, satellite assemblies must be signed with the same private key as the main assembly." Well if you allow the regeneration...
3
7522
by: Nils Erik Asmundvaag | last post by:
Hello I hope someone is able to help me with this frustrating problem. I have a C# web project in Visual Studio .NET 2003. I want to support Swedish and Norwegian texts and have put the texts...
0
1195
by: Mário Sobral | last post by:
Hi, I created an assembly (let's call it assembly (B)) that returns a localized resource for a given key (similar to System.Globalization.ResourceManager). I checks if the caller assembly (let's...
1
6913
by: Afaq | last post by:
Hi, After adding large number of empty resource files (which will be updated later), we are not able to compile the project. the following is the output of the build process. It fails while...
0
1533
by: thbst16 | last post by:
After a number of weeks of fruitless research and experimentation, I decided to turn to the group with this issue and see if anyone had any experiences or insights that might help me out. Here's...
5
10047
by: Rudolf Ball | last post by:
Dear NG, i want to load a plugin (WinForm) in my Applikation. That works fine. Now I want to globalize that plugin. So I have to load the Satellite Assembly, as well. But how can I load this...
5
2048
by: Chua Wen Ching | last post by:
Hi all, Basically right now, i am interested to learn how to break strong names in ..net assemblies. I had researched a lot and found a blog that mention how to hack strong name assemblies....
3
1673
by: Adam Calderon | last post by:
In ASP.NET 2.0 you have the choice of using the built in App_GlobalResoruces or App_LocalResources style of using resources or you can use your own resources utilizing satellite assemblies. In the...
0
1484
by: Faris Ahmed | last post by:
Dear ASP newsgroup, I have the following environment: 1) VS2005 ASP.NET 2.0 WebApplication called MyApp. 2) MyApp contains Strings.resx, Strings.en.resx and Strings.de.resx in...
1
1489
by: scpedicini | last post by:
Let's say that I've built an assembly, called myapi.dll whose default resource messages are english. Then let's say I create a german satellite assembly for the assembly called...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.