Skip to content

Fix object null reference exception in reflection. #4738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotnet-svcutil/lib/src/CodeDomFixup/CodeDomHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static object ReferenceKey
if (s_referenceKey == null)
{
Type namespaceHelper = typeof(ServiceContractGenerator).GetTypeInfo().Assembly.GetType(typeof(ServiceContractGenerator).FullName + "+NamespaceHelper");
FieldInfo referenceKeyField = namespaceHelper.GetField("referenceKey", BindingFlags.NonPublic | BindingFlags.Static);
FieldInfo referenceKeyField = namespaceHelper.GetField("s_referenceKey", BindingFlags.NonPublic | BindingFlags.Static);
s_referenceKey = referenceKeyField.GetValue(null);
}
return s_referenceKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Duplex_NS
{


[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="Duplex_NS.IWcfDuplexService", CallbackContract=typeof(Duplex_NS.IWcfDuplexServiceCallback))]
public interface IWcfDuplexService
{

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IWcfDuplexService/Ping", ReplyAction="http://tempuri.org/IWcfDuplexService/PingResponse")]
System.Threading.Tasks.Task PingAsync(System.Guid guid);
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
public interface IWcfDuplexServiceCallback
{

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IWcfDuplexService/OnPingCallback", ReplyAction="http://tempuri.org/IWcfDuplexService/OnPingCallbackResponse")]
void OnPingCallback(System.Guid guid);
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
public interface IWcfDuplexServiceChannel : Duplex_NS.IWcfDuplexService, System.ServiceModel.IClientChannel
{
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
public partial class WcfDuplexServiceClientBase : System.ServiceModel.DuplexClientBase<Duplex_NS.IWcfDuplexService>, Duplex_NS.IWcfDuplexService
{

/// <summary>
/// Implement this partial method to configure the service endpoint.
/// </summary>
/// <param name="serviceEndpoint">The endpoint to configure</param>
/// <param name="clientCredentials">The client credentials</param>
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);

public WcfDuplexServiceClientBase(System.ServiceModel.InstanceContext callbackInstance) :
base(callbackInstance, WcfDuplexServiceClientBase.GetDefaultBinding(), WcfDuplexServiceClientBase.GetDefaultEndpointAddress())
{
this.Endpoint.Name = EndpointConfiguration.tcp_nosecurity_callback_IWcfDuplexService.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public WcfDuplexServiceClientBase(System.ServiceModel.InstanceContext callbackInstance, EndpointConfiguration endpointConfiguration) :
base(callbackInstance, WcfDuplexServiceClientBase.GetBindingForEndpoint(endpointConfiguration), WcfDuplexServiceClientBase.GetEndpointAddress(endpointConfiguration))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public WcfDuplexServiceClientBase(System.ServiceModel.InstanceContext callbackInstance, EndpointConfiguration endpointConfiguration, string remoteAddress) :
base(callbackInstance, WcfDuplexServiceClientBase.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public WcfDuplexServiceClientBase(System.ServiceModel.InstanceContext callbackInstance, EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
base(callbackInstance, WcfDuplexServiceClientBase.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public WcfDuplexServiceClientBase(System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(callbackInstance, binding, remoteAddress)
{
}

public System.Threading.Tasks.Task PingAsync(System.Guid guid)
{
return base.Channel.PingAsync(guid);
}

public virtual System.Threading.Tasks.Task OpenAsync()
{
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
}

public virtual System.Threading.Tasks.Task CloseAsync()
{
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
}

private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.tcp_nosecurity_callback_IWcfDuplexService))
{
System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.Security.Mode = System.ServiceModel.SecurityMode.None;
return result;
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}

private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.tcp_nosecurity_callback_IWcfDuplexService))
{
return new System.ServiceModel.EndpointAddress("net.tcp://wcfcoresrv5/WcfTestService1/Duplex.svc/tcp-nosecurity-callback");
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}

private static System.ServiceModel.Channels.Binding GetDefaultBinding()
{
return WcfDuplexServiceClientBase.GetBindingForEndpoint(EndpointConfiguration.tcp_nosecurity_callback_IWcfDuplexService);
}

private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
{
return WcfDuplexServiceClientBase.GetEndpointAddress(EndpointConfiguration.tcp_nosecurity_callback_IWcfDuplexService);
}

public enum EndpointConfiguration
{

tcp_nosecurity_callback_IWcfDuplexService,
}
}

public class OnPingCallbackReceivedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
{

private object[] results;

public OnPingCallbackReceivedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState)
{
this.results = results;
}

public System.Guid guid
{
get
{
base.RaiseExceptionIfNecessary();
return ((System.Guid)(this.results[0]));
}
}
}

public partial class WcfDuplexServiceClient : WcfDuplexServiceClientBase
{

public WcfDuplexServiceClient(EndpointConfiguration endpointConfiguration) :
this(new WcfDuplexServiceClientCallback(), endpointConfiguration)
{
}

private WcfDuplexServiceClient(WcfDuplexServiceClientCallback callbackImpl, EndpointConfiguration endpointConfiguration) :
base(new System.ServiceModel.InstanceContext(callbackImpl), endpointConfiguration)
{
callbackImpl.Initialize(this);
}

public WcfDuplexServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
this(new WcfDuplexServiceClientCallback(), binding, remoteAddress)
{
}

private WcfDuplexServiceClient(WcfDuplexServiceClientCallback callbackImpl, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(new System.ServiceModel.InstanceContext(callbackImpl), binding, remoteAddress)
{
callbackImpl.Initialize(this);
}

public WcfDuplexServiceClient() :
this(new WcfDuplexServiceClientCallback())
{
}

private WcfDuplexServiceClient(WcfDuplexServiceClientCallback callbackImpl) :
base(new System.ServiceModel.InstanceContext(callbackImpl))
{
callbackImpl.Initialize(this);
}

public event System.EventHandler<OnPingCallbackReceivedEventArgs> OnPingCallbackReceived;

private void OnOnPingCallbackReceived(object state)
{
if ((this.OnPingCallbackReceived != null))
{
object[] results = ((object[])(state));
this.OnPingCallbackReceived(this, new OnPingCallbackReceivedEventArgs(results, null, false, null));
}
}

private class WcfDuplexServiceClientCallback : object, IWcfDuplexServiceCallback
{

private WcfDuplexServiceClient proxy;

public void Initialize(WcfDuplexServiceClient proxy)
{
this.proxy = proxy;
}

public void OnPingCallback(System.Guid guid)
{
this.proxy.OnOnPingCallbackReceived(new object[] {
guid});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"providerId": "Microsoft.Tools.ServiceModel.Svcutil",
"version": "99.99.99",
"options": {
"inputs": [
"http://wcfcoresrv5.westus2.cloudapp.azure.com/wcftestservice1/Duplex.svc"
],
"namespaceMappings": [
"*, Duplex_NS"
],
"outputFile": "Reference.cs",
"targetFramework": "N.N",
"typeReuseMode": "None"
}
}
15 changes: 13 additions & 2 deletions src/dotnet-svcutil/lib/tests/src/E2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public void WcfRuntimeBasicSvcs(string serviceName, bool expectSuccess)
}

[Trait("Category", "Test")]
[Theory]
[Theory]
[InlineData("BasicHttpsTransSecMessCredsUserName.svc", true)]
public void WcfRuntimeBasicHttpsTransSecMessCredsUserName(string serviceName, bool expectSuccess)
{
Expand All @@ -403,7 +403,7 @@ public void WcfRuntimeNettcpTransSecMessCredsUserName(string serviceName, bool e

var uri = $"{g_ServiceUrl}/{serviceName}".Replace("http", "net.tcp");
this_TestCaseName = testCaseName;
TestSvcutil(AppendCommonOptions(uri), expectSuccess);
TestSvcutil(AppendCommonOptions(uri), expectSuccess);
}

[Trait("Category", "Test")]
Expand All @@ -417,6 +417,17 @@ public void WsHttpBindingAndws2007HttpBindingTransSecMessCredsUserName(string se
WcfRuntimeSvcs(serviceName, expectSuccess);
}

[Trait("Category", "Test")]
[Theory]
[InlineData("Duplex.svc", true)]
public void WcfRuntimeDuplexCallback(string serviceName, bool expectSuccess)
{
this_TestCaseName = "DuplexCallback";
TestFixture();

WcfRuntimeSvcs(serviceName, expectSuccess);
}

[Trait("Category", "Test")]
[Theory]
[InlineData("NetHttp.svc", true)]
Expand Down