0

I have a web service added by service reference (called "MyServiceReferences") in my ASP .NET MVC 4 solution. Also I have an Active Directory service in another project in the same solution. I am trying to display user name (First name and Last name) in my web page using active directory users information. The problem is when I call

PrincipalSearcher.FindAll(), it works sometimes. The exception I am getting is

Could not load file or assembly 'MyServiceReferences.XmlSerializers' or one of its dependencies. The system cannot find the file specified.

In my project build setting I have tried to set Generate serialization assembly "On". But it did not solve my problem.

Yogi
  • 9,174
  • 2
  • 46
  • 61
  • The "Generate Serialization Library" functionality has been broken for a while. All options "Off, Auto or ON" do not produce the XmlSerializers library. You can safely ignore the "Cannot load ..." message. The loading of the "xxx.XmlSerializers.dll" is an optimalization by the .Net framework to not have to 'generate & JIT' the XmlSerializers (by type) that you are using in your program. If you do want to have the library generated on build, use a post-build step for you project that runs "SGEN.EXE" against your output library. Hope this helps. – Marvin Smit Sep 19 '13 at 09:42
  • Hi Marvin, Thanks for your comment. I have searched SGEN.EXE in my C drive and unable to find it. Then I have downloaded it and put it in "C:\Windows\Microsoft.NET\Framework\v4.0.30319" directory. I have run the command from command prompt "SGEN MyServiceReferences.dll", but it produced an error saying "Unhandled Exception: System.NotSupportException: Cannot serialize interface MyServiceReferences.(namespace).(interfaceName)". From your comment it seems promising but I don't know how to do that from visual studio. Can you please provide me steps of doing this ?? – Asif Hossain Shantu Sep 19 '13 at 09:58
  • Hi Mushfiqur, sgen.exe is actually part of a windows SDK. The path to the SDK will differ depending on which version of VS you are using. Using the visual studio command line (cmd.exe with paths set) should allow you directly execute the sgen.exe tool. It is important to have the correct version in compliance with the .Net version you are using. It is important to realize that "not being able to load the .XmlSerializers.dll" library is not a breaking situation. the CLR will just generate and JIT compile the XmlSerializers in memory. – Marvin Smit Sep 19 '13 at 12:15
  • I doubt the "Could not load" is the actual cause of failing the ".FindAll" method. – Marvin Smit Sep 19 '13 at 12:17
  • Hi, UserPrincipal.FindByIdentity(ctx, UserPrincipal.Current.Name); Like .findAll(), .FindByIdentity also fails and the exception is same "could not ...". It means you are right and other words , .findAll() and .FindByIdentity() are trying to use the serialize or deserialize object value but in the process they can not find MyServiceReferences.XmlSerializers.dll file. (Not sure just a guess) – Asif Hossain Shantu Sep 19 '13 at 13:12

1 Answers1

1

Following command from visual studio command line solves the problem

Sgen.exe (locationOfTheDllFile)\MyServiceReferences.dll

But there is another following error occurs rarely (when attempting to load the page very very often)

[System.AppDomainUnloadedException] = {"Attempted to access an unloaded appdomain. (Exception from HRESULT: 0x80131014)"}