Saturday, September 14, 2013

Strong name validation failed

When we execute our code which refers an assembly(dll) then that assembly gets validated for the signature validation and if it's a non-signed or delay signed(in some cases) then it throws the error:

Could not load file or assembly '[Your file], Version=2.0.0.0, Culture=neutral, PublicKeyToken=[public key token]' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A).

To solve this we can disable the verification of an assembly by using sn.exe available at "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools" (depends on the Framework you are using i.e .Net framework 4.5 in my case)

Open Command Prompt and run the command:
cd "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools"
SN -Vr YourAssemblyName

After disabling the verification the CLR will not verify the assembly signature.

Then to re-enable the verification of the assembly run:
SN -Vu YourAssemblyName

CryptoAPI not available

You have set up a new Microsoft Dynamics AX environment and everything works fine but EP(Enterprise Portal). The only thing Event Viewer(eventvwr) says is "CryptoAPI not available". So it's time to check the Business Connector user account under "System Administration->Setup->System->System service accounts" or Application Pool identity of the EP site using Sharepoint Central Administration.

The bcproxy account is either not setup properly or not assigned in AX or in sharepoint. Remember bcproxy account should be a same domain account. So you just need to assign it and you have got your EP back :)

Get SID of a User Account

To get the SID(Security Identifier) of a particular User ID we may use multiple methods. Some of them are mentioned below:

1. Using Registry Editor (only for logged in users)
  • Method 1: Goto Run(press Window+R or Start->Run), type regedit and press ok. It will open the Registry Editor then goto the following path: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList and expand it. Then you have to select the folders prefixed with S-1-5-21. As you select them on the right pane of the window you will find a String type "ProfileImagePath" which will display the username.
  • Method 2: In regedit, goto the HKEY_USERS folder and the first key with prefix S-1-5-21 is currently logged in user's SID.
(NOTE: Modifying registry may cause any system-wide troubles or may even crash it)

2. Open Command Prompt, goto Run type "cmd" and press OK. Now in the command prompt type "wmic useraccount get name,sid" and it will display the list of usernames and their SID's.

3. Using scripting, open notepad and paste the below script in it:
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
Set objAccount = objWMIService.Get("Win32_UserAccount.Name='administrator',Domain='Abhishek'")
Wscript.Echo objAccount.SID

Change the UserAccount.Name and Domain as per your requirement and then save the file as script.vbs(make filetype as "All types") and then run the file. It will display your SID

4. Using external tools such as PsGetSid: http://technet.microsoft.com/en-us/sysinternals/bb897417.aspx

If anybody knows any other way for this then please do comment :)

You are not recognized as a recognized user of Microsoft Dynamics Ax

You may this error when you have to import an AX database from some other environment of different domain e.g. your client's DB. In this case once you import the db and start Ax, it will throw the following error:








Now this happens because of the change in domain(new domain and users are not logged in AX DB) so we need to add users of our domain to this DB. For this we need to add an entry with SID of our "Admin" account to the "USERINFO" table.



Follow the steps:
  1. Get the SID of Admin account.
  • You can also get SID from an existing AX DB in your environment by using the SQL command:
select SID, Networkdomain, networkalias from userinfo where networkalias = '<UserAlias>'
  1. Open SQL Server Management Studio.
  2. Run the provided query
update USERINFO
set NETWORKDOMAIN = 'contoso.com', NETWORKALIAS = 'axadmin', SID = 'S-1-5-21-2423567575-2897528880-3809357285-500'
where id = 'admin'

where NETWORKDOMAIN is the DomainName of your environment where you have restored the DB and NETWORKALIAS is the username to which you want to provide access(Admin in this case).