PermissionSet - Request Failed error - c#

I have few projects communicating using ChannelSink, ServerSink and ClientSink.
I've upgraded the projects from .NET 2.0 to .NET 4.0. Before the upgrade everything worked fine.
Now, when I try to communicate , - for a specific message - my OnReceiveMessage isn't called and throwing the following exception:
System.Security.SecurityException: Request failed
Server stack trace:
at System.Array.InternalCreate(Void* elementType, Int32 rank, Int32* pLengths, Int32*
pLowerBounds)
at System.Array.CreateInstance(Type elementType, Int32 Length)
at System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseArray(ParseRecord
pr)
at System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseObject(ParseRecord
pr)
at System.Runtime.Serialization.Formatters.Soap.ObjectReader.Parse(ParseRecord
pr)
System.Runtime.Serialization.Formatters.Soap.SoapHandler.StartChildren()
at System.Runtime.Serialization.Formatters.Soap.SoapParser.ParseXML()
System.Runtime.Serialization.Formatters.Soap.ObjectReader.Run()
System.Runtime.Serialization.Formatters.Soap.ObjectReader.Deserialize(HeaderHandler,
ISerParser
serParser)
System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream
serializationStream,
HeaderHandler handler)
at System.Runtime.Remoting.Channels.CoreChannel.DeserializeSoapRequestMessage(Stream
inputStream, Header[] h, Boolean bStrictBinding)
at System.Runtime.Remoting.Chanels.SoapServerFormatterSink.ProcessMessage
(IServerChannelSinkStack sinkStack, IMessage requestMsg,
ITransportHeaders requestHeaders, Stream
requestStream, IMessage& responseMsg, ITransportHeaders&
responseHeaders, Stream& responseStream)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage (IMessage reqMsg, IMessage
retMSg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
.
. (some of my files)
. The action that failed was: Demand The type of the first permission that failed was: System.Security.PermissionSet The demand
was for:
The only permitted permissions were:
The method that caused that failure was:
System.Runtime.Remoting.Channels.ServerProcessing
ProcessMessage(System.Runtime.Remoting.Channels.IServerChannelSinkStack,
System.Runtime.Remoting.Messaging.IMessage,
System.Runtime.Remoting.Channels.ITransportHeaders, System.IO.Stream,
System.Runtime.Remoting.Messaging.IMessage ByRef,
System.Runtime.Remoting.Channels.ITransportHeaders ByRef,
System.IO.Stream ByRef)
The thing is, if I create a dummy method and add it to the sinkstack - it calls it. even if I use the same proxy which denies the message.
Other thing is, The other messages are working just fine. only one type of messages isnt working from all the types iv'e created.
I haven't requested PermissionSet at my app at all, Any help?

Pah - should have guess that 5 minutes after posting on stack exchange I would find it. I simply had to replace:
<formatter ref="soap" />
by
<formatter ref="soap" typeFilterLevel="Full" />
The MSDN documentation for typeFilterLevel explains what's happening, although I'm not entirely sure why an array isn't considered a "basic" type

Related

How to fix TFS build issue "ResolveComReference" task failed unexpectedly process can't access file System.Windows.Interactivity.resources.dll'

I have a WPF solution and I'm using Visual Studio Team Services with TFVC for source control. I've created an automated build, however, the build will fail (sporadically) with the following error:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (2015, 0)
The "ResolveComReference" task failed unexpectedly.
System.IO.IOException: The process cannot access the file 'C:\a\bin\es\System.Windows.Interactivity.resources.dll' because it is being used by another process.
Server stack trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at Microsoft.Build.Tasks.Copy.CopyFileWithLogging(FileState sourceFileState, FileState destinationFileState)
at Microsoft.Build.Tasks.Copy.DoCopyWithRetries(FileState sourceFileState, FileState destinationFileState, CopyFileWithState copyFile)
at Microsoft.Build.Tasks.NativeMethods.QueryPathOfRegTypeLib(Guid& clsid, Int16 majorVersion, Int16 minorVersion, Int32 lcid)
at Microsoft.Build.Tasks.ComReference.GetPathOfTypeLib(TaskLoggingHelper log, Boolean silent, TYPELIBATTR& typeLibAttr, String& typeLibPath)
at Microsoft.Build.Tasks.ResolveComReference.ConvertAttrReferencesToComReferenceInfo(List`1 projectRefs, ITaskItem[] typeLibAttrs)
at Microsoft.Build.Tasks.ResolveComReference.Execute()
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Build.Framework.ITask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__1.MoveNext()
When this does occur.. I can queue another build and it will pass. Does anyone know why this may be happening and how it can be fixed?

AppDomainUnloadedException when TFS is cloning git repos for a build

Suddenly, when queuing builds in TFS based on a git team project, I get the following stack trace.
Exception Message: Attempted to access an unloaded AppDomain. (type
AppDomainUnloadedException) Exception Stack Trace: Server stack
trace: at
LibGit2Sharp.Core.NativeMethods.git_clone(RepositorySafeHandle& repo,
String origin_url, FilePath workdir_path, GitCloneOptions& opts) at
LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir,
GitCloneOptions& opts) at LibGit2Sharp.Repository.Clone(String
sourceUrl, String workdirPath, CloneOptions options) at
Microsoft.TeamFoundation.Build.Activities.Git.GitPull.GitClone.GetRepository(String
repositoryUrl, String workingFolder, Boolean checkoutSubmodules) at
System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr
md, Object[] args, Object server, Object[]& outArgs) at
System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage
msg, IMessageSink replySink)
Exception rethrown at [0]: at
System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message
reqMsg, Boolean bProxyCase) at System.Func4.EndInvoke(IAsyncResult
result) at
Microsoft.TeamFoundation.Build.Activities.Git.GitPull.GitRepositoryBase.EndExecute(AsyncCodeActivityContext
context, IAsyncResult result) at
System.Activities.AsyncCodeActivity1.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext
context, IAsyncResult result) at
System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor
executor, BookmarkManager bookmarkManager)
I changed nothing for this to happend, googling so far I found info about it perhaps being macafee, but we dont use that on our build agent.
Using an on-premises build server
Normal TFS team projects build as expected
Resolved by restarting the server - not sure how I didn't think of that.

Exception on Serialization when making Active Directory calls

I have code in my Facade layer to make calls to active directory
activeDirectoryUserCache = new MyFacade()
.GetActiveDirectorySearchResults(MyEnum.MemberCategory.User);
This call works fine in my local machine. But when the same is deployed to DEV server, it throws the following exception.
{System.Runtime.Serialization.SerializationException: The input stream
is not a valid binary format. The starting contents (in bytes) are:
53-79-73-74-65-6D-2E-49-4F-2E-46-69-6C-65-4E-6F-74 ...
Server stack trace: at
System.Runtime.Serialization.Formatters.Binary.SerializationHeaderRecord.Read(_BinaryParser
input) at
System.Runtime.Serialization.Formatters.Binary._BinaryParser.ReadSerializationHeaderRecord()
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler
handler, __BinaryParser serParser, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage) at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream, HeaderHandler handler, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage) at
System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryResponseMessage(Stream
inputStream, IMethodCallMessage reqMsg, Boolean bStrictBinding) at
System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage
msg)
Exception rethrown at [0]: at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg) at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type) at
Drive.Beagle.Server.BeagleFacade.GetActiveDirectorySearchResults(MemberCategory
memberType) at
Drive.Beagle.Client.BeagleController.get_ActiveDirectoryUserCache() in
C:\Development\ MyProject\ClientCtrlr\MyController.cs:line 68}
As I understand the active directory call works with the Principal Objects and I believe they are not serializable by default and I cannot mark them as they are .net reserved objects. But what should I be doing in order to get rid of this issue?
I am using System.DirectoryServices.AccountManagement; namespace for AD Get users and groups calls.

"Value cannot be null" when invoking method decorated with [Autocomplete]

I have a Windows Forms application (.NET 3.5) which is deployed with the ClickOnce-technology and is used by approximately 50-100 concurrent users. They all target the same MS SQL database (SQL SERVER 2008 R2) which is hosted externally.
The application itself uses a "wrapper"-class to perform database queries. This class derives from ServicedComponent and decorates its methods with the [AutoComplete] attribute. Below is an example:
[Serializable]
[Transaction(TransactionOption.Required, Isolation=TransactionIsolationLevel.ReadCommitted)]
public class CTxGreenfee374Processor: ServicedComponent
{
public CTxGreenfee374Processor() { }
[AutoComplete]
internal Season SaveSeason(CallContext callContext, Season season)
{
return new PGreenfee374Processor().SaveSeason(callContext, season);
}
}
Most of the time this approach works like a charm. But numerous times a day following exception occur when this method gets invoked (of course there are similar methods with this exact problem):
System.ArgumentNullException
Value cannot be null.
Server stack trace:
at System.Threading.Monitor.Enter(Object obj)
at System.Data.ProviderBase.DbConnectionPool.TransactedConnectionPool.TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject)
at System.Data.ProviderBase.DbConnectionPool.TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject)
at System.Data.ProviderBase.DbConnectionInternal.CleanupConnectionOnTransactionCompletion(Transaction transaction)
at System.Data.SqlClient.SqlDelegatedTransaction.SinglePhaseCommit(SinglePhaseEnlistment enlistment)
at System.Transactions.TransactionStateDelegatedCommitting.EnterState(InternalTransaction tx)
at System.Transactions.TransactionStateDelegated.BeginCommit(InternalTransaction tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState)
at System.Transactions.CommittableTransaction.Commit()
at System.EnterpriseServices.TransactionProxy.Commit(Guid guid)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.EnterpriseServices.Thunk.Callback.DoCallback(Object otp, IMessage msg, IntPtr ctx, Boolean fIsAutoDone, MemberInfo mb, Boolean bHasGit)
at System.EnterpriseServices.ServicedComponentProxy.CrossCtxInvoke(IMessage reqMsg)
at System.EnterpriseServices.ServicedComponentProxy.Invoke(IMessage request)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at GOLFIT.BusinessProcess.Economics.CTxGreenfee374Processor.SaveSeason(CallContext callContext, Season season)
at GOLFIT.BusinessProcess.Economics.Greenfee374Processor.SaveSeason(CallContext callContext, Season season) in C:\Projekt\GOLFIT\DEVELOPMENTPROD374\BusinessProcess\GOLFIT.BusinessProcess.Economics\Greenfee374\Greenfee374Processor.cs:line 104
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at GOLFIT.BusinessProcess.Economics.Greenfee374Processor.SaveSeason(CallContext callContext, Season season)
at GOLFIT.WinGUI.Economics.FrmPrice374.Save(Boolean refresh).
As you can see the method SaveSeason in the CTxGreenfee374Processor class is mentioned in the exception. As far as I can see this is the last trace of code that I've written.
My only clue is that the exception has something to do with the [AutoComplete] attribute and/or the derived ServicedComponent class. This conclusion is based on that I've checked for invalid input parameters and that no code inside the method gets executed before the exception. And I assume that both ServicedComponent class and [AutoComplete] attribute performs som kind of logic before the method block executes.
I haven't been successful in recreating this exception when debugging, due to inconsequent occurrences of this exeption. So I've had to depend on logs from the production application.
If anyone got an idea regarding this problem it would be extremely appreciated!

WCF Service TargetInvocationException - Possible Cyclic Reference

I need a little help with an Exception being thrown at my WCF service. The point is: I need to develop a WPF application and I've heard that to treat data WCF is the best choice so I used it only with basic knowledge and now I have this problem.
The point is, I have a Customer class, a Supplier class and an Order class. I have then two services: the first one has all methods to add, read and edit customers and suppliers from database. This service works perfectly fine. The second service has methods to add new orders, edit orders and read them from database, and this service has a problem.
The class Customer has a list of Suppliers (the suppliers from which the customer buys), the class Supplier has a list of Customers (the customers that buy from that supplier). The class order has a Customer, a Supplier and a list of Itens (and the itens are added to the database together with the order).
The method for adding an order works fine, however, once an order has been added, the method to list the orders throws the TargetInvocationException. I searched a lot on the internet and the best answer I've found is that it's possibly a "Ciclyc Reference".
The method to list the orders is inside the repository class and is simply:
public IQueryable<Order> ListOrders()
{
return Context.Set<Order>().Include(x => x.Customer).Include(x => x.Supplier);
}
Where Context is the entity framework context. I tried to remove the includes and load the customer and supplier separately, but the result was the same exception.
Can someone please help me ? If I need to post more information just tell me. And sorry if this matter is trivial, I'm new to WPF and WCF so I'm still a little confused.
Thanks a lot in advance.
EDIT Exception below
An error occurred while receiving the HTTP response to
http://SomeService.com/OrdersService.svc. This could be due to the
service endpoint binding not using the HTTP protocol. This could also
be due to an HTTP request context being
aborted by the server (possibly due to the service shutting down). See
server logs for more details.
Server stack trace: at
System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException
webException, HttpWebRequest request, HttpAbortReason abortReason)
at
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan
timeout) at
System.ServiceModel.Channels.RequestChannel.Request(Message message,
TimeSpan timeout) at
System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message
message, TimeSpan timeout) at
System.ServiceModel.Channels.ServiceChannel.Call(String action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins,
Object[] outs, TimeSpan timeout) at
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime operation) at
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
message)
Exception rethrown at [0]: at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg) at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type) at IOrdersService.ReturnOrders() at
OrdersServiceClient.ReturnOrders()
Inner Exception: The underlying connection was closed: An unexpected
error occurred on a receive. at
System.Net.HttpWebRequest.GetResponse() at
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan
timeout)
Inner Exception: Unable to read data from the transport connection: An
existing connection was forcibly closed by the remote host. at
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 size) at System.Net.PooledStream.Read(Byte[] buffer, Int32
offset, Int32 size) at
System.Net.Connection.SyncRead(HttpWebRequest request, Boolean
userRetrievedStream, Boolean probeRead)
Inner Exception: An existing connection was forcibly closed by the
remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer,
Int32 offset, Int32 size, SocketFlags socketFlags) at
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 size)
Mark your data objects with the [DataContract(IsReference = true)] attribute. This should resolve the issue.

Categories

Resources