Answered Writing a SmsServiceProvider.dll extension

  • Wednesday, December 12, 2012 2:47 PM
     
      Has Code

    I've written a SmsServiceProvider.dll class to work with the SMS OTP, and now I've stumbled across this error when resetting my password:

     

    Microsoft.IdentityManagement.SmsServiceProviderManager: System.TypeLoadException: An error occurred while loading the custom SMS provider DLL.  Please review the inner exception details. ---> System.TypeLoadException: The custom SMS provider DLL does not implement the required interface.

       at Microsoft.IdentityManagement.SmsServiceProvider.SmsServiceProviderManager.InitializeSmsServiceProvider()

       --- End of inner exception stack trace ---

       at Microsoft.IdentityManagement.SmsServiceProvider.SmsServiceProviderManager.InitializeSmsServiceProvider()

       at Microsoft.IdentityManagement.SmsServiceProvider.SmsServiceProviderManager.get_ExternalSmsServiceProviderExists()

       at Microsoft.ResourceManagement.Workflow.Hosting.SmsNotificationServiceImpl.SendSmsMessage(String mobileNumber, String message, Guid requestId, Dictionary`2 deliveryAttributes)

       at Microsoft.ResourceManagement.Workflow.Activities.OneTimePasswordSmsAuthenticationGate.SendOneTimePassword(String plainTextOneTimePassword)

    Now the weird thing is that I've seen this in the beginning when fooling around, but then it started working. Now all of a sudden no matter what I do it just doesnt want to work.

    Here's my code, a bit stripped though

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using Microsoft.IdentityManagement.SmsServiceProvider;
    using System.Diagnostics;
    using System.Configuration;
    using Shared.DataContracts;
    using System.Reflection;
    
    namespace FIM.SmsServiceProvider
    {
        public class SmsServiceProvider : ISmsServiceProvider
        {
            readonly static TraceSource trace = new TraceSource("SmsServiceProvider", SourceLevels.All);
    
            public void SendSms(string mobileNumber,
                                string message,
                                Guid requestId,
                                Dictionary<string, object> deliveryAttributes)
            {
                
    //some logging stripped                
    mySMSProvider.SendSms(ui, message);            
                }            
            }       
        }
    
        class mySMSProvider
        {
            readonly static TraceSource trace = new TraceSource("SmsServiceProvider", SourceLevels.All);
    
            mySMSProvider()
            {
            }
    
            public static int SendSms(UserInfo ui, string message)
            {
               //send sms logic stripped
                return 1;
            }
    
            //public static string GetRequestData(string mobile, string message)
            //{
            //    return "";
            //}        
    
            //public void GetCredentials()
            //{
            //}       
        };
    }
    

    This is really really weird, as the only method to implement for that Interface is sendSMS which to me seems pretty present in the code...

    http://setspn.blogspot.com

All Replies

  • Wednesday, December 12, 2012 3:08 PM
     
     Answered
    I remember there was a bug in the product (i think it's fixed) -- basically the workaround is to make sure the DLL only contain 1 clas... so if u want >1 class, use inner class instead

    The FIM Password Reset Blog http://blogs.technet.com/aho/

  • Wednesday, December 12, 2012 4:49 PM
     
     

    Bah,

    No matter how "simple" I make the code, even by only specifying the public sendSms method with some dummy lines in it the thing doesnt work. Restarting the FIM Service should be enough to be "up to date" about the newly compiled DLL eh?

    Even taking the sample code (from http://technet.microsoft.com/en-us/library/jj134288(v=ws.10)) and compiling as is doesn't seem to work.

    This is turning into a nightmare.

    Kind regards,

    Thomas


    http://setspn.blogspot.com


  • Wednesday, December 12, 2012 5:23 PM
     
     
    can u make sure your DLL only have 1 class defined?

    The FIM Password Reset Blog http://blogs.technet.com/aho/

  • Wednesday, December 12, 2012 6:34 PM
     
     Answered Has Code

    Additionally, the *one* class defined in SmsProvider must have a no-argument constructor.

    The SMS wrapper interface would be easier to troubleshoot if it simply did this:

    return assembly.GetTypes().Where(t => typeof(ISmsServiceProvider).IsAssignableFrom(t)).Single().GetConstructor(new Type[0]).Invoke();

    Unfortunately, it presently conceals informative exceptions with uninformative ones, and throws a fit if the "first" type in the assembly isn't what it's looking for.

  • Wednesday, December 12, 2012 10:28 PM
     
     
    This is also Thomas. So in my first example I've got two classes and the  smsserviceprovider  has the sendsms method and no "no argument" constructor like Steve states. so I'm wrong twice?
    so IT would be better to nest the myserviceprovider class in the first one and add a no argument constructor for the first class?
    • Edited by Invisibal Wednesday, December 12, 2012 10:30 PM
    •  
  • Wednesday, December 12, 2012 10:32 PM
     
     
    It's probably just the problem of having two Types in the assembly; the no-arg constructor is implicitly available unless hidden or alternate constructors are present.  I just noticed it as another weird quirk in the SmsProvider loader.

    Steve Kradel, Zetetic LLC SMS OTP for FIM | Salesforce MA for FIM

  • Tuesday, December 18, 2012 8:15 AM
     
     

    After asking a (dev) colleague for some insights I finally got it working again. As you guys stated: use one class AND make sure there's a no-arg constructor. I really had to do both.

    Oh and perhaps eassy to be forgotten: adding a "service reference" in visual studio also results in additional class files! And the same goes for "settings" which results in a settings.cs file.

    I'm cooking up a blogpost for future reference, but it's kinda busy here...

    Thanks all for the quick replies!


    http://setspn.blogspot.com

  • Thursday, January 31, 2013 10:47 AM
     
     
    Did you get a chanse to write that blogpost? I'm stuck aswell on the SMS OTP. Everything goes as planned but I'm not recieving any sms's..