Service running on one server but not on another ~ The type name or alias xxx could not be resolved - service

I have an issue with a service. I am installing the service via an Advanced Installer installation file, and after installing it, it runs just fine on the development server.
However, when trying to install the service using the same installation file on a different server, the service crashes during startup with the following error message:
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException
at Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.TypeResolverImpl.ResolveType(System.String, Boolean)
at Microsoft.Practices.Unity.Configuration.RegisterElement.GetRegisteringType()
at Microsoft.Practices.Unity.Configuration.RegisterElement.ConfigureContainer(Microsoft.Practices.Unity.IUnityContainer)
at Microsoft.Practices.Unity.Configuration.ContainerElement+<>c__DisplayClass1.<ConfigureContainer>b__0(Microsoft.Practices.Unity.Configuration.ContainerConfiguringElement)
at Microsoft.Practices.ObjectBuilder2.EnumerableExtensions.ForEach[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>, System.Action`1<System.__Canon>)
at Microsoft.Practices.Unity.Configuration.ContainerElement.ConfigureContainer(Microsoft.Practices.Unity.IUnityContainer)
at Microsoft.Practices.Unity.Configuration.UnityConfigurationSection.Configure(Microsoft.Practices.Unity.IUnityContainer, System.String)
at Microsoft.Practices.Unity.Configuration.UnityContainerExtensions.LoadConfiguration(Microsoft.Practices.Unity.IUnityContainer, Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, System.String)
at Microsoft.Practices.Unity.Configuration.UnityContainerExtensions.LoadConfiguration(Microsoft.Practices.Unity.IUnityContainer, Microsoft.Practices.Unity.Configuration.UnityConfigurationSection)
at NFCommonImplementation.Factory.NfUnityContainer..ctor()
at NFCommonImplementation.Factory.NfUnityContainer.get_Instance()
at NFObjectFactory.CommonObjectFactory..ctor()
at NFObjectFactory.CommonObjectFactory.<.cctor>b__0()
at System.Lazy`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].CreateValue()
at System.Lazy`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].LazyInitValue()
at System.Lazy`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].get_Value()
at NFDataImporter.ImportService.<Start>b__2()
at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
Using the console to manually start the service file (which uses topshelf), specifies the error as follows:
Topshelf.Hosts.ConsoleRunHost Critical: 0 : The service threw an unhandled exception, System.InvalidOperationException: The type name or alias INetReportDao could not be resolved. Please check your configuration file and verify this type name.
I've already checked the unity configuration file, which reads:
[...]
<typeAlias alias="INetReportDao"
type="NFCommonInterfaces.Database.DAO.INetReportDao, NFCommonInterfaces, Version=6.0.0.1, Culture=neutral, PublicKeyToken=c98e951d4a9d1d0a" />
[...]
<typeAlias alias="NetReportDao"
type="NFCommonImplementation.Database.DAO.NetReportDao, NFCommonImplementation, Version=6.0.0.1, Culture=neutral, PublicKeyToken=c98e951d4a9d1d0a" />
[...]
<register type="INetReportDao" mapTo="NetReportDao">
</register>
[...]
I've also checked that the NFCommonImplementation.dll and NFCommonInterfaces.dll are located right next to the service executable.
Now I'm at my wit's end. Theoretically, it should work since the installer installs the exact same version of the service on both servers. However, for some reason it works on one server, and not on another.
Could it be that I'm missing dependencies? The installer already automatically recognizes a dependency on Visual C++ Redistributable for Visual Studio 2012 and installs it. Could there be other dependencies required for this that might be installed on the development server and not the test server which could cause this problem?

Okay, after some investigation, I figured out how to fix the issue, and after some more investigation, I found out what had caused it:
The Fix:
The missing .dlls have to be installed into the GAC. The easiest way to do so is using the followinh PowerShell script:
Set-location "[dll file location]"
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall("[dll file name]")
The Cause:
On the development server, the build process installed the .dlls in question into a custom assembly cache which the service was able to access if run on that server. However, it naturally was not able to find those files on any other server.
I hope this helps others who are experiencing similar difficulties.

Related

How could I load MongoDB Client and start a connection inside F# Interactive?

I'm using netcore 3.1, on macOS Catalina 10.15.6, and JetBrains Rider 2020.2 .
I tried starting a MongoDB connection with the following:
#r "../../../.nuget/packages/dnsclient/1.3.1/lib/net471/DnsClient.dll"
#r "../../../.nuget/packages/mongodb.driver.core/2.11.0/lib/net452/MongoDB.Driver.Core.dll"
#r "../../../.nuget/packages/mongodb.bson/2.11.0/lib/net452/MongoDB.Bson.dll"
#r "../../../.nuget/packages/mongodb.driver/2.11.0/lib/net452/MongoDB.Driver.dll"
let connection = MongoDB.Driver.MongoClient "someConnectionString"
however, when executed, there's still a problem loading the DnsClient assembly, as in the error message below:
System.TypeInitializationException: The type initializer for 'MongoDB.Driver.Core.Misc.DnsClientWrapper' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'DnsClient, Version=1.3.1.0, Culture=neutral, PublicKeyToken=4574bb5573c51424'. The system cannot find the file specified.
File name: 'DnsClient, Version=1.3.1.0, Culture=neutral, PublicKeyToken=4574bb5573c51424'
at MongoDB.Driver.Core.Misc.DnsClientWrapper..ctor()
at MongoDB.Driver.Core.Misc.DnsClientWrapper..cctor()
--- End of inner exception stack trace ---
at MongoDB.Driver.Core.Misc.DnsClientWrapper.get_Instance()
at MongoDB.Driver.Core.Configuration.ConnectionString..ctor(String connectionString)
at MongoDB.Driver.MongoUrlBuilder.Parse(String url)
at MongoDB.Driver.MongoUrlBuilder..ctor(String url)
at MongoDB.Driver.MongoUrl..ctor(String url)
at MongoDB.Driver.MongoClientSettings.FromConnectionString(String connectionString)
at MongoDB.Driver.MongoClient..ctor(String connectionString)
at <StartupCode$FSI_0181>.$FSI_0181.main#()
Stopped due to error
How to make the MongoDB.Driver.Core refer to the right path for DnsClient?
Try restore/install all your drivers(mongoDB.Driver.Core and ones depending on),
I got the same error with the following situation :
I have a DAL class library with dependency packages AspNetCore.Identity.MongoDBCore(2.1.1) and MongoDB.Driver.Core(2.11.0), An API project which lacked the Identity.MongoDBCore(2.1.1) but had the MongoDB.Driver.Core(2.11.0),
The Dependency container thrawed the DNSClient exception,{"The type initializer for 'MongoDB.Driver.Core.Misc.DnsClientWrapper' threw an exception."}

provider with invariant name 'Devart.Data.PostgreSql' is either not registered in the machine or application config file, or could not be loaded

I get this error message when using my API with PostGres database.
"The ADO.NET provider with invariant name 'Devart.Data.PostgreSql' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details."
I have the feeling I need to install Devart product on my staging and production server to fix the error. Is it right? In case this is right I would like to understand why simply copying or publishing Devart dll is not enough? Normally it should be enough.
In error message I can read "is either not registered". What does it mean to be registered? Is it rehgistered in confi file or I need to do a specific operation on my staging and produciton machine?
You should register configuration information in the DbProviderFactories section of the *.config file:
<system.data>
<DbProviderFactories>
<remove invariant="Devart.Data.PostgreSql" />
<add name="dotConnect for PostgreSQL" invariant="Devart.Data.PostgreSql" description="Devart dotConnect for PostgreSQL" type="Devart.Data.PostgreSql.PgSqlProviderFactory, Devart.Data.PostgreSql, Version=7.12.1328.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</DbProviderFactories>
</system.data>
Replace 7.12.1328.0 here with your actual version.
Refer to https://www.devart.com/dotconnect/postgresql/docs/?deployment.html.

Unity-Photon Voice-Serialization Weaver Build error

I'm trying to add Photon Voice to my Unity app for Windows 10, but I'm getting an error when I try to build the app from Visual Studio.
System.Exception: Exception while processing UnityVoiceFrontend UnityVoiceFrontend PhotonVoiceNetwork::client, error Failed to resolve assembly: 'Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
at Unity.Serialization.Weaver.MethodEmitterBase.WillUnitySerialize(FieldDefinition fieldDefinition)
at Unity.Serialization.Weaver.SerializeMethodEmitterBase.ShouldProcess(FieldDefinition fieldDefinition)
at System.Linq.Enumerable.<>c__DisplayClass6_0`1.<CombinePredicates>b__0(TSource x)
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at Unity.Serialization.Weaver.MethodEmitterBase.EmitMethodBody()
at Unity.Serialization.Weaver.MethodEmitterBase.CreateMethodDef(String methodName)
at Unity.Serialization.Weaver.SerializeMethodEmitter.SerializeMethodDefinitionFor(TypeDefinition typeDef, SerializationBridgeProvider serializationBridgeProvider)
at Unity.Serialization.Weaver.SerializationWeaver.AddSerializeMethod()
at Unity.Serialization.Weaver.SerializationWeaver.Weave()
at usw.Weaver.WeaveAssembly(String assemblyPath, AssemblyDefinition unityEngineAssemblyDefinition, ReaderParameters readerParameters)
at usw.Weaver.Weave()
at usw.Program.RunProgram(ConversionOptions options)
at usw.Program.Main(String[] args)
Am I missing something or did I not do the set up correctly?
I followed the instructions here

Could not load file or assembly 'Microsoft.PowerShell.Security' or one of its dependencies. The system cannot find the file specified

I'm running PowerShell from a C# console app. My dev box has PowerShell 3.0 - the target machines will probably have v2.0. My project file has a reference to the assembly:
<Reference Include="System.Management.Automation" />
which seems to be the recommended way. I'm getting a System.IO.FileNotFoundException when I call runspace.Open():
using (var runspace = RunspaceFactory.CreateRunspace(initialSessionState))
{
runspace.AvailabilityChanged += runspace_AvailabilityChanged;
runspace.StateChanged += runspace_StateChanged;
runspace.Open();
...
}
The exception details are:
Message: Could not load file or assembly 'Microsoft.PowerShell.Security' or one of its dependencies. The system cannot find the file specified.
FusionLog:
=== Pre-bind state information ===
LOG: User = MYDOMAIN\MyUser
LOG: DisplayName = Microsoft.PowerShell.Security
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.PowerShell.Security | Domain ID: 1
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/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\MyUser.MYDOMAIN\Projects\PoSh\PoShRunner1\bin\Debug\PoShRunner1.vshost.exe.Config
LOG: Using host configuration file:
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/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security.DLL.
LOG: Attempting download of new URL file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.DLL.
LOG: Attempting download of new URL file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security.EXE.
LOG: Attempting download of new URL file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.EXE.
If I turn off Common Language Runtime Exceptions in VS 2012, I get
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.DllNotFoundException' occurred in System.Management.Automation.dll
A first chance exception of type 'System.Management.Automation.Host.HostException' occurred in System.Management.Automation.dll
in the output log.
I've had a look at the document referenced in the fusion log but most of it doesn't seem to apply to this case or help much with my understanding. Microsoft.PowerShell.Security is in the GAC so what's the problem?
The problem is that you compiled against the powershell 3.0 system.management.automation (s.m.a.) assembly - 3.0.0.0 - instead of the powershell 2.0 s.m.a which is 1.0.0.0.
Open your project, browse to the 1.0.0.0 version and recompile. PowerShell 3.0 installs both 1.0.0.0 and 3.0.0.0 s.m.a assemblies to the GAC. Then your program will work on systems with either 2.0 or 3.0 versions of powershell.

Server Error loading HttpModule

I am stumped and need some suggestions in resolving the following error
I am getting in my application that is configured to use
an HttpModule that I have created:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Could not load type 'namespaceResponseModifier.ResponseModifer'.
...
Exception Details: System.Web.HttpException: Could not load
type 'namespaceResponseModifier.ResponseModifer'.
...
Stack Trace:
[HttpException (0x80004005): Could not load type 'namespaceResponseModifier.ResponseModifer'.]
...
[ConfigurationErrorsException: Could not load type 'namespaceResponseModifier.ResponseModifer'.]
...
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
The web server is IIS Express 7.0.
In the web.config file, the code for the element is:
<system.webServer>
<modules>
<add name="ResponseModifier"
type="namespaceResponseModifier.ResponseModifer" />
</modules>
</system.webServer>
The assembly for the HttpModule resides in
C:\...\HttpModulePreSendRequestContentCS\Bin\ResponseModifier.dll
I have also tried placing the source for the HttpModule in the App_Code directory
but I am still getting Server Error on loading the HttpModule.
In this 2nd scenario, I am getting the following error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Could not load type 'namespaceResponseModifier.ResponseModifer' from assembly 'App_Code'.
...
Exception Details: System.TypeLoadException: Could not load
type 'namespaceResponseModifier.ResponseModifer' from assembly 'App_Code'.
...
Stack Trace:
[TypeLoadException: Could not load type 'namespaceResponseModifier.ResponseModifer' from
assembly 'App_Code'.]
...
[ConfigurationErrorsException: Could not load type 'namespaceResponseModifier.ResponseModifer'
from assembly 'App_Code'.]
...
[HttpException (0x80004005): Could not load type 'namespaceResponseModifier.ResponseModifer'
from assembly 'App_Code'.]
...
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
I have also tried using the Visual Studio Development Web Server instead of the IIS Express Web Server.
I tried this server with both scenarios:
- with the assembly in the bin folder
- with the source in the App_Code folder.
These scenarios respectively produced the following Errors:
Server Error in '/HttpModulePreSendRequestContentCS' Application.
--------------------------------------------------------------------------------
Configuration Error
...
Parser Error Message: Could not load type 'ResponseModifer'.
(C:\...\HttpModulePreSendRequestContentCS\web.config line 8)
...
Source File: C:\...\HttpModulePreSendRequestContentCS\web.config Line: 8
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Server Error in '/HttpModulePreSendRequestContentCS' Application.
--------------------------------------------------------------------------------
Configuration Error
...
Parser Error Message: Could not load type 'ResponseModifer' from assembly 'App_Code'.
(C:\...\HttpModulePreSendRequestContentCS\web.config line 8)
...
Source File: C:\...\HttpModulePreSendRequestContentCS\web.config Line: 8
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Any suggestions as to what I can do to resolve the problem would be greatly appreciated.
Old question, but I believe your module add is incorrect.
<add name="NameOfModule" type="Namespace.NameOfModule, AssemblyName" />
Is the typical way I see it, so not knowing your namespace for this module, it'd look closer to:
<add name="ResponseModifier" type="ActualNameSpaceGoesHere.namespaceResponseModifier.ResponseModifer, ResponseModifier" />