The type initializer for 'DotNetOpenAuth.Logger' threw an exception - powershell

My aim is to call Google Admin SDK Directory updates from PowerShell. I started out with a working .NET app and converted it into a class library (which I tested - it works). I load that in the module manifest with
RequiredAssemblies = #('My.GoogleAdminSDK.Directory.dll')
My Get-GoogleSDKUser function New-Objects my class and calls GetUser on it. And I get:
Exception calling "GetUser" with "1" argument(s): "The type initializer for
'DotNetOpenAuth.Logger' threw an exception."
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\My.googleadminsdkdirectory.admin\My.GoogleA
dminSDKDirectory.Admin.psm1:56 char:9
+ $service.GetUser($googleUserName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : TypeInitializationException
I've tried adding a config file for log4net which has produced an empty log file but that didn't help.
Note: in order to get this far, I had to add
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.12.0" newVersion="1.2.12.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
to powershell_ise.exe.config to prevent the error:
"Could not load file or assembly 'System.Net.Http.Primitives,
Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified."
which is far from ideal.
EDIT
The InnerException for the PowerShell-calling-my-DLL version was:
Could not load file or assembly 'log4net, Version=1.2.10.0,
Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its
dependencies. The system cannot find the file specified.
It took a bit of digging to find the innerException. I had a bit of a ferret around and found suggestions to use Fuslogvw, so I tried that. I closed and re-opened PowerShell, started up Fusion Log Viewer (it's the first time I've used it) and found three entries for log4net. The descriptions are:
log4net
log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821
When I open them up, the first two have 'The operation was successful.' as the second line of text. The third has 'The operation failed. Bind result: hr = 0x80070002. The system cannot find the file specified.'
When I dig into that log, I find:
LOG: Assembly download was successful. Attempting setup of file: C:\windows\system32\windowspowershell\v1.0\Modules\JLP.GoogleAdminSDKDirectory.Admin\log4net.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: The assembly reference did not match the assembly definition found.
I tried running it from Visual Studio again. There were also three entries in fuslogvw and the third had the same error. But there's nothing in the VS output to indicate a problem.

It turns out that the two versions of log4net with different PublicKeyTokens have caused problems for others. I've got it working by adding a verison of log4netwith PublicKeyToken=1b44e1d426115821 to the GAC and adding another bindingredirect to the config file because the versions didn't match.
You can find the log4net versions here. You'll see references to oldkey and newkey versions. The oldkey one has PublicKeyToken=1b44e1d426115821 so I simply ran
gacutil /i "C:\Users\Me\Downloads\log4net\log4net-1.2.12-bin-oldkey\log4net-1.2.12\b
in\net\4.0\release\log4net.dll"
to stick it in the GAC and added:
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.12.0" newVersion="1.2.12.0" />
</dependentAssembly>
to the assemblyBindings in the config file.

Related

Service Fabric: The EntryPoint Blah.exe is not found

I did some project renaming and changed the folder structure and now I can't deploy my service fabric app to my local service fabric cluster.
Register-ServiceFabricApplicationType : The EntryPoint IdentityService.exe is not found.
The app was called IdentityApp and is now TheProject.Identity.App
The service was called IdentityWeb and is now TheProject.Identity.Service
More Log Details
Started executing script 'Deploy-FabricApplication.ps1'.
. 'C:\Users\mdepouw\source\repos\TheProject\TheProject.IdentityDomain\TheProject.Identity.App\Scripts\Deploy-FabricApplication.ps1' -ApplicationPackagePath 'C:\Users\mdepouw\source\repos\TheProject\TheProject.IdentityDomain\TheProject.Identity.App\pkg\Debug' -PublishProfileFile 'C:\Users\mdepouw\source\repos\TheProject\TheProject.IdentityDomain\TheProject.Identity.App\PublishProfiles\Local.5Node.xml' -DeployOnly:$true -ApplicationParameter:#{} -UnregisterUnusedApplicationVersionsAfterUpgrade $false -OverrideUpgradeBehavior 'None' -OverwriteBehavior 'Always' -SkipPackageValidation:$true -ErrorAction Stop
Copying application to image store...
Upload to Image Store succeeded
Registering application type...
Register-ServiceFabricApplicationType : The EntryPoint IdentityService.exe is not found.
FileName: C:\SfDevCluster\Data\ImageBuilderProxy\AppType\IdentityAppType\IdentityServicePkg\ServiceManifest.xml
At C:\Program Files\Microsoft SDKs\Service
Fabric\Tools\PSModule\ServiceFabricSDK\Publish-NewServiceFabricApplication.ps1:251 char:9
Register-ServiceFabricApplicationType -ApplicationPathInImage ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (Microsoft.Servi...usterConnection:ClusterConnection) [Register-Servic
eFabricApplicationType], FabricException
FullyQualifiedErrorId : RegisterApplicationTypeErrorId,Microsoft.ServiceFabric.Powershell.RegisterApplicationType
Finished executing script 'Deploy-FabricApplication.ps1'.
Time elapsed: 00:00:26.1378123
The PowerShell script failed to execute.
In TheProject.Identity.Service\PackageRoot\ServiceManifest.xml I had to change the <Program> to match the new exe name
<!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>TheProject.Identity.Service.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
</CodePackage>
I have also encounter this issue, i got the below two parameters was different in *.csproj file.
<AssemblyName>servicename</AssemblyName>
<RootNamespace>servicename</RootNamespace>
Maybe it might be helpful for somebody else.
I didn't rename services in my project, but I faced the same error couple of days ago. After a lot of time of deep into the issue, I got its reason finally.
I had this line in service's *.csproj file:
<SelfContained>false</SelfContained>
And after removing this string everything started working. I'm not sure why Azure's team didn't provide the much more obvious error in this case.
Maybe it might be helpful for somebody else.
Build configuration was wrong in my case, it was set to release for Debug.
Right click on the solution -> Configuration Manager, change to debug for your project
Even I faced the same problem . I updated the serviceManifest.xml as below and got the issue resolved
<CodePackage Name="Code" Version="1.0.0">
<SetupEntryPoint>
<ExeHost>
<Program>SetupEntryPointTasks.exe</Program>
<ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="20480"/>
</ExeHost>
</SetupEntryPoint>
<EntryPoint>
<ExeHost>
<Program>aaa.exe</Program>
<ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="20480" />
</ExeHost>
</EntryPoint>
</CodePackage>

RegAsm error RA0000 Could not load file or assembly on Network Drive

I experience a problem using a batch file to call Regasm on framework 4 on a network drive.
It works correctly when the dll is on a local drive.
The message is Could not load file or assembly filename.dll or one of its dependencies. Operation is not supported.
The problem is discussed
here ad "Darrens Developer Diary"
however editing the config as described does not help
I also tried the advice
here
which differs in the line
<loadFromRemoteSources="true"/>
with this I received a different error
"The system cannot execute the specified program"
The DLL used to use Framework 2, but I unregistered it using Framework 2 Regasm.
Here is the regasm.exe.config
<?xml version ="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
<supportedRuntime version="v4.0" sku="client" />
</startup>
<runtime>
<loadfromremotesources enabled="true"> </loadfromremotesources>
</runtime>
</configuration>
Here is the command in my batch file
Z:
cd foldername
c:\WINDOWS\Microsoft.Net\Framework\v4.0.30319/regasm /verbose /codebase /tlb: .\SBD.CommBridge.tlb .\SBD.ComBridge.dll
The correct line in regasm.exe.config is
<loadFromRemoteSources enabled="true"/>
the case matters

Subsonic Access To App.Config Connection Strings From Referenced DLL in Powershell Script

I've got a DLL that contains Subsonic-generated and augmented code to access a data model. Actually, it is a merged DLL of that original assembly, Subsonic itself and a few other referenced DLL's into a single assembly, called "PowershellDataAccess.dll. However, it should be noted that I've also tried this referencing each assembly individually in the script as well and that doesn't work either.
I am then attempting to use the objects and methods in that assembly. In this case, I'm accessing a class that uses Subsonic to load a bunch of records and creates a Lucene index from those records.
The problem I'm running into is that the call into the Subsonic method to retrieve data from the database says it can't find the connection string. I'm pointing the AppDomain at the appropriate config file which does contain that connection string, by name.
Here's the script.
$ScriptDir = Get-Location
[System.IO.Directory]::SetCurrentDirectory($ScriptDir)
[Reflection.Assembly]::LoadFrom("PowershellDataAccess.dll")
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", "$ScriptDir\App.config")
$indexer = New-Object LuceneIndexingEngine.LuceneIndexGenerator
$indexer.GeneratePageTemplateIndex("PageTemplateIndex");
I went digging into Subsonic itself and the following line in Subsonic is what's looking for the connection string and throwing the exception:
ConfigurationManager.ConnectionStrings[connectionStringName]
So, out of curiosity, I created an assembly with a single class that has a single property that just runs that one line to retrieve the connection string name.
I created a ps1 that called that assembly and hit that property. That prototype can find the connection string just fine.
Anyone have any idea why Subsonic's portion can't seem to see the connection strings?
Did you add the System.Configuration assembly to your PowerShell session? The following works for me:
PS> gc .\app.config
<?xml version='1.0' encoding='utf-8'?>
<configuration>
<connectionStrings>
<clear />
<add name="Name"
providerName="System.Data.ProviderName"
connectionString="Valid Connection String;" />
</connectionStrings>
</configuration>
PS> [appdomain]::CurrentDomain.SetData("APP_CONFIG_FILE", "$home\app.config")
PS> Add-Type -AssemblyName System.Configuration
PS> [Configuration.ConfigurationManager]::ConnectionStrings['Name']
Name : Name
ConnectionString : Valid Connection String;
...

Deploy to remote server using scp in NANT script

I am trying to copy a file to a remote server using scp task in Nant.Contrib .
I have used the following code to do that:
<target name= "QADeploy"description="gthtyb" >
<loadtasks assembly="C:\nantcontrib-0.85\bin\NAnt.Contrib.Tasks.dll" />
<echo message="htyh"/>
<scp file="D:\SourceTest\redist.txt" server="\\10.4.30.19" user="xxx:uuuu">
</scp>
</target>
But I am getting an error: scp failed to start. The system cannot find the file specified.
The code is as follows:
Then I have downloaded pscp.exe and modified the code as below:
<target name= "QADeploy"
description="gthtyb" >
<loadtasks assembly="C:\nantcontrib-0.85\bin\NAnt.Contrib.Tasks.dll" />
<echo message="htyh"/>
<scp file="D:\SourceTest\redist.txt" server="\\10.4.30.19" user="xxx:uuuu" program="C:\pscp\pscp.exe">
</scp>
Now I am getting the following error:
[scp] ssh_init:host does not exist
External Program Failed:C:\pscp\pscp.exe
can u please help whats the best way to copy a file to a remote server using Nant. I am using this code to deploy files to a remote server.
Thanks
You don't have to put two backslashes behind the IP of your server.
<scp file="D:\SourceTest\redist.txt" server="10.4.30.19" user="xxx:uuuu" program="C:\pscp\pscp.exe">
Also note that without the "path" parameter, the default destination folder is "~".
Update: it is the username that is crashing the pscp.exe program. Remove the ":" from your username or try with a different one.
it seems like there is some weirdness on how pscp parses paths in windows. The following should fix ssh_init:host does not exist problem:
-upload
pscp some.file user#[remote-host-or-ip]:/some/path/
-download
pscp user#[remote-host-or-ip]:/some/path/some.file some.file

How can I force IIS 7 to flush output?

In IIS 6, using Perl, I was able to send a stream of output to the client rather than buffering the entire thing and dumping it out at all once. This allowed such things as progress bars and such to be used.
How can I accomplish the same thing in IIS 7?
Under IIS 7, once you have created the Perl Script script mapping, you can add an attribute that will fix this.
You modify the %windir%\system32\inetsrv\config\applicationHost.control file and find the script mapping by name (in my case, Perl-Script). Then add the responseBufferLimit attribute into the XML, for example:
<add name="Perl-Script" path="*.pl" blah blah blah responseBufferLimit="0" />
This causes IIS to run as it did in IIS 6, with buffering off.
You can customize the web application's web.config to set responseBufferLimit="0" instead of changing global settings. Example web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Perl CGI for .pl (custom)" path="*.pl" verb="GET,HEAD,POST" modules="CgiModule" scriptProcessor="C:\Perl64\bin\perl.exe "%s" %s" resourceType="File" requireAccess="Script" responseBufferLimit="0" />
</handlers>
</system.webServer>
<system.web>
<identity impersonate="false" />
</system.web>
</configuration>
Place this file in the web root directory. It will override server settings for *.pl.
The ONLY thing that worked for my in IIS 7.5 (Windows 7) was the following command, run from CMD:
appcmd.exe set config /section:handlers "/[name='PHP_via_FastCGI'].ResponseBufferLimit:0"
NOTE: You must replace PHP_via_FastCGI with the name of your PHP handler in "Handler Mappings".