Vault SDK and .NET Core 2.1

Vault SDK and .NET Core 2.1

Anonymous
Not applicable
1,095 Views
3 Replies
Message 1 of 4

Vault SDK and .NET Core 2.1

Anonymous
Not applicable

Is there any way to use Vault SDK libraries with ASP.NET Core 2.1 project in Visual Studio ?

I'm getting error related to Dispatcher object.

0 Likes
1,096 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

With one of the suggestions I've also tried to connect using WebServiceManager - I just want to query Vault Database -with no luck. 

I can successfully connect using .NET Framework 4.7 Console App but if I try to do the same thing in ASP.NET ( using the same .NET Framework 4.7 ) it throws this error.

 

Server Error in '/' Application.
Could not load file or assembly 'Autodesk.Connectivity.WebServices.Interop' or one of its dependencies. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.BadImageFormatException: Could not load file or assembly 'Autodesk.Connectivity.WebServices.Interop' or one of its dependencies. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Autodesk.Connectivity.WebServices.Interop' could not be loaded.


=== Pre-bind state information ===
LOG: DisplayName = Autodesk.Connectivity.WebServices.Interop
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Autodesk.Connectivity.WebServices.Interop | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/***/source/repos/WebApplication33/
LOG: Initial PrivatePath = C:\Users\***\source\repos\WebApplication33\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\***\source\repos\WebApplication33\web.config
LOG: Using host configuration file: C:\Users\***\OneDrive\Dokumenty\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/***/AppData/Local/Temp/Temporary ASP.NET Files/vs/f078ab58/e2fab317/Autodesk.Connectivity.WebServices.Interop.DLL.
LOG: Attempting download of new URL file:///C:/Users/***/AppData/Local/Temp/Temporary ASP.NET Files/vs/f078ab58/e2fab317/Autodesk.Connectivity.WebServices.Interop/Autodesk.Connectivity.WebServices.Interop.DLL.
LOG: Attempting download of new URL file:///C:/Users/***/source/repos/WebApplication33/bin/Autodesk.Connectivity.WebServices.Interop.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

Stack Trace: 


[BadImageFormatException: Could not load file or assembly 'Autodesk.Connectivity.WebServices.Interop' or one of its dependencies.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +36
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +21
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: Could not load file or assembly 'Autodesk.Connectivity.WebServices.Interop' or one of its dependencies.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +738
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +217
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +92
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +290
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +549

[HttpException (0x80004005): Could not load file or assembly 'Autodesk.Connectivity.WebServices.Interop' or one of its dependencies.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10075108
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Any ideas what can cause this ? It's the same framework...

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi,

the problem is that ASP.NET application hosted on IIS or run from IIS Express behaves differently then normal standalone application like console application. First of all, ASP.NET Web app resolves dependencies from another sources. As You can see in Your log that library is searched in Framework folders and other system folders - and this is by convention.

 

To change this behavior define your own AssemblyLoader class:

    public static class AssemblyLoader
    {
        private static Regex _assemblyRegEx;
        private static bool _is64Process;

        public static void Program()
        {
            _is64Process = IntPtr.Size == 8;
            InitRegEx();
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
        }

        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            if (IsXmlSerializer(args.Name))
            {
                return null;
            }

            var fields = args.Name.Split(',');
            var assname = fields[0];
            if (assname.EndsWith(".resources", StringComparison.InvariantCultureIgnoreCase))
            {
                return null;
            }

            Assembly result = null;
            try
            {
                var name = new AssemblyName(args.Name);
                var assemblies = AppDomain.CurrentDomain.GetAssemblies();
                foreach (var assembly in assemblies)
                {
                    if (name.Name != assembly.GetName().Name) continue;
                    return assembly;
                }
                result = Assembly.LoadFrom(args.Name);
            }
            catch
            {
                if (MethodBase.GetCurrentMethod().DeclaringType == null) return result;

                var basePath = System.IO.Path.GetDirectoryName(new Uri(MethodBase.GetCurrentMethod().DeclaringType.Assembly.CodeBase).LocalPath);
                var subFolder = _is64Process ? "x64" : "x86";
                var assemblyFileName = System.IO.Path.Combine(basePath, string.Format(CultureInfo.InvariantCulture, "{1}\\{0}.dll", new AssemblyName(args.Name).Name, subFolder));
                if (System.IO.File.Exists(assemblyFileName))
                {
                    result = Assembly.LoadFile(assemblyFileName);
                }
            }

            return result;
        }

        private static void InitRegEx()
        {
            const string regex = @"^([\w\.]+)XmlSerializers";
            const RegexOptions options = RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.IgnoreCase;
            _assemblyRegEx = new Regex(regex, options);
        }

        private static bool IsXmlSerializer(string name)
        {
            return _assemblyRegEx.IsMatch(name);
        }
    }

Then copy x86 and x64 references from Vault SDK to your bin folder.

In your Global.asax file execute your loader in Application_Start method:

protected void Application_Start()
        {
            AssemblyLoader.Program();
         ...
        }

If You are using Vault 2020 there are no longer x86 references, so You should adopt this class.

Remember that running standalone Vault Client app in web enviroment is not a simple task. You should take into consideration that application pool should be run in x64 bitness and identity should be set to Windows user who once logged in via Vault Client on that machine You are running web app (if You are using Network License this not necessary). There are some other requirements that must met.

 

Let me know if that helps.

Message 4 of 4

Anonymous
Not applicable

Is there any further tutorials or articles available that document the steps needed to access a Vault Server from a .NET Core 3.1 web application?