Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SGEN : error : Could not load file or assembly (Exception from HRESULT: 0x8013141A)

VS 2010, win server 2003, .Net 3.5 solution, which were migurated from .Net 1.1

All projects in solution are Delay signed. The soluton can be build successfully for Debug, but always failed for Release with following error. SGEN : error : Could not load file or assembly 'AssemblingX, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=xxxxxxxx' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)

The AssemblingX is the project i want to build. All referenced DLLs of this project are saved at local folder, and signed already. If i change the property of project AssemblingX to sign it, then solution can be built for release successfully.

I created a sgen.exe.config to enable "loadFromRemoteSources" by following the guided on http://social.msdn.microsoft.com/Forums/nl-NL/msbuild/thread/695581ae-77e7-4c3a-bb3f-6472b8c47f65

But nothing changed. Any ideas?

Thanks

like image 674
Yadong Avatar asked Aug 23 '12 21:08

Yadong


3 Answers

This problem is related to Strong Name Validation. Open your AssemblyX in Ildasm.exe(C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin). Note its PublicKeyToken, lets say pkt123 for an example. Now open VS Command prompt in administrator mode and run the sn.exe command. Such as:

sn -Vr *,pkt123

Build your solution again and everything should be fine by now.

But if not and you receive same error now also, then you need to run a different version of sn.exe. To locate that, go to Visual Studio command prompt.

c:\Program Files(x86)>dir /s sn.exe

It may take 5-10 seconds and should give a list of sn.exe files. Go to the path and execute the sn.exe, required or belongs to you, as shown above. If not sure which one to execute, execute all the sn.exe. That should and must solve your problem. If not, let me know and let me carry forward the RnD again.

like image 114
Sandy Avatar answered Nov 09 '22 19:11

Sandy


Since I'm not able to comment on the only answer to this I wanted to make sure that other users that came upon this answer as I did do not make the same mistakes other may have. According to the MSDN documentation for the strong naming utility, using the Vr(signature skipping) switch can cause malicious assemblies to load and should only be used in DEVELOPMENT not deployment.

http://msdn.microsoft.com/en-us/library/k5b5tt23(v=vs.80).aspx

like image 6
mW00t Avatar answered Nov 09 '22 19:11

mW00t


if still not resolved you have to delete or set AllowStrongNameBypass (DWORD) to "1" in the key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework

On 64-bit computers,

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework

and

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework
like image 1
ewwink Avatar answered Nov 09 '22 19:11

ewwink